> For the complete documentation index, see [llms.txt](https://docs.typeset.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.typeset.sh/advanced-guides/pdf-standards/pdf-x-4.md).

# PDF/X-4

When working with printers, they typically require PDFs to be PDF/X-4 compliant. This can be achieved using the save-handler `\Typesetsh\HtmlToPdf\X4`.&#x20;

However, there are certain considerations to keep in mind when creating documents for print. All colors must be defined in CMYK, and Typeset.sh does not automatically convert colors. Therefore, it is important to ensure that colors are defined correctly in your document and CSS.

```css
html, body {
   color: cmyk(0 0 0 100%);
}
```

In PHP you can then simply use the save-handler to create X4 conform PDF documents.

```php
<?php
$html = "Hello World, I am a pdf/x-4 conform pdf!";

$service = new \Typesetsh\HtmlToPdf();
$service->saveHandler['pdf_x4'] = new \Typesetsh\HtmlToPdf\X4();

$result = $service->render($html, \Typesetsh\UriResolver::all());
$result->toFile(__DIR__.'/hello.x4.pdf');
```

### Advanced configuration

When generating a PDF, Typeset.sh keeps track of the images included in the document and their dimensions. The images are saved into the PDF only at the final step of saving the document. This allows a save-handler to alter the images before they are embedded in the PDF.&#x20;

The X4 save-handler uses the `\Typesetsh\HtmlToPdf\ImagePreflight` save-handler, which allows for resizing images based on DPI configuration and converting RGB images to CMYK. However, this process requires the [Imagick PHP extension](https://www.php.net/manual/de/book.imagick.php). Additionally, a cache path can be provided to ensure that image resizing and conversion only occurs once.

```php
<?php
$html = "Hello World, I am a pdf/x-4 conform pdf!";

$service = new \Typesetsh\HtmlToPdf();
$service->saveHandler['pdf_x4'] = new \Typesetsh\HtmlToPdf\X4(
    outputIntent: new \Typesetsh\Pdf\OutputIntent\PdfX\ECI\PSO_Coated_v3(),
    preflight: true,
    dpi: 350,
    cachePath: __DIR__.'/cache/'
);

$result = $service->render($html, \Typesetsh\UriResolver::all());
$result->toFile(__DIR__.'/hello.x4.pdf');
```
