Skip to content

Commit c490d98

Browse files
Merge pull request #2772 from iareebahmad/master
Adding PDF Options for customized view
2 parents 2ea75cc + 0a10402 commit c490d98

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

HTML_to_PDF/main.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@
1414
htmlFile = f'{path}\\index.html'
1515
pdfFile = f'{path}\\output.pdf'
1616

17+
# Adding PDF Options for customized view
18+
options = {
19+
'page-size': 'A4',
20+
'margin-top': '0.75in',
21+
'margin-right': '0.75in',
22+
'margin-bottom': '0.75in',
23+
'margin-left': '0.75in',
24+
'encoding': 'UTF-8',
25+
'no-outline': None
26+
}
27+
1728
# Check if the HTML file exists before proceeding
1829
if not os.path.exists(htmlFile):
1930
print(f"HTML file does not exist at: {htmlFile}")
2031
else:
2132
try:
2233
# Convert HTML to PDF
23-
pdfkit.from_file(htmlFile, pdfFile, configuration=config)
34+
pdfkit.from_file(htmlFile, pdfFile, configuration=config,options=options)
2435
print(f"Successfully converted HTML to PDF: {pdfFile}")
2536
except Exception as e:
2637
print(f"An error occurred: {e}")

0 commit comments

Comments
 (0)