Metadata

DW
Last updated 8 months ago

Configure how a PDF is rendered with metadata. Tweak page sizes, margins, and more.

Metadata can be specified in the defaults of the BreezyPDF library you're using, the markup of the HTML you're rendering, or pass as an option when using pragmatic access.

Default options will be overridden by options specified in the markup of the HTML.

Options specified in the markup of the HTML will be overriden by options passed using pragmatic access.

The BreezyPDF library you're using must be configured to parse the HTML for metadata options in the HTML.

Rendering Options

Stylistic and layout options to configure how the PDF is rendered.

Filename

Configure the resulting filename of the generated PDF. If not specified, a UUID will be used as the filename.

<meta name="breezy-pdf-filename" content="myfilename.pdf">

Width

Configure the width of the generated PDF. Measured in inches, defaulting to 8.5.

<meta name="breezy-pdf-width" content="8.5">

This value will be disregarded if cssPageSize is set to true.

Height

Configure the height of the generated PDF. Measured in inches, defaulting to 11.

<meta name="breezy-pdf-height" content="11">

This value will be disregarded if cssPageSize is set to true.

Use CSS for Page Size

Configure the width and height of the genreated PDF with CSS instead of the arguments passed via metadata. Defaults to false.

<meta name="breezy-pdf-cssPageSize" content="true">
body {
width: 8.5in;
height: 11in;
}

Margins

Configure the top, left, right, and bottom margins of the genreated PDF. Measured in inches, defaulting to 0.4.

<meta name="breezy-pdf-marginTop" content="0.4">
<meta name="breezy-pdf-marginRight" content="0.4">
<meta name="breezy-pdf-marginBottom" content="0.4">
<meta name="breezy-pdf-marginLeft" content="0.4">

Landscape

Configure the genreated PDF to be displayed in landscape instead of portrait. Defaults to false.

<meta name="breezy-pdf-landscape" content="true">

Scale

Configure the scale at which the HTML will be displayed when converted to PDF. Defaults to 1.

<meta name="breezy-pdf-scale" content="2">

Display Background in PDF

Configure if the background in the HTML is included in the PDF. Defaults to false.

<meta name="breezy-pdf-displayBackground" content="true">
body {
background: red;
}

Configure the HTML template to be included at the top and bottom of every page. Include elements with the classes of date, title, pageNumber, and totalPages to have values inserted at render time. At this time, any images must be DataURI encoded and styles must be specified within the template. Defaults to no HTML.

date - Formatted render date displayed in UTC. title - Title of the document specified by the title tag. pageNumber - The count of the current page in the PDF. totalPages - The total count of pages in the PDF.

<meta name="breezy-pdf-headerTemplate" content="<div class='header'><table><tr><td class='date'></td><td><img src='data:image/png;base64,...' alt='Logo'><span class='title'></span></td><td><span class='pageNumber'></span>/<span class='totalPages'></span></td></tr></table></div>">
<meta name="breezy-pdf-footerTemplate" content="<div class='footer'><table><tr><td class='date'></td><td><img src='data:image/png;base64,...' alt='Logo'><span class='title'></span></td><td><span class='pageNumber'></span>/<span class='totalPages'></span></td></tr></table></div>">

Completion Triggers

Notify the rendering engine when your rich content has completed loading and the PDF is ready to be rendered. Most typically used when complex JavaScript needs to be evaluated. The default completion trigger is a timer of 5000ms. If multiple completion triggers, the first trigger used will be adopted based on the order in which they're specified here.

If a render times out via the specified timeout option, the user will be redirected to an error page.

Callback

A JavaScript function in the global namespace which will be defined by the renderer. Your code will be invoke this callback when the document is ready for PDF rendering. Optional timeout can be specified in ms, defaulting to 5000ms.

<meta name="breezy-pdf-callback" content="myWorkHereIsDoneCallback">
<meta name="breezy-pdf-timeout" content="3000">
function() {
// My hard working JS here
window.myWorkHereIsDoneCallback();
}

Event

A JavaScript event which will be dispatched on an element when the document is ready for PDF rendering. Optional CSS element selector can be specified, defaulting to document. Optional timeout can be specified in ms, defaulting to 5000ms.

<meta name="breezy-pdf-event" content="myCustomEvent">
<meta name="breezy-pdf-element" content="#myContainer">
<meta name="breezy-pdf-timeout" content="3000">
var event = new CustomEvent('myCustomEvent');
var element = document.getElementBydId('myContainer');
‚Äč
element.dispatchEvent(event);

Element

The CSS selector of an element which will be inserted into the document when the document is ready for PDF rendering. Optional timeout can be specified in ms, defaulting to 5000ms.

<meta name="breezy-pdf-element" content="#last-page > #last-element">
<meta name="breezy-pdf-timeout" content="3000">
function() {
// My hard working JS here
var lastPage = document.getElementById('#last-page');
var lastElement = document.createElement('div');
lastElement.id = 'last-element';
lastPage.appendChild(lastElement);
}

Variable

The variable in the global namespace which will be defined when the document is ready for PDF rendering. Optional timeout can be specified in ms, defaulting to 5000ms.

<meta name="breezy-pdf-variable" content="myWorkHereIsDoneVariable">
function() {
// My hard working JS here
window.myWorkHereIsDoneVariable = true;
}

Timer

The predefined amount of time to wait before the document is rendered to PDF. Timer can be specified in ms, defaulting to 5000ms.

<meta name="breezy-pdf-timer" content="10000">