Options
All
  • Public
  • Public/Protected
  • All
Menu

the new options for rendering PDF's using our Chrome backend. If you are using the old WebKit backend, see IPdfOptions_WebKit

Note: by default PDF's use the CSS @screen media type. to change this, set IRenderSettings.emulateMedia to a value such as print

If you want to rename the file (used if the user saves the pdf) set the Content-Disposition header via IRenderSettings.extraResponseHeaders. For example: "Content-Disposition":'attachment; filename="downloaded.pdf"'

example

//full api request JSON example showing use of header template { url: "https://phantomjscloud.com/examples/corpus/simple.html", renderType: 'pdf', renderSettings: { emulateMedia: 'print', pdfOptions: { headerTemplate: "Header or Footer. Keep templates simple, and inline CSS. Page:XX/YY", format: 'letter', preferCSSPageSize: true, margin: {top: '2in', bottom: 0, left: 0, right: 0} }, zoomFactor: 1 } }

Hierarchy

  • IPdfOptions

Index

Properties

Optional displayHeaderFooter

displayHeaderFooter: boolean

(Optional) Whether to show the header and footer. Default: false

Optional footerTemplate

footerTemplate: string

a HTML template, use the following classes to inject print values into their respective elements: date, title, url, pageNumber, totalPages

If the associated margin is not explicitly set, setting a template will automatically set the margin to "1in"

Note: page css is not available to this template, so include inline-css for styling.

example

footerTemplate:"<span style='font-size: 15px; height: 200px; background-color: black; color: white; margin: 20px;'>Header or Footer. <span style='font-size: 10px;'>Keep templates simple, and inline CSS. Page:<span class='pageNumber'>XX</span>/<span class='totalPages'>YY</span></span></span>"

Optional format

format: "letter" | "legal" | "tabloid" | "ledger" | "a0" | "a1" | "a2" | "a3" | "a4" | "a5" | "a6" | "viewport" | "onepage"

pdf paper size to use.

You may choose a standard paper size, or an adaptive size.

standard paper sizes: Letter, Legal, Tabloid, Ledger, and A0 to A6

adaptive sizes:

  • viewport : renders pages the size of the current browser viewport
  • onepage : renders all the browser contents in a single pdf page. It does this by setting the pdf page width to the current viewport width, and pdf page height to the entire page contents height. To better control page width, remember that 96px === 1in. So to have a 8.5inch wide page, set your viewport width to 816 (also consider using zoomFactor to shrink the page contents). onepage is slightly buggy, so to better control page length, you can set the additional onepageFudgeFactor sibling parameter.
default

"letter"

Optional headerTemplate

headerTemplate: string

a HTML template, use the following CSS classes to inject print values into their respective elements: date, title, url, pageNumber, totalPages

alternatively, you could pass the special classes as variables, as shown in this example: <span>Page %pageNumber% of %totalPages%</span>

If the associated margin is not explicitly set, setting a template will automatically set the margin to "1in"

Note: page css is not available to this template, so include inline-css for styling.

example

headerTemplate:"<span style='font-size: 15px; height: 200px; background-color: black; color: white; margin: 20px;'>Header or Footer. <span style='font-size: 10px;'>Keep templates simple, and inline CSS. Page:<span class='pageNumber'>XX</span>/<span class='totalPages'>YY</span></span></span>"

Optional height

height: string

optional pdf page dimensions used if you don't specify format.

pass a number with one of the following units: px, in, cm, or mm.

example

"88cm"

Optional landscape

landscape: boolean

Optional margin

margin: { bottom?: string; left?: string; right?: string; top?: string }

optional margin use units such as those used for width or height properties

default

no margin.

Type declaration

  • Optional bottom?: string
  • Optional left?: string
  • Optional right?: string
  • Optional top?: string

Optional omitBackground

omitBackground: boolean

(Optional) Hides default white background and allows generating pdfs with transparency. Default: false

Optional onepageFudgeFactor

onepageFudgeFactor: number

only used when format="onepage".

multiplier for pdf page height, to get it to fit on a pdf page. leaves a small blank area at the bottom.

formula is: pdfPageHeight = (browserPageHeight * fudgeFactor) + margins

default

1.05

Optional pageRanges

pageRanges: string

(Optional) Paper ranges to print, e.g. 1-5, 8, 11-13. Default: empty (all pages)

Optional preferCSSPageSize

preferCSSPageSize: boolean

if set to true, will use the CSS @page size if any is present.

Optional scale

scale: number

(Optional) Scales the rendering of the web page. Amount must be between 0.1 and 2. Default: 1

Optional timeout

timeout: number

(Optional) Timeout in milliseconds. Pass 0 to disable timeout. Default: 30000

Optional width

width: string

optional pdf page dimensions used if you don't specify format.

pass a number with one of the following units: px, in, cm, or mm.

example

"88cm"