Print a HTML string to PDF

From DataFlex Wiki
Revision as of 00:58, 22 December 2017 by Wil (talk | contribs) (Extract of recent forum discussion)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Say you have a cwebHTMLEdit and you want to print the HTML result to a PDF file with a fixed name and destination.

You can do it via: "wkhtmltopdf" (WebKit HTML to PDF)

You can find the tool on this page: https://wkhtmltopdf.org/index.html

Following is a DataFlex function that returns the full path for the exe-file (once it has been installed on the machine).

 // Return full path to "wkhtmltopdf.exe"
 Function HtmlToPdfExeFile Returns String
     Integer hoRegistry
     Boolean bFound
     String sExeFile sKey
 
     Get Create (RefClass(cRegistry)) to hoRegistry
     Set phRootKey of hoRegistry to HKEY_LOCAL_MACHINE
     Set pfAccessRights of hoRegistry to (Key_Read ior wkKEY_WOW64_64KEY)
     Get OpenKey of hoRegistry "SOFTWARE\wkhtmltopdf" to bFound
     If (bFound) Begin
         If (ValueExists(hoRegistry,"PdfPath")) Begin
             Get ReadString of hoRegistry "PdfPath" to sExeFile
         End
         Send CloseKey of hoRegistry
     End
     Send Destroy of hoRegistry
     Function_Return sExeFile
 End_Function

External Links

This know how comes from: https://support.dataaccess.com/Forums/showthread.php?62055-Printing-a-HTML-string-to-PDF-file