# Customizing the PDF

## Job parameters

When creating jobs, the following parameters are available to customize the PDF output.

You can set these parameters either as form data or as a JSON object in the body of the request.

{% tabs %}
{% tab title="JSON" %}
This is an example of submitting parameters as a JSON object, using the `curl` command line tool. This example uses an external file - `body.json` - which contains the API parameters as JSON-formatted data.

{% code title="body.json" %}

```javascript
{
  "url": "https://en.wikipedia.org/wiki/Airplane",
  "footer_template": "<div style=\"width=100%; font-size: 12px; text-align: center\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>",
  "margin_bottom": "2cm"
}
```

{% endcode %}

```
$ curl -u myapp-api-key: \
  --data @body.json \
  --header "Content-Type: application/json" \
  https://api.paperplane.app/jobs

{
  "id": "29d89d2f-1a4f-4bcc-a2ff-16ca6e90e635",
  "url": "https://en.wikipedia.org/wiki/Airplane",
  "status": "queued",
  "done": false,
  "object": "job"
}
```

{% endtab %}

{% tab title="Form data" %}
Here's how you might use `curl` to make a request using form data from the command line:

```
$ curl -u myapp-api-key: https://api.paperplane.app/jobs \
  -d url="https://en.wikipedia.org/wiki/Airplane" \
  -d margin_top=0.5cm \
  -d margin_bottom=0.5cm \
  -d page_size=A4

{
  "id": "a43ad1ff-ee2a-4c32-b279-eef51cc46d12",
  "url": "https://en.wikipedia.org/wiki/Airplane",
  "status": "queued",
  "done": false,
  "object": "job"
}
```

{% endtab %}
{% endtabs %}

