0

I am using pylatex in python to generate PDFs. I want to add a Page border in the generated PDF but I am not able to do so. I didn't found any reference for adding border in the pylatex documentation. Is there any way that can work? Here are the geometry options for Document class:

geometry_options = {
    "head": "40pt",
    "margin": "0.5in",
    "bottom": "0.6in",
    "includeheadfoot": True
}
doc = Document(geometry_options=geometry_options)

Let me know if you need more details.

Sahil Chaudhary
  • 111
  • 1
  • 9

1 Answers1

0

Sorry, I have posted this questions and now after some research I found its solution too.

There are many packages to add page border in a latex document using various packages.

Following are the steps that one can follow:

  • Identify the package you want to use for your latex document.The one I used is memoir class and especially its showtrims function.
  • After deciding the desired package, you can use NoEscape() function to execute raw latex commands in python.For example, NoEscape(r'\trimFrame')
  • The last step will be to append this object returned by NoEscape() to the doc class.

Here is a code snippet- (Hope it helps!!)

doc = Document(documentclass='memoir',document_options=['10pt','a4paper','showtrims'],
                            geometry_options=geometry_options, lmodern = True)

new_comm1 = NoEscape(r'\trimFrame')
doc.append(new_comm1)
new_comm2 = NoEscape(r'\settrimmedsize{286mm}{198mm}{*}')
doc.append(new_comm2)
new_comm3 = NoEscape(r'\settrims{6mm}{6mm}')
doc.append(new_comm3)
Sahil Chaudhary
  • 111
  • 1
  • 9