# Export to PDF On-Premises REST API usage

The Export to PDF On-Premises converter provides the ability to convert an HTML document to a PDF file via Restful API.

The API is available on `http://localhost:[port]` (by default the `port` is `8080`).

> **Note**
>
> The REST API documentation is available at `http://localhost:[port]/v2/convert/docs`.\
> Alternatively, you can check the specifications in our public resources `https://pdf-converter.cke-cs.com/v2/convert/docs`.

If you have the authorization for the API enabled, you should provide an authorization token. More instructions you can find in the [authorization](authorization.md) section.

<a id="using-additional-http-headers">

### Using additional HTTP headers

If fetching some resources (e.g. images) used in a generated PDF requires passing an additional authorization factor in the form of additional HTTP headers:

1. It can be defined on the application startup by setting `EXTRA_HTTP_HEADERS` environmental variable where the value is a stringified JSON object with required headers.
2. It can be defined in a request sent to the PDF Converter API in `config`:

```javascript
const data = {
   html: '<p>I am a teapot</p><img src="https://secured-example-website.com/image.jpg">',
   css: 'p { color: red; }',
   config: {
	  extra_http_headers: {
		authorization: 'Bearer RDp0NqyePooNWFIWvHtbKrKKHLXfmLfZcv3PRpCyJI90uwi3pKvumKl2vymCxoGFw6Vx'
	  }
   }
};

axios.post( 'https://pdf-converter.cke-cs.com/v2/convert/html-pdf', data, config )
   .then( response => {
	  fs.writeFileSync('./file.pdf', response.data, 'binary')
   } ).catch( error => {
	  console.log( error );
   } );
```

Headers defined in the application config and from the request are merged. If the same header is defined in both places, a header value from PDF config is prioritized over the value from the application config.

---

Full index of the Cloud Services documentation: [llms.txt](../../../llms.txt)
