# 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');
```


---

# 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.typeset.sh/advanced-guides/pdf-standards/pdf-x-4.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.
