Skip to Main Content
Cognex Support Hub
LogoLogo

Convert HTML Doc to PDF Through Automated Script

Method to automatically convert HTML docs to PDF. Used in this case for converting the HTML ID grading verification report into PDF.

02/26/2025

Question

How to get a an automatically generated PDF report for barcode grading verification results? 

Answer

Currently the In-Sight 7905V only generates HTML Validation Reports.
The idea is to write a PowerShell script that monitors a folder for .html files and uses wkhtmltopdf to convert them to PDFs. You'll first need to ensure wkhtmltopdf is installed on your system. Wkhtmltopdf is an open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine.

Once wkhtmltopdf is installed, the script can be used as a command-line tool to convert HTML files to PDF. Download and install wkhtmltopdf from the . “wkhtmltopdf.org” official web site.

Shown below is a PowerShell script that monitors a folder for .html files, converts them to PDF using wkhtmltopdf, and then deletes the original HTML file. The script continuously monitors the C:\ftproot folder for any new .html files. When an .html file is found, it uses the wkhtmltopdf command-line tool to convert the HTML file to a PDF and saves it to the C:\processed directory. After the PDF is created, the original .html file is deleted.

Placeholder

Define Paths: Make sure to update the wkhtmltopdf executable path in the script ($wkhtmltopdfPath) according to your installation. Ex "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"

To run the script, start a new Power Shell command line window. : “Set-ExecutionPolicy - ExecutionPolicy Bypass -Scope Process .\watch-and-convert.ps1”

Placeholder

To test it copy an HTML file into the C:\ftproot folder. The script should detect it, convert it to PDF using wkhtmltopdf, and move the result to the C:\processed folder. The console will log success or failure, and you should find the PDF in C:\processed. 

Related Resources

Loading component...