Typeset.sh
HomeNewsDemoPricing
  • Getting started
    • Installation
    • Using typeset.sh
    • First template
    • CSS and paged media
      • Page counters
      • Page selectors
      • Page groups
      • Running elements
      • Bleed area
    • Convert from URL
    • Document Metadata
    • Changelog
  • Advanced guides
    • QR codes
    • Save handlers
    • Error handling
    • Signing a PDF
    • PDF Standards
      • ZUGFeRD
      • PDF/A
      • PDF/UA
      • PDF/X-4
    • Color profiles
    • JavaScript
    • Common Object/Classes
      • createPdf function
      • HtmlToPdf
      • Result Object
Powered by GitBook
On this page
  1. Advanced guides
  2. PDF Standards

PDF/X-4

Create print ready documents

PreviousPDF/UANextColor profiles

Last updated 2 years ago

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.

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.

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
$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.

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 . Additionally, a cache path can be provided to ensure that image resizing and conversion only occurs once.

<?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');
Imagick PHP extension