I tried to follow a tutorial and programmed something via Python to convert an HTML file to PDF.
In my case "sample.html".
import pdfkit
#Define path to wkhtmltopdf.exe
path_to_wkhtmltopdf = r'C:Program Fileswkhtmltopdfbinwkthmltopdf.exe'
#Define path to HTML file
path_to_file = 'sample.html'
#Point pdfkit configuration to wkhtml.exe
config = pdfkit.configuration(wkhtmltopdf = path_to_wkhtmltopdf)
#Convert HTML file to PDF
pdfkit.from_file(path_to_file, output_path = 'sample.pdf', configuration = config)
But now I have a folder with many HTML files and it would be too much work to do it for each file individually. What part of the code would I need to change to achieve this?
2
Answers
I add sample code below.
You dont need Python or PDFkit to run WkHTMLtoX, but they do provide a wrapper to files and settings.
However if you know the switches to get the desired layout, you can use them in a batch file, running from a working folder.
Here are two ways of converting HTML to PDF (there are many others) and each has their merits. I include the batch file for you to place in a test set folder (and or sub folders) you will need to edit the exe folder names and add any switches desired.
htm2pdf.cmd