# PDF

Collection of PDF functions.

### Methods

#### create

```javascript
create(htmlBody: string | string[], options?: { 
        /**
         * Paper size
         */
        format?: 'A4' | 'Letter' | 'Legal' | 'Ledger' | 'Tabloid' | 'A0' | 'A1' | 'A2' | 'A3' | 'A5' | 'A6',
        /**
         * Paper orientation. Defaults to false (portrait).
         */
        landscape?: boolean,
        /**
         * Paper margins. Defaults to { top: 30, right: 35, bottom: 70, left: 25 }. Units can be numbers or strings with units (e.g. '1cm', '10px', '2in', '5mm').
         */
        margin?: { top?: number | string, right?: number | string, bottom?: number | string, left?: number | string },
        /**
         * Paper width, accepts values labeled with units.
         */
        width?: string | number,
        /**
         * Paper height, accepts values labeled with units.
         */
        height?: string | number,
        /**
         * HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
         * - date: formatted print date
         * - title: document title
         * - url: document location
         * - pageNumber: current page number
         * - totalPages: total pages in the document
         */
        headerTemplate?: string,
        /**
         * HTML template for the print footer. Should use the same format as the headerTemplate.
         */
        footerTemplate?: string,
        /**
         * Whether or not to embed the document outline into the PDF. Defaults to false.
         */
        outline?: boolean,
        /**
         * Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
         */
        pageRanges?: string,
        /**
         * Print background graphics. Defaults to false.
         */
        printBackground?: boolean,
        /**
         * Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2.
         */
        scale?: number,
        /**
         * Whether or not to generate tagged (accessible) PDF. Defaults to false.
         */
        tagged?: boolean,
        /**
         * Navigator language.
         */
        locale?: string,
        /**
         * Selector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').
         */
        waitForSelector?: string
        /**
         * State of defined waitForSelector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').
         */
        waitForState?: 'attached' | 'detached' | 'hidden' | 'visible',
        /**
         * Add debugging information to the PDF. Defaults to false.
         */
        debug?: boolean,
        /**
         * Custom CSS to be injected into the page before printing.
         */
        css?: string,
        /**
         * HTTP headers to be sent with the request.
         */
        httpHeaders?: Record<string, string>,
        /**
         * LocalStorage content to be injected into the page before printing.
         */
        localStorage?: Record<string, string>,
        /**
         * SessionStorage content to be injected into the page before printing.
         */
        sessionStorage?: Record<string, string>,
        /**
         * Cookies to be set in the page before printing.
         */
        cookies?: Record<string, string>
    })
```

Creates a PDF document from given HTML. Returns a base64 encoded string.

**Parameters**

&#x20;   **htmlBody&#x20;*****string | string\[]***

&#x20;       The HTML to convert to PDF. Can be a single string or an array of strings for multiple pages.

&#x20;   **options&#x20;*****{ /*****\* \* Paper size&#x20;*****/ format?: 'A4' | 'Letter' | 'Legal' | 'Ledger' | 'Tabloid' | 'A0' | 'A1' | 'A2' | 'A3' | 'A5' | 'A6', /*****\* \* Paper orientation. Defaults to false (portrait).&#x20;*****/ landscape?: boolean, /*****\* \* Paper margins. Defaults to { top: 30, right: 35, bottom: 70, left: 25 }. Units can be numbers or strings with units (e.g. '1cm', '10px', '2in', '5mm').&#x20;*****/ margin?: { top?: number | string, right?: number | string, bottom?: number | string, left?: number | string }, /*****\* \* Paper width, accepts values labeled with units.&#x20;*****/ width?: string | number, /*****\* \* Paper height, accepts values labeled with units.&#x20;*****/ height?: string | number, /*****\* \* HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: \* - date: formatted print date \* - title: document title \* - url: document location \* - pageNumber: current page number \* - totalPages: total pages in the document&#x20;*****/ headerTemplate?: string, /*****\* \* HTML template for the print footer. Should use the same format as the headerTemplate.&#x20;*****/ footerTemplate?: string, /*****\* \* Whether or not to embed the document outline into the PDF. Defaults to false.&#x20;*****/ outline?: boolean, /*****\* \* Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.&#x20;*****/ pageRanges?: string, /*****\* \* Print background graphics. Defaults to false.&#x20;*****/ printBackground?: boolean, /*****\* \* Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2.&#x20;*****/ scale?: number, /*****\* \* Whether or not to generate tagged (accessible) PDF. Defaults to false.&#x20;*****/ tagged?: boolean, /*****\* \* Navigator language.&#x20;*****/ locale?: string, /*****\* \* Selector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').&#x20;*****/ waitForSelector?: string /*****\* \* State of defined waitForSelector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').&#x20;*****/ waitForState?: 'attached' | 'detached' | 'hidden' | 'visible', /*****\* \* Add debugging information to the PDF. Defaults to false.&#x20;*****/ debug?: boolean, /*****\* \* Custom CSS to be injected into the page before printing.&#x20;*****/ css?: string, /*****\* \* HTTP headers to be sent with the request.&#x20;*****/ httpHeaders?: Record\<string, string>, /*****\* \* LocalStorage content to be injected into the page before printing.&#x20;*****/ localStorage?: Record\<string, string>, /*****\* \* SessionStorage content to be injected into the page before printing.&#x20;*****/ sessionStorage?: Record\<string, string>, /*****\* \* Cookies to be set in the page before printing.&#x20;*****/ cookies?: Record\<string, string> }***