| Parameter name                                                                                                                     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ---------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url` (required)                                                                                                                   | The url parameter is required and is the web address that will be loaded and used to render the PDF.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `landscape`                                                                                                                        | <p>Set this to “true” to use landscape orientation.</p><p></p><p><em>Default: false</em></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>margin\_top</code></p><p><code>margin\_right</code></p><p><code>margin\_bottom</code></p><p><code>margin\_left</code></p> | <p>Use these parameters to set the size of the page margins. The value must be a number and by default will be interpreted as inches. You can set a margin size in centimetres by suffixing the value with “cm”. For example, these are all valid margins:<br></p><ul><li>1 (interpreted as 1 inch)</li><li>1.25 (interpreted as 1.25 inches)</li><li>1.25in</li><li>1.25cm</li></ul><p><em>Default: 1cm</em></p>                                                                                                                                                                                                                                                                                                     |
| `page_size`                                                                                                                        | <p>The page size can be set to one of the following values:</p><p></p><ul><li>Letter</li><li>Legal</li><li>A3</li><li>A4</li><li>A5</li></ul><p>Alternatively you can specify a custom page size. See the <a href="#custom-page-sizes">section on custom page sizes</a> below to learn how to do this.</p><p></p><p><em>Default: Letter</em></p>                                                                                                                                                                                                                                                                                                                                                                      |
| `scale`                                                                                                                            | <p>Allows you to scale the size of the page content up or down. The minimum scale value is 0.1 and the maximum is 2.</p><p></p><p><em>Default: 1</em></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `screen`                                                                                                                           | <p>Set this to "true" to ignore any print styles on the page, and instead emulate the screen CSS media type.<br></p><p><em>Default: false</em></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| <p><code>header\_template</code></p><p><code>footer\_template</code></p>                                                           | <p>These parameters allow you to provide an HTML template that will be used to insert a header or footer on each page. Take a look at the <a href="guide-header-and-footer-templates">header and footer templates guide</a> for more information about setting up a template.</p><p></p><p><em>Default: No header or footer</em></p>                                                                                                                                                                                                                                                                                                                                                                                  |
| `wait_network`                                                                                                                     | <p>Set this to "true" to cause Paperplane to wait until network activity has paused before generating the PDF.</p><p></p><p>This option is useful if you're using a client-side framework like <strong>React</strong> or <strong>Angular</strong> to build your document. When using client-side frameworks, PDFs can sometimes be captured too early and miss some content or images. By waiting until all network activity has stopped for a short period, it's usually possible to reliably generate the PDF once all page content has been loaded. Using this option is recommended if you're using any sort of client-side javascript framework.</p><p></p><p><em>Default: false</em></p>                        |
| `wait_network_time`                                                                                                                | <p>For use in conjunction with <code>wait\_network</code>. This option controls how many seconds of network inactivity is required before the PDF is captured.</p><p></p><p>The <code>wait\_network\_time</code> value must be a number between 0 and 20.</p><p></p><p><em>Default: 2 seconds (used if <code>wait\_network</code> is set but this option is not)</em></p>                                                                                                                                                                                                                                                                                                                                             |
| `wait_time`                                                                                                                        | <p>If the page content isn't immediately visible, you can instruct Paperplane to wait up to 20 seconds before generating the PDF. This delay will allow time for your content to fully load.</p><p></p><p>The <code>wait\_time</code> value must be a number between 0 and 20.</p><p></p><p><em>Default: 3 seconds</em></p>                                                                                                                                                                                                                                                                                                                                                                                           |
| `wait_css_selector`                                                                                                                | <p>If the page content is not immediately visible, you can instruct Paperplane to wait for an element matching a specific CSS selector to be loaded.</p><p></p><p>This is an alternative to the <code>wait\_time</code> option which gives you finer control over exactly when the PDF starts generating. You might find this useful if you have a single-page app or a page with a lot of dynamic content.</p><p></p><p>You can set <code>wait\_css\_selector</code> to any valid CSS selector - for example:</p><p></p><ul><li><code>.container</code></li><li><code>body > .container</code></li><li><code>#main-content</code></li></ul><p><em>Default: Not set (Does not wait for any matching element)</em></p> |
| `file_name`                                                                                                                        | <p>Sets a custom file name to use when uploading to S3. If not set, the PDF will be uploaded as <code>\[id].pdf</code> - for example <code>acf9e87a-ab9f-4340-986b-647c7db28b64.pdf</code>.</p><p><br>Files can be placed in a directory structure by using <code>/</code> to separate directory names - for example <code>Reports/Customer-1234/2019-01-01.pdf</code>.</p><p><br>Note that if you use the same file name twice, the existing file will be overwritten.</p><p></p><p>Adding a <code>.pdf</code> extension to the file name isn't required, but is strongly recommended.</p><p></p><p><em>Default:</em> <code>\[id].pdf</code></p>                                                                     |
| `attachment`                                                                                                                       | <p>Setting this to "true" will result in the file being downloaded by the browser rather than displayed inline.</p><p><br>This option is mainly useful when <a href="https://s3-ap-southeast-2.amazonaws.com/paperplane-testing-local.nick.cloud/attachment.pdf">making PDFs directly downloadable</a>.<br><br>If you're <a href="https://s3-ap-southeast-2.amazonaws.com/paperplane-testing-local.nick.cloud/attachment.pdf">generating a pre-signed URL</a> using the Amazon SDK, then you have the option of setting "content disposition" to "attachment" when generating the URL, which will have the same effect.</p><p></p><p><em>Default:</em> false</p>                                                      |
| `username`                                                                                                                         | <p>If set, this username will be used if HTTP Basic Auth is requested.</p><p></p><p>For more information see our <a href="guide-securing-access-to-html-documents">guide on securing access to documents</a>.</p><p></p><p><em>Default: Not set</em></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `password`                                                                                                                         | <p>If set, this password will be used if HTTP Basic Auth is requested. If <code>password</code> is set, you must also provide a <code>username</code>.</p><p></p><p>For more information see our <a href="guide-securing-access-to-html-documents">guide on securing access to documents</a>.</p><p></p><p><em>Default: Not set</em></p>                                                                                                                                                                                                                                                                                                                                                                              |
| `http_success`                                                                                                                     | <p>Setting this to "true" will result in the PDF conversion job failing (with the <code>creation\_failed</code> status) if the HTTP response from the URL is in the 400 or 500 range. For example, 401, 404 etc.</p><p></p><p><em>Default:  false</em></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

## Custom page sizes

To use a custom page size, provide `height` and `width` values within the `page_size` parameter.

{% tabs %}
{% tab title="JSON" %}
Here's an example of specifying a custom page size using JSON:

```javascript
{
  "url": "https://en.wikipedia.org/wiki/Paper_size",
  "page_size": {
    "height": "10in",
    "width": "10in"
  }
}
```

{% endtab %}

{% tab title="Form data" %}
Here's an example of using `curl` to set a custom page size:

```
$ curl -u myapp-api-key: https://api.paperplane.app/jobs \
  -d url="https://en.wikipedia.org/wiki/Paper_size" \
  -d "page_size[height]"="10in" \
  -d "page_size[width]"="10in"
```

{% endtab %}
{% endtabs %}

### Size units

You can specify page height or width in millimetres (`mm`) or inches (`in`). If you don't specify a unit, inches are assumed. For example, these are all valid heights or widths:

* `11.5in`
* `8in`
* `300mm`
* `155mm`
* `12` (interpreted as 12 inches)
