Print a HTML string to PDF: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
m add syntax highlighting
m Changed from Web Programming to Web Applications category
 
Line 34: Line 34:
This know how comes from: https://support.dataaccess.com/Forums/showthread.php?62055-Printing-a-HTML-string-to-PDF-file
This know how comes from: https://support.dataaccess.com/Forums/showthread.php?62055-Printing-a-HTML-string-to-PDF-file


[[Category:Web Programming]]
[[Category:Web Applications]]

Latest revision as of 14:12, 8 April 2020

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