How to create pdf file from html

Primary tabs

<html>
    <head>
        <title>LabCorp</title>
        <link rel="apple-touch-icon" sizes="60x60" href="app-assets/img/ico/apple-icon-60.png">
        <link rel="apple-touch-icon" sizes="76x76" href="app-assets/img/ico/apple-icon-76.png">
        <link rel="apple-touch-icon" sizes="120x120" href="app-assets/img/ico/apple-icon-120.png">
        <link rel="apple-touch-icon" sizes="152x152" href="app-assets/img/ico/apple-icon-152.png">
        <link rel="shortcut icon" type="image/x-icon" href="app-assets/img/ico/favicon.ico">
        <link rel="shortcut icon" type="image/png" href="app-assets/img/ico/favicon-32.png">
        <style>
            body, p, strong{font-size: 12px; font-family: Arial;}
            table tr td{font-size: 12px; font-family: Arial; padding: 2px 6px;}
            .borL{border-left:1px solid #333;}
            .borR{border-right:1px solid #333;}
            .borT{border-top:1px solid #333;}
            .borB{border-bottom:1px solid #333;}
            .border{border:1px solid #333;}
            
            @font-face {
                font-family: 'IDAutomationHC39M';
                src: url('d:/file/fonts/IDAutomationHC39M_0.ttf');
            }
            
            .IDAutomationCover {
                background: #f5f7fa;
                /*margin-top: 14px;
                padding-top: 45px;
                padding-left: 10px;*/
                padding-right: 10px;
            }
            .IDAutomationHC39M {
                font-family: IDAutomationHC39M;
                color: #525252;
                font-size: 20px;
                height: 80px;
                line-height: 80px;
                white-space: nowrap;
                margin-bottom: 0;
                padding-left: 10px;
                padding-right: 10px;
            }

            svg {
                border: 1px solid #000;
                padding-bottom: 4px;
            }
        </style>
    </head>
    <body>
    
    </body>
</html>

Replies

Hi Marc,

Can you please provide an example that used wkhtmltopdf  to covert html to pdf.

FYI,

I want to convert html to pdf programmatically. 

The wkhtmltopdf website has an example of the command-line usage -- looks fairly simple.

And have a look at our product documentation for $ZF(-100) on how to execute an external program from ObjectScript.

Hi, 

a sample:

   set command="c:\MyProgDir\wkhtmltopdf.exe --print-media-type --page-size A4  --orientation Landscape --margin-left 5 --margin-top 5 --margin-right 5 --margin-bottom 5 c:\MySourceDir\myHtml.html c:\MyTargetDir\MyPDF.pdf"
  set ok=$zf(-100,"",command)

on "html to pdf converter freeware" google gave me 3 270 000 hits.
Why reinventing the wheel. 
Place your HTML into a local file and let someone else do the dirty job.
There are enough solutions for a call-out to trigger the conversion.

Use Pupeteer. Follow the third option tutorial and you should be fine.

P.S.: You need NodeJS to run Pupeteer.

Hi Vivek,

We bought a license for CoolUtils (coolutils.com), whch also has  command line  functionality.  There are dozens of different converters with CoolUtils, but you can buy just the one.

We use a batch file for the command line, which will take two parameters, and an "option file" (used by the converter):

"C:\Program Files (x86)\TotalHTMLConverter\HTMLConverter.exe" "%1" "%2" -c pdf -fp -combine -si -pc Normal -ps letter -OptionFile %3

then call the batch file using $zf:

set command=dir_"Converters\html\ConvertHtmlToPDF.BAT"
set params(1)=fromHTMLfilename

set params(2)=toPDFfilename

set params(3)=OptionFileName

; NEXT: $ZF(-1) NOT USED BECAUSE ANY PROBLEM WITH THE CONVERTER PROGRAM WOULD CAUSE THIS PROCESS TO HANG UNTIL ETERNITY!!!
; Fire off HTML>PDF Converter program in background (-2 = don't wait)
status=$ZF(-100,"/ASYNC",command,.params)

 

The OptionFile has PDF codes like:

po=Landscape
PgHead=&b&d &t
PgFoot=&bPage &p of &P&bInsights powered by RevenueHealth Systems (C) 2018

I used the utility's "Command Line Parameters" help file to figure out how to set all the options, and how to use the option file.  I wrote a note to myself to "See http://www.verydoc.com/htmlprint-footer-header.html" for use on the pdf codes that are in the option file. 

It took a while, and I had to program in a new "language" of PDF options and stuff.

Good luck!