Generating PDF from HTML template

Posted under features on September 18 , 2019 by Nidhisha Shetty

HTML file is created with the help of an HTML template using ExportToHtml() function. The HTML file is then converted into PDF file using wkhtmltopdf tool.

Conversion of HTML template to HTML file

ExportToHtml() function is used to generate HTML file from HTML template.
ExportToHtml() function accepts the following arguments:

  • Template: Provide the path of HTML template.
  • ToFile: This field accepts a boolean value (TRUE/FALSE).
  • File: If ToFile field has TRUE value, provide the path for the output file that will be generated. If no path is provided, the output file will be generated on the temporary (Temp) path within the SheetKraft folder.
  • StaticTags: Array or range of static tag names. Static tags are the fields that are fixed and have one-to-one mapping with the values that are provided in Excel. These tags should match exactly with the tag names provided in the HTML template file.

For example: Name_tag is the static tag in the following code line:

<sk:Replace tag="Name_tag"></sk:Replace>.  
  • StaticValues: Array or range of values corresponding to the static tag names.
  • RepeatTags: Array or range of repeating tag names. (Provide the tag names whose fields are to be repeated.) For example: repeat_tag is the repeat tag in the following code line:

  • RepeatRange1: Range corresponding to the first repeat tag. (Provide the column data for the fields that will be repeated.)
  • ReportTags1: Array or range of tags in the first repeat range. (Provide the tags to be exported to html file as a header to the list or table.). For example: column_1 and column_2 are the report tags (ReportTags1) within the first repeat tag as shown in the following code block:
    Here the column fields are to be repeated within table having repeat tag as table_tag.

  • Report1: Provide the order/sequence of data that will be exported to html. The data is provided within Report.SK() function.
    After Report1 field, data for second repeat tags are provided, that is, RepeatRange, ReportTags, and Report respectively. Providing all the details of arguments in the ExportToHtml() function, will generate the HTML file.

Conversion of HTML file to PDF file

HTML file can be converted to PDF file using wkhtmltopdf tool.
Following are the steps to convert HTML file to PDF file:

  1. Run command prompt with administrator rights.
  2. Change the directory to the folder having wkhtml.exe file.
  3. Run the following command:

Syntax:

<Path to wkhtmltopdf.exe file> --page-size <Letter|A4> --header-html <path to html header file>
--header-spacing <header spacing  value> --footer-html <path to html footer file> --margin-bottom <bottom spacing value> <path to input HTML file> <path to output PDF file>

For example:

wkhtmltopdf.exe --page-size Letter --header-html "header.html"  --header-spacing 15 --footer-html "footer.html" --margin-bottom 25 --header-spacing 15 *Input_html.html* *Output_PDF.pdf*  

For more information on wkhtmltopdf arguments refer to the following link: https://wkhtmltopdf.org/usage/wkhtmltopdf.txt.



TAGGED:HTMLPDFWkhtmltopdf


Recent Posts


Export To Excel Using Template

February 06, 2020 bySwanand Nirgudkar

For generating custom reports with complex formatting rules, SheetKraft's ExportToExcel Using…

Continue Reading

Export to XML

February 02, 2020 bySwanand Nirgudkar

A quick reference for exporting to an XML document through SheetKraft Any form of organized or…

Continue Reading

Display Inputs and Calculate Immediately Outputs

January 20, 2020 bySwanand Nirgudkar

While running an automated process, there may arise a need for the user to get some assistance on…

Continue Reading

Exporting Double Quotes Within a Text File

November 19, 2019 byShubham Thakkar

When dealing with automatic messaging systems, we often have to use some conventions in our input…

Continue Reading

Let's talk

Address

7th floor, Unit No. 701, C Wing,
Kailas Business Park, S. Veer Savarkar Marg,
Park Site, Vikhroli (W), Mumbai-400079.

 

Phone

+91 22 62362043

 

For General Queries & Technical Support

contact@quantumphinance.com

 

For Sale and Demos

sales@quantumphinance.com