&#x20;       (optional) The additional PDF options.

**Return type**

&#x20;   string

**Examples**

```javascript
// The HTML body is the only required parameter
PDF.create('Hello World!');

// You can also add multiple pages, header and footer templates and custom formatting and styling
PDF.create(
    [
        // Use multiple strings for multiple pages
        '<h1>Hello World!</h1>',
        '<p>Hello World Too!</p>',
        '<span>A third page</span>',
    ],    
    // Set additional PDF options
    {
        headerTemplate: '<div style="width: 100%; text-align: center">This is the header</div>',
        footerTemplate: `<div style="width: 100%; margin-right: 25px; text-align: right">
            <!-- Use pageNumber and totalPages classes to display page numbers -->
            Page: <span class="pageNumber"></span>/<span class="totalPages"></span>
        </div>`,
        margin: { bottom: 70, left: 25, right: 35, top: 30 }
    }
);
```

#### createFromUrl

```javascript
createFromUrl(url: string | string[], options?: { 
        /**
         * Paper size
         */
        format?: 'A4' | 'Letter' | 'Legal' | 'Ledger' | 'Tabloid' | 'A0' | 'A1' | 'A2' | 'A3' | 'A5' | 'A6',
        /**
         * Paper orientation. Defaults to false (portrait).
         */
        landscape?: boolean,
        /**
         * Paper margins. Defaults to { top: 30, right: 35, bottom: 70, left: 25 }. Units can be numbers or strings with units (e.g. '1cm', '10px', '2in', '5mm').
         */
        margin?: { top?: number | string, right?: number | string, bottom?: number | string, left?: number | string },
        /**
         * Paper width, accepts values labeled with units.
         */
        width?: string | number,
        /**
         * Paper height, accepts values labeled with units.
         */
        height?: string | number,
        /**
         * HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
         * - date: formatted print date
         * - title: document title
         * - url: document location
         * - pageNumber: current page number
         * - totalPages: total pages in the document
         */
        headerTemplate?: string,
        /**
         * HTML template for the print footer. Should use the same format as the headerTemplate.
         */
        footerTemplate?: string,
        /**
         * Whether or not to embed the document outline into the PDF. Defaults to false.
         */
        outline?: boolean,
        /**
         * Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
         */
        pageRanges?: string,
        /**
         * Print background graphics. Defaults to false.
         */
        printBackground?: boolean,
        /**
         * Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2.
         */
        scale?: number,
        /**
         * Whether or not to generate tagged (accessible) PDF. Defaults to false.
         */
        tagged?: boolean,
        /**
         * Navigator language.
         */
        locale?: string,
        /**
         * Selector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').
         */
        waitForSelector?: string
        /**
         * State of defined waitForSelector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').
         */
        waitForState?: 'attached' | 'detached' | 'hidden' | 'visible',
        /**
         * Add debugging information to the PDF. Defaults to false.
         */
        debug?: boolean,
        /**
         * Custom CSS to be injected into the page before printing.
         */
        css?: string,
        /**
         * HTTP headers to be sent with the request.
         */
        httpHeaders?: Record<string, string>,
        /**
         * LocalStorage content to be injected into the page before printing.
         */
        localStorage?: Record<string, string>,
        /**
         * SessionStorage content to be injected into the page before printing.
         */
        sessionStorage?: Record<string, string>,
        /**
         * Cookies to be set in the page before printing.
         */
        cookies?: Record<string, string>
    })
```

