I am using wkhtmltopdf with Python by calling Python from within the classic asp.
I defined some parameters as default in wkhtmltopdf. with the name “option”.
But later, when I call the function, I want to be able to change the page-size and cookie values, and I want the other default values to remain the same.
My code.py file:
def htmlToPdf(self, html_file, pdf_file, additional_options=None):
path_wkhtmltopdf = r'C:Program Files (x86)wkhtmltopdfbinwkhtmltopdf.exe'
option = {
'quiet': True,
'page-size': 'A4',
'cookie':[('login', 'token1=7040D304-34A5-444F-A10D-6942ABEC9B9F&token2=6E8405C7-B6BE-41F6-A5D3-0A20574A6849')],
'margin-top': '0.0in',
'margin-right': '0.0in',
'margin-bottom': '0.0in',
'margin-left': '0.0in',
}
if additional_options:
option.update(additional_options)
print(option)
The way I call the function:
result = htmlToPdf(html_file, r'c:WebPdf1.pdf',additional_options={'page-size':'A3','cookie': [('login', 'token1=7040D304-34A5-444F-A10D-6942ABEC9B9F&token2=6E8405C7-B6BE-41F6-A5D3-0A20574A6849')]})
print(result)
The error it gives:
Traceback (most recent call last):
File “c:PythonAspcode.py”, line 19, in
result=htmlToPdf(html_file, r’c:printPdf1.pdf’,additional_options={‘page-size’:’A3′,’cookie’: [(‘login’, ‘token1=111111-34A5-444F-A10D-6942ABEC9B9F&token2=222222-B6BE-41F6-A5D3-0A20574A6849’)]})
TypeError: htmlToPdf() got an unexpected keyword argument ‘additional_options’
I tried giving page-size and cookie values separately. I can give the page-size separately, but I still get stuck in the cookie and it does not accept strings.
I can have more than one cookie value.
Hafize Turk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.