Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

HOW TO: Manipulate Margins in PDF Files

Hello,

I want to share how I could define margin for PDF Files. This workaround works for Cloud and On-Premises instances.

First, you may can take a look to the pdf.py file in GitHub (Frappe Repo).

This method looks for a CSS class .print-format and its attribute but ONLY in mm. However, ERPNext could cache the .css file making impossible to see changes immediately after we save. To solve this, we have to add a <style></style> tag in the Custom Report (or Predefined) changing this attributes. i.e.

<style>
    .print-format {
    font-family: 'Open Sans', sans-serif;
        margin-left:0mm;
        margin-top:0mm;
        margin-right:0mm;
        margin-bottom:0mm;
}
</style>

After this, you will get your PDF file with no margin.

Good Luck!

Alirio.

6 Likes

Thank you. Did you find a table or chart indicating each of the elements so others can be adjusted? For example want to make terms font size smaller and was working before, but now neither:

  • [data-fieldname=“terms”].value { font-size:40%; }
  • [data-fieldname=“terms”] { font-size:40%; }
  • .[data-fieldname=“terms”].value { font-size:40%; }
  • .[data-fieldname=“terms”] { font-size:40%; }

Trying other measurements such as 9px does not work either

This is only for PDF specific settings such as margin or page size.

You can adjust with this class:

  • margin-top
  • margin-bottom
  • margin-left
  • margin-right
  • page-size
  • header-spacing

It’s mandatory you specify all measures in mm.

You may want to open your own post so other users could help you with your issue. If you send full HTML will be better.

Alirio.

Thank if work for me but in my situation it removed the letter head

Hi

I had the same problem. I fixed it by not changing the margin-top in .print-format and putting the letter head in a div like the following:

<div id="header-html" class="visible-pdf">
  <div style="margin-top: -15mm;">
    {{ letter_head }}
  </div>
</div>

Of course, change -15mm by the value you actually want. Here, -15mm cancels the default 15mm, so it ends up being a 0mm top margin.

1 Like