Creates a PDF document from a given url. Returns a base64 encoded string.

**Parameters**

&#x20;   **url&#x20;*****string | string\[]***

&#x20;       The url to convert to PDF.

&#x20;   **options&#x20;*****{ /*****\* \* Paper size&#x20;*****/ format?: 'A4' | 'Letter' | 'Legal' | 'Ledger' | 'Tabloid' | 'A0' | 'A1' | 'A2' | 'A3' | 'A5' | 'A6', /*****\* \* Paper orientation. Defaults to false (portrait).&#x20;*****/ landscape?: boolean, /*****\* \* Paper margins. Defaults to { top: 30, right: 35, bottom: 70, left: 25 }. Units can be numbers or strings with units (e.g. '1cm', '10px', '2in', '5mm').&#x20;*****/ margin?: { top?: number | string, right?: number | string, bottom?: number | string, left?: number | string }, /*****\* \* Paper width, accepts values labeled with units.&#x20;*****/ width?: string | number, /*****\* \* Paper height, accepts values labeled with units.&#x20;*****/ height?: string | number, /*****\* \* HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: \* - date: formatted print date \* - title: document title \* - url: document location \* - pageNumber: current page number \* - totalPages: total pages in the document&#x20;*****/ headerTemplate?: string, /*****\* \* HTML template for the print footer. Should use the same format as the headerTemplate.&#x20;*****/ footerTemplate?: string, /*****\* \* Whether or not to embed the document outline into the PDF. Defaults to false.&#x20;*****/ outline?: boolean, /*****\* \* Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.&#x20;*****/ pageRanges?: string, /*****\* \* Print background graphics. Defaults to false.&#x20;*****/ printBackground?: boolean, /*****\* \* Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2.&#x20;*****/ scale?: number, /*****\* \* Whether or not to generate tagged (accessible) PDF. Defaults to false.&#x20;*****/ tagged?: boolean, /*****\* \* Navigator language.&#x20;*****/ locale?: string, /*****\* \* Selector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').&#x20;*****/ waitForSelector?: string /*****\* \* State of defined waitForSelector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').&#x20;*****/ waitForState?: 'attached' | 'detached' | 'hidden' | 'visible', /*****\* \* Add debugging information to the PDF. Defaults to false.&#x20;*****/ debug?: boolean, /*****\* \* Custom CSS to be injected into the page before printing.&#x20;*****/ css?: string, /*****\* \* HTTP headers to be sent with the request.&#x20;*****/ httpHeaders?: Record\<string, string>, /*****\* \* LocalStorage content to be injected into the page before printing.&#x20;*****/ localStorage?: Record\<string, string>, /*****\* \* SessionStorage content to be injected into the page before printing.&#x20;*****/ sessionStorage?: Record\<string, string>, /*****\* \* Cookies to be set in the page before printing.&#x20;*****/ cookies?: Record\<string, string> }***

&#x20;       (optional) The additional PDF options.

**Return type**

&#x20;   string

**Examples**

```javascript
// The url is the only required parameter
PDF.createFromUrl('https://www.example.com');

// You can also add header and footer templates and custom formatting and styling
PDF.createFromUrl(
   'https://www.example.com',   
    // Set additional PDF options
    {
        headerTemplate: '<div style="width: 100%; text-align: center">This is the header</div>',
        footerTemplate: `<div style="width: 100%; margin-right: 25px; text-align: right">
            <!-- Use pageNumber and totalPages classes to display page numbers -->
            Page: <span class="pageNumber"></span>/<span class="totalPages"></span>
        </div>`,
        margin: {bottom: 70, left: 25, right: 35, top: 30}
    }
);
```

#### renderForm

