Xbasic

Helper::HtmlToPdf Class

Description

Class that wraps the wkhtmltppdf utility to convert HTML content to PDF. The helper::HtmlToPdf Class class allows you to convert HTML to PDF or a URL to PDF. The following example code can be pasted into a new script in the Code editor and executed.

dim hp as helper::HtmlToPdf
dim html as c 
html = <<%html%
<style>
.mystyle {color: red;}
</style>
<h1>This is So Cool</h1<br>
<h2>Generate PDF from HTML!</h2>
<p>This shows how you can turn <span class=&quot;mystyle&quot;>any</span> 
html into a pdf</p>
%html%
dir_create_recurse("c:\mypdffiles")
hp.SaveHTMLToPdf(html,"c:\mypdffiles\mypdf.pdf")
'now open the file
sys_open("c:\mypdffiles\mypdf.pdf")

Properties

unitsCharacter

String units property. The units that all measurements are in (e.g. margin_left, page_height, etc.). default is "in" (inches). options are: "cm", "mm", "pt" (points), "tw" (twips - 20th of a point), "px" (pixels)

page_sizeCharacter

String page_size property. The size of the page. Options include "A4", "Letter", etc. Default is "A4"

page_heightNumeric

Numeric page_height property. Page height expression in setting for units

page_widthNumeric

Numeric page_width property. Page width expression in setting for units

landscapeLogical

Logical landscape property, .t. or .f. - If .t. then use landscape mode.

grayscaleLogical

Logical grayscale property, .t. or .f. - default .f. - if .t. then pdf does not use colors.

enable_formsLogical

Logical enable_forms property, .t. or .f. - default .f. - if .t. then input controls in the HTML become input controls in the PDF file.

margin_leftNumeric

Numeric margin_left property. Margin expression in setting for units

margin_rightNumeric

Numeric margin_right property

margin_topNumeric

Numeric margin_top property. Margin expression in setting for units

margin_bottomNumeric

Numeric margin_bottom property. Margin expression in setting for units

image_qualityNumeric

Numeric image_quality property. Numeric value that controls the amount of compression of embedded jpeg images. default is 94 - 100 is no compression.

use_print_mediaLogical

Logical use_print_media property

javascript_delayNumeric

Numeric javascript_delay property. If the html page contains javascript code that runs when the page renders, the amount of time in milliseconds to wait before generating the PDF. Allows long running Javascript to complete before conversion starts.

smart_shrinkingLogical

Logical smart_shrinking property. Enable WebKit's 'intelligent shrinking' strategy. Makes the pixel/dpi ratio variable.

allow_file_pathCharacter

String allow_file_path property

cookies

cookies property

Methods

Deletecookie Method

Delete a cookie.

Insertcookie Method

Insert a new cookie.

Movecookie Method

Move a block of cookie items.

SaveHTMLToPdf Method

Generate a PDF from a given html.

SaveUrlToPdf Method

Generate a PDF from a given uri.

See Also