The 'Paper Format' takes a significant part while creating a QWeb report in PDF format in Odoo 20. This parameter helps to specify important parameters like paper dimension, portrait or landscape mode, margin and header/footer margin, and resolution at which rendering would be done.
Paper formats allow developers to design standardized printed reports for such papers as invoices, contracts, loan papers, ID cards, and certificates. By linking paper format with report actions, we ensure that the same paper format will be used while printing all the documents using various printing machines.
This blog will help you understand how you can create customized paper formats in Odoo 20.
Name the file report_paperformat_data.xml and place it in the data directory of your module. Then add the XML code to create a paper format and include the XML file in your module’s __manifest__.py file so that paper format gets installed/updated when the module is installed/updated.
Here is an example of the paper format code snippet:
<record id="paperformat_label_sheet" model="report.paperformat">
<field name="name">A4 Label Sheet</field>
<field name="default" eval="True" />
<field name="format">A4</field>
<field name="page_height">0</field>
<field name="page_width">0</field>
<field name="orientation">Portrait</field>
<field name="margin_top">0</field>
<field name="margin_bottom">0</field>
<field name="margin_left">0</field>
<field name="margin_right">0</field>
<field name="disable_shrinking" eval="True"/>
<field name="dpi">96</field>
</record>
<record id="paperformat_label_sheet" model="report.paperformat">
The data is created in the new record in the database using paperformat_label_sheet as an XML reference. This is done using report.paperformat, where the record is tagged as the paper format configuration for PDF report generation.
<field name="name">A4 Label Sheet</field>
The name attribute gives the name of the paper format as A4 Label Sheet.
<field name="default" eval="True" />
The default attribute set to True shows that this is the default paper format if there are no other paper formats for the report.
<field name="format">A4</field>
The format attribute is the standard paper size, which is set to A4.
<field name="page_height">0</field>
<field name="page_width">0</field>
The page_height and page_width attributes are set as 0, and this is done because Odoo will make use of predefined sizes of A4.
<field name="orientation">Portrait</field>
The orientation attribute sets the type of page layout as Portrait or Landscape.
<field name="margin_top">0</field>
<field name="margin_bottom">0</field>
<field name="margin_left">0</field>
<field name="margin_right">0</field>
The margin_top, margin_bottom, margin_left, and margin_right attributes give the page margins in mm. If they are set to 0, then it means the entire page will be used.
<field name="disable_shrinking" eval="True"/>
The disable_shrinking option is used to avoid the auto-resizing of report contents.
<field name="dpi">96</field>
The dpi attribute shows the number of dots per inch during the rendering process, which influences the visual properties of the PDF report.
To assign the paper format to the report, one needs to use the paperformat_id attribute. See the example of how it works on the Reception Report Label:
<record id="label_picking" model="ir.actions.report">
<field name="name">Reception Report Label</field>
<field name="model">stock.move</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">stock.report_reception_report_label</field>
<field name="report_file">stock.report_reception_report_label</field>
<field name="paperformat_id" ref="product.paperformat_label_sheet"/>
<field name="binding_type">report</field>
</record>
And now we’ll create the paper format from Settings > Technical > Reporting > Paper Format.
In Odoo 20, paper formats enable customization of the design of the generated PDF report without changing anything in the report template itself. You may set the format to be printed, page size, margins, DPI, and other parameters for the correct printout from various printers and devices. If you’re generating invoices, product labels, certificates, contracts, or any business documents, defining the correct paper size will improve the readability of the report, its professional look, and minimize printing errors.
To read more about How to Configure Paper Formats in Odoo 19, refer to our blog, How to Configure Paper Formats in Odoo 19.