```javascript
renderForm(formName: string, context: { [key: string]: any; }, options?: { 
        /**
         * Paper size
         */
        format?: 'A4' | 'Letter' | 'Legal' | 'Ledger' | 'Tabloid' | 'A0' | 'A1' | 'A2' | 'A3' | 'A5' | 'A6',
        /**
         * Paper orientation. Defaults to false (portrait).
         */
        landscape?: boolean,
        /**
         * Paper margins. Defaults to { top: 30, right: 35, bottom: 70, left: 25 }. Units can be numbers or strings with units (e.g. '1cm', '10px', '2in', '5mm').
         */
        margin?: { top?: number | string, right?: number | string, bottom?: number | string, left?: number | string },
        /**
         * Paper width, accepts values labeled with units.
         */
        width?: string | number,
        /**
         * Paper height, accepts values labeled with units.
         */
        height?: string | number,
        /**
         * HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
         * - date: formatted print date
         * - title: document title
         * - url: document location
         * - pageNumber: current page number
         * - totalPages: total pages in the document
         */
        headerTemplate?: string,
        /**
         * HTML template for the print footer. Should use the same format as the headerTemplate.
         */
        footerTemplate?: string,
        /**
         * Whether or not to embed the document outline into the PDF. Defaults to false.
         */
        outline?: boolean,
        /**
         * Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
         */
        pageRanges?: string,
        /**
         * Print background graphics. Defaults to false.
         */
        printBackground?: boolean,
        /**
         * Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2.
         */
        scale?: number,
        /**
         * Whether or not to generate tagged (accessible) PDF. Defaults to false.
         */
        tagged?: boolean,
        /**
         * Navigator language.
         */
        locale?: string,
        /**
         * Selector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').
         */
        waitForSelector?: string
        /**
         * State of defined waitForSelector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').
         */
        waitForState?: 'attached' | 'detached' | 'hidden' | 'visible',
        /**
         * Add debugging information to the PDF. Defaults to false.
         */
        debug?: boolean,
        /**
         * Custom CSS to be injected into the page before printing.
         */
        css?: string,
        /**
         * HTTP headers to be sent with the request.
         */
        httpHeaders?: Record<string, string>,
        /**
         * LocalStorage content to be injected into the page before printing.
         */
        localStorage?: Record<string, string>,
        /**
         * SessionStorage content to be injected into the page before printing.
         */
        sessionStorage?: Record<string, string>,
        /**
         * Cookies to be set in the page before printing.
         */
        cookies?: Record<string, string>
    })
```

Render a Ruleset Form to PDF.

**Parameters**

&#x20;   **formName&#x20;*****string***

&#x20;       The name or ID of the Form (e.g. "Form1").

&#x20;   **context&#x20;*****{ \[key: string]: any; }***

&#x20;       The context to render the form with.

&#x20;   **options&#x20;*****{ /*****\* \* Paper size&#x20;*****/ format?: 'A4' | 'Letter' | 'Legal' | 'Ledger' | 'Tabloid' | 'A0' | 'A1' | 'A2' | 'A3' | 'A5' | 'A6', /*****\* \* Paper orientation. Defaults to false (portrait).&#x20;*****/ landscape?: boolean, /*****\* \* Paper margins. Defaults to { top: 30, right: 35, bottom: 70, left: 25 }. Units can be numbers or strings with units (e.g. '1cm', '10px', '2in', '5mm').&#x20;*****/ margin?: { top?: number | string, right?: number | string, bottom?: number | string, left?: number | string }, /*****\* \* Paper width, accepts values labeled with units.&#x20;*****/ width?: string | number, /*****\* \* Paper height, accepts values labeled with units.&#x20;*****/ height?: string | number, /*****\* \* HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: \* - date: formatted print date \* - title: document title \* - url: document location \* - pageNumber: current page number \* - totalPages: total pages in the document&#x20;*****/ headerTemplate?: string, /*****\* \* HTML template for the print footer. Should use the same format as the headerTemplate.&#x20;*****/ footerTemplate?: string, /*****\* \* Whether or not to embed the document outline into the PDF. Defaults to false.&#x20;*****/ outline?: boolean, /*****\* \* Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.&#x20;*****/ pageRanges?: string, /*****\* \* Print background graphics. Defaults to false.&#x20;*****/ printBackground?: boolean, /*****\* \* Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2.&#x20;*****/ scale?: number, /*****\* \* Whether or not to generate tagged (accessible) PDF. Defaults to false.&#x20;*****/ tagged?: boolean, /*****\* \* Navigator language.&#x20;*****/ locale?: string, /*****\* \* Selector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').&#x20;*****/ waitForSelector?: string /*****\* \* State of defined waitForSelector to wait for during URL fetch. The PDF generation will wait until the selector has the given state (default 'attached').&#x20;*****/ waitForState?: 'attached' | 'detached' | 'hidden' | 'visible', /*****\* \* Add debugging information to the PDF. Defaults to false.&#x20;*****/ debug?: boolean, /*****\* \* Custom CSS to be injected into the page before printing.&#x20;*****/ css?: string, /*****\* \* HTTP headers to be sent with the request.&#x20;*****/ httpHeaders?: Record\<string, string>, /*****\* \* LocalStorage content to be injected into the page before printing.&#x20;*****/ localStorage?: Record\<string, string>, /*****\* \* SessionStorage content to be injected into the page before printing.&#x20;*****/ sessionStorage?: Record\<string, string>, /*****\* \* Cookies to be set in the page before printing.&#x20;*****/ cookies?: Record\<string, string> }***

&#x20;       (optional) The additional PDF options.

**Return type**

&#x20;   string

**Examples**

```javascript
// Simplest example, render the form with the name 'Form1'
PDF.renderForm('Form1');

// Context can be passed to the form model with the second parameter as variables.
//  This will set the variable 'selectedClient' to 'J007' in the form model.
PDF.renderForm('Form1', { selectedClient: 'J007' });

// You can also set a nested property by using dot notation:
//  This will set the variable 'client.name' to 'John'. It will create an object 'client' with a property 'name' and 'age' in the form model.
PDF.renderForm('Form1', { 'client.name': 'John', 'client.age': 30 });

// You can also set additional PDF options, like with the create function.
PDF.renderForm('Form1', { selectedClient: 'J007' }, { landscape: true });
```

#### setPrivileges

```javascript
setPrivileges(document: string, options?: { 
        /**
         * User password. When set, the PDF will require a password to be opened.
         */
        userPassword?: string,
        /**
         * Owner password. When set, the PDF will require a password to be modified.
         */
        ownerPassword?: string,
        /**
         * Permit printing. Defaults to false.
         */
        permitPrint?: boolean,
        /**
         * Permit modifying the document. Defaults to false.
         */
        permitModifyDocument?: boolean,
        /**
         * Permit extracting content. Defaults to false.
         */
        permitExtractContent?: boolean,
        /**
         * Permit filling forms. Defaults to false.
         */
        permitFormsFill?: boolean,
        /**
         * Permit full quality printing. Defaults to false.
         */
        permitFullQualityPrint?: boolean,
        /**
         * Permit annotations. Defaults to false.
         */
        permitAnnotations?: boolean,
        /**
         * Permit assembling the document. Defaults to false.
         */
        permitAssembleDocument?: boolean
    })
```

Set the privileges of a PDF document. Returns a base64 encoded string. The User password is required to open the document for viewing and editing. The Owner password is required to change the document's permissions. All permissions are set to false by default.

**Parameters**

&#x20;   **document&#x20;*****string***

&#x20;       The PDF document to set the privileges on.

&#x20;   **options&#x20;*****{ /*****\* \* User password. When set, the PDF will require a password to be opened.&#x20;*****/ userPassword?: string, /*****\* \* Owner password. When set, the PDF will require a password to be modified.&#x20;*****/ ownerPassword?: string, /*****\* \* Permit printing. Defaults to false.&#x20;*****/ permitPrint?: boolean, /*****\* \* Permit modifying the document. Defaults to false.&#x20;*****/ permitModifyDocument?: boolean, /*****\* \* Permit extracting content. Defaults to false.&#x20;*****/ permitExtractContent?: boolean, /*****\* \* Permit filling forms. Defaults to false.&#x20;*****/ permitFormsFill?: boolean, /*****\* \* Permit full quality printing. Defaults to false.&#x20;*****/ permitFullQualityPrint?: boolean, /*****\* \* Permit annotations. Defaults to false.&#x20;*****/ permitAnnotations?: boolean, /*****\* \* Permit assembling the document. Defaults to false.&#x20;*****/ permitAssembleDocument?: boolean }***

&#x20;       (optional) The additional PDF privileges options. When set, the PDF will require a password to be opened (user password) or to modify (owner password). All other options are optional and default to false (no permission).

**Return type**

&#x20;   string

**Examples**

```javascript
// Set the privileges of a PDF document.
PDF.setPrivileges('base64encodedPDFDocument', {
  ownerPassword: 'secret',
  permitPrint: true,
  permitModifyDocument: false,
  permitExtractContent: false,
  permitFullQualityPrint: true
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rulecube.com/language-reference/pdf.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
