@imgly/pdfx-exporter
v0.3.2
Published
Export CE.SDK designs as print-ready PDF/X-1a, X-3 and X-4, with bleed; converts existing PDFs too.
Maintainers
Keywords
Readme
@imgly/pdfx-exporter
Exports CE.SDK designs as print-ready PDF/X-1a:2003, PDF/X-3:2003 or PDF/X-4, with an embedded output intent (FOGRA39, GRACoL, sRGB or your own ICC profile) and real bleed boxes. Runs in the browser and in Node.js.
It replaces @imgly/plugin-print-ready-pdfs-web 1.x; see
Migrating.
import { exportPDFX } from '@imgly/pdfx-exporter';
// Engine → PDF/X in one call: every page of the scene, with bleed.
const printReady = await exportPDFX(cesdk.engine, { outputProfile: 'fogra39' });Usage
convertToPDFX converts a PDF Blob you already have:
import { convertToPDFX } from '@imgly/pdfx-exporter';
const pdf = await engine.block.export(page, 'application/pdf');
const printReady = await convertToPDFX(pdf, {
outputStandard: 'PDF/X-4', // or 'PDF/X-3', 'PDF/X-1a'
outputProfile: 'fogra39', // 'gracol' | 'srgb' | 'custom'
title: 'Spring campaign'
});Pass an array of Blobs to convert several PDFs; the result is an array in the same order.
Options
| Option | Default | Notes |
| --------------------------- | ------------------- | ---------------------------------------------------------------- |
| maxInputSize | 100 * 1024 * 1024 | Positive safe integer in bytes; maximum size of each input Blob. |
| outputStandard | 'PDF/X-4' | 'PDF/X-1a', 'PDF/X-3' or 'PDF/X-4'. |
| outputProfile | — | Required. 'fogra39', 'gracol', 'srgb' or 'custom'. ¹ |
| customProfile | — | ICC profile Blob; required when outputProfile is 'custom'. |
| flattenTransparency | true for X-3 | PDF/X-1a flattens pages with transparency; PDF/X-4 keeps live transparency. |
| flattenResolution | 300 | Resolution in dpi for flattened pages. |
| flattenMode | 'page' | 'page' or 'region'; see below. |
| embedICCProfile | true | Embed the output profile in the output intent. |
| title | 'Untitled' | Document title in Info and XMP metadata. |
| creator | input's, 'IMG.LY' | Info Creator and XMP xmp:CreatorTool. |
| author | input's | Info Author and XMP dc:creator. |
| subject | input's | Info Subject and XMP dc:description. |
| keywords | input's | Info Keywords and XMP pdf:Keywords. |
| outputCondition | per profile | Overrides the output intent's OutputCondition. |
| outputConditionIdentifier | per profile | Overrides the output intent's OutputConditionIdentifier. |
| nonPrinterProfile | 'keep' | 'keep' or 'reject'; see below. |
¹ 'gracol' uses GRACoL 2013 CRPC6 (ICC v4, CGATS 21.2) for PDF/X-4, and GRACoL 2006 Coated #1 (ICC v2, CGATS TR 006) for PDF/X-1a and PDF/X-3, whose readers commonly accept only ICC v2.
For larger photo books, pass maxInputSize: 1024 * 1024 * 1024 to allow up to
1 GiB. The limit includes its exact boundary and applies separately to each Blob
in a batch. Raising it may require more browser or WebAssembly memory; it does
not guarantee a document of that size can be converted.
PDF/X-1a allows only CMYK and spot colours, so srgb is rejected for it.
Flattened pages and their CMYK values
PDF/X-1a, and PDF/X-3 by default, do not allow live transparency, so a page with
transparency (opacity below 100 %, a blend mode, a drop shadow, an image with an
alpha channel) is flattened: its transparency is turned into images at
flattenResolution. flattenMode decides what becomes an image and how its
colours are made:
'page'(default): the whole page becomes one image, so its text is no longer text. The page is rendered as RGB and the pixels are converted to the output profile. Pages without transparency keep their exact CMYK values, but on a flattened page they change: 100 % C prints as about 67/14/0/0 and 100 % K as a four-colour black (GRACoL).'region': only the areas that transparent objects paint become images. Set it to keep the text of PDF/X-1a and X-3 pages that have transparency; the default stays'page', and its output does not change. It needs a CMYK output profile: with an RGB output profile, as PDF/X-3 allows, the page is flattened as with'page'. The rest of the page keeps its text with embedded fonts, its photos as separate images, its spot colours and its overprint. Inside those areas, the colours are converted to CMYK first and the inks are blended as a press RIP blends live transparency, so they keep their CMYK values. A spot colour there keeps its own plate, and overprint is applied as a press applies it. Each area holds only the spot colours it prints. PDF 1.3 and 1.4, which PDF/X-1a and X-3 build on, allow one image at most 8 inks, so a page where one transparent area prints more than 4 spot colours is flattened whole and prints its spot colours as CMYK. Transparent areas look like the printed PDF/X-4, which can differ from the RGB screen preview. A flattened page can have at most 65535 pixels per side and 268 million pixels atflattenResolution. Region mode applies the pixel limit to the transparent areas only. So a large page with small transparent objects can still be exported. A page that is flattened whole keeps the page limit.Region mode handles a fixed list of PDF constructs: what CE.SDK writes. A page that holds anything else is flattened as with
'page', so region mode never guesses at content it was not built for.- On the list: DeviceGray, DeviceRGB, DeviceCMYK and ICC-based RGB colours; spot colours (Separation) with a linear tint, the All colorant of printer's marks, and indexed colours built on those; images, also with a soft mask; forms and transparency groups with their own resources; shadings and coloured patterns; alpha, soft masks without a transfer function and the separable blend modes; any embedded font, and a Type 3 font when its glyphs are plain paths or draw an image of the font, as a colour emoji does; overprint on fills, strokes and text in a plain colour.
- Not on the list: layers (optional content) anywhere in the file; a Hue,
Saturation, Color or Luminosity blend mode; a DeviceN, Lab or calibrated
colour space; a gray or CMYK ICC space; a spot colour named None, or one
whose tint transform is not linear; an uncoloured tiling pattern; an
inline image; a
qwithout itsQ, or aQwithout itsq; a resource whose name starts withPx; an overprinted image, shading, pattern, form or Type 3 text; a Type 3 glyph that sets a colour or draws a form; a form without its own resources; forms nested more than 15 levels deep; an object that contains itself; a PDF operator or graphics-state entry that region mode does not know; more than about one million content operators on the page.
A colour emoji has an alpha channel, so it is a transparent area: the emoji becomes an image and the rest of the text on its page stays text.
CE.SDK exports text with reduced block opacity as a transparency group. Region mode can rasterize that group while keeping the rest of the page.
A page on the list is still flattened whole in these cases:
Text with a semi-transparent colour, a transparent shading or pattern, a transparent object inside a form that is drawn more than once, a semi-transparent fill or stroke that also clips, a colour emoji followed by other text in the same text object or after text that clips, any annotation (also a link that does not print), page content split into several streams, or more than 64 transparent objects. Each transparent object is rendered at least four times, so the limit of 64 bounds the conversion time. It is a chosen value, not a measured one. This also applies to the cases below:
- A transparent object or group whose area cannot be measured.
- Transparent areas larger than 268 million pixels in total.
- Transparent areas that need more than about 1.5 GiB of memory, together with the images of the page.
- A page that still has transparency after its transparent areas are replaced.
The whole page becomes one image, and its CMYK values stay exact. Its spot colours keep their plates and its overprint is applied. With more than 4 spot colours on the page, or when one image per ink would need more than about 1.5 GiB of memory, the spot colours print as CMYK and overprint is not applied.
A spot colour named Cyan, Magenta, Yellow or Black, more than 60 spot colours on the page, a spot colour whose alternate is not DeviceCMYK or DeviceGray after the colour conversion (such as a CMYK ICC profile), a soft mask that shares an image, a form or resources with the page, or content the converter cannot read: the page is flattened as with
'page', so its CMYK values change. This also applies when the page and its images are so large that the CMYK image would need more than about 1.5 GiB of memory, and to a page whose spot colours cannot be matched across pages. If region mode still fails, the whole document is converted as with'page', and theLoggergets a warning that says why.
The
Loggergets a warning for each page that region mode flattens whole, with the reason, such aspage 1: region flattening is not possible (more than 64 transparent objects); the page is flattened whole. Such a page is valid PDF/X but keeps no text, so check the warnings after a conversion. A warning about the whole document comes first. After 64 warnings, one last line gives the number of warnings that are not listed.Limits of region mode on large pages and at edges:
- Large images on large pages. CE.SDK writes each image at the scene
resolution (
scene/dpi) times its size on the page, so a 52 inch wide logo at 300 dpi is about 15500 px wide. A transparent image of that size needs more than the 1.5 GiB above, so the page is flattened whole, or the conversion fails with "page too large" when the page is also above the page limit. Lowerscene/dpiandflattenResolutionfor large products: at 150 dpi a 120 x 120 inch page with a 65 inch logo converts in region mode. CE.SDK itself cannot export an image above 16384 px per side. - Drop shadows on large pages. CE.SDK writes a drop shadow as an image with the size of the page. The text of the page stays text, but the page limit of 268 million pixels then applies to the shadow, and CE.SDK cannot export it above 16384 px per side. A 44 x 87 inch page with a drop shadow does not export at 300 dpi.
- Memory. Region mode holds two renders of each transparent area, and
one more channel per spot colour. A transparent object that covers a
whole large page needs several times the memory of
'page': about 2.5 GB against 0.65 GB for a 44 x 87 inch page at 150 dpi (Node 22, macOS). - Edges. A transparent image and what is under it become one image at
flattenResolution. Its edges are fixed at that resolution, so at 300 dpi they are up to one pixel (0.08 mm) softer than in PDF/X-4, where the press software computes them at its own resolution.
const pdf = await exportPDFX(cesdk.engine, {
outputStandard: 'PDF/X-1a',
outputProfile: 'gracol',
flattenMode: 'region'
});srgb and other non-printer profiles are not PDF/X
PDF/X (ISO 15930) describes a printing condition, so its output intent must be a
printer profile (ICC device class prtr). srgb is a display profile (mntr),
and a custom profile may be a display, input or colour-space profile. Output
with such a profile is never PDF/X compliant, for any standard: Acrobat
Preflight reports "OutputIntent profile not 'prtr'" and checkPDFX reports
6.2.3 dest-profile-class. nonPrinterProfile decides what happens:
'keep'(default, as in@imgly/plugin-print-ready-pdfs-web1.x): the file is produced anyway. Use it where an RGB file with PDF/X structure (boxes, output intent, metadata) is good enough.'reject': conversion throwsOutput profile is not a printer profile (ICC device class "mntr"); PDF/X needs class "prtr"(with the profile's class) before any work is done (inexportPDFX, after the engine export).
With an RGB output intent, gray content colour is written as the equal RGB, so the only finding left is the profile class.
JPEG 2000 images are not converted
PDF/X-1a and PDF/X-3 do not allow JPEG 2000 images (/JPXDecode). CE.SDK does
not write them, but a PDF from another tool can hold one. The converter keeps
such an image as it is, so the output is not compliant, and checkPDFX does not
report it. Store these images as JPEG before you convert such a PDF.
Exporting straight from the engine
exportPDFX takes the running CE.SDK engine instead of a PDF Blob: it exports
the pages, or any other blocks, itself, with print-oriented export settings and
bleed, and returns one PDF/X — engine to PDF/X in one call. Use convertToPDFX
only for PDFs you already have.
import { exportPDFX } from '@imgly/pdfx-exporter';
// Every page of the current scene, as one multi-page PDF/X:
const printReady = await exportPDFX(cesdk.engine, {
outputStandard: 'PDF/X-4',
outputProfile: 'fogra39'
});
// Selected pages, in the order given:
const back = await exportPDFX(engine, {
outputProfile: 'gracol',
blocks: [pages[3], pages[0]]
});
// Any block — a group, an image, a text — as a page of its own, mixed with pages:
const sticker = await exportPDFX(engine, {
outputProfile: 'fogra39',
blocks: [logoGroup, pages[0]]
});It works with the browser cesdk.engine, @cesdk/node and
@cesdk/node-native (tested against @cesdk/node-native 1.83 and the native engine of @cesdk/node 1.87); the engine parameter is typed by the methods it calls
(PDFXEngine), so the package has no CE.SDK dependency. It takes every
convertToPDFX option, plus:
| Option | Default | Notes |
| --------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| blocks | every page of the scene | Block ids, one output page each, in this order. Pages get bleed (below); any other block (group, image, text, …) is exported at its own size, without bleed boxes. A scene or stack block stands for its pages. Blocks the engine cannot export fail with the engine's error. |
| exportOptions | see below | Overrides the options passed to engine.block.export. |
| title | block or scene name | One block: its name, else the scene's. Several blocks: the scene's name. Else 'Untitled'. |
For exportPDFX, maxInputSize limits the combined bytes of the exported PDFs,
before they are concatenated and converted. Engine exports remain uncapped when
this option is omitted, preserving their existing behavior.
Engine export options. Each block is exported with
engine.block.export(block, { mimeType: 'application/pdf', … }) and:
| Engine option | exportPDFX sets | Why |
| -------------------------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| exportPdfWithHighCompatibility | true | The engine's own default, set explicitly so every engine build behaves the same. It is the output the converter is validated against (corpus, legacy suite). Bitmaps and gradients are rasterised at the scene's scene/dpi (300 by default). false keeps source images and vector gradients — also passes every standard, but a sample page with a photo grew about 3× as PDF/X-4. |
| exportPdfWithDeviceCMYK | true for a CMYK output intent | CMYK and spot colours set in the scene reach the PDF as CMYK instead of a round trip through RGB. false for srgb (and RGB custom profiles): the converter does not map DeviceCMYK into an RGB intent, so PDF/X-4 with srgb would fail. Custom profiles are detected from the ICC header. |
| exportPdfWithUnderlayer | not set (off) | An underlayer is a white-ink layer for special printers, not part of a regular PDF/X job; turn it on through exportOptions. |
| printer's marks (1.83+) | not set | exportPdfWithCropMarks / exportPdfWithRegistrationMarks pass every standard with CMYK intents (the marks' All colorant fails 6.10 with srgb). They grow the MediaBox around the page and its bleed; TrimBox and BleedBox stay on the page and its bleed. With bleed they need CE.SDK 1.85+, and exportPDFX throws on an older engine instead of writing wrong boxes. In CE.SDK 1.85, a page's image fill does not cover the bleed; 1.86 adds this. |
| others | not set | pdfImageQuality, allowTextOverhang, abortSignal, onProgress, … keep the engine defaults; pass them in exportOptions. |
Overriding exportPdfWithDeviceCMYK: true with outputProfile: 'srgb' produces
a PDF/X-4 that checkPDFX rejects (rule 6.10).
Bleed. CE.SDK keeps a page's bleed in page/marginEnabled and
page/margin/{top,bottom,left,right} (design units), and engine.block.export
(1.83) includes those margins for a page in a VerticalStack or
HorizontalStack scene but exports the page area alone in a Free or
DepthStack scene. For a page with bleed enabled and any margin above 0,
exportPDFX exports a hidden copy of the page, enlarged by the margins, with
its own margins turned off and its content shifted by the left/top margins, so
whatever reaches into the bleed is printed, once, in every scene layout. The
output page then has MediaBox = BleedBox = page + bleed and TrimBox = the page. The engine snaps the page size to whole device pixels at
scene/dpi, so the TrimBox can be off by a device pixel or two (at most 0.5 pt
at 300 dpi).
Pages without bleed, and blocks other than pages, get TrimBox = MediaBox.
The copy lives only while it is exported: it is made invisible (it never shows
in an editor, but engine.scene.getPages() lists it for the duration of the
export) and destroyed in a finally, children first (destroying a page leaves
its children's fills and shapes behind in CE.SDK 1.82 and 1.83). The scene is
left as it was, whether or not the export succeeds. exportPDFX does not touch
undo histories: the copy is added and removed between two undo steps, so it
nets out of the next one, but an undo step the host app records while an export
runs would contain it. (A scratch history was tried and dropped: in
@cesdk/node-native 1.83, once the active history has been switched, an export
discards pending changes.) Overlapping exportPDFX
calls on the same engine object run one after the other. Limits: the copy's
direct children are placed with absolute positions and sizes taken from their
current frames, and a page's own fill (e.g. a background image fill on the page
itself) is stretched across the bleed by the engine.
Each page is exported separately and the pages are merged before conversion, so fonts used on several pages are embedded once per page (about 7% larger than a single scene export in a six-page text test).
Checking conformance
import { checkPDFX } from '@imgly/pdfx-exporter';
const violations = await checkPDFX(printReady, 'PDF/X-4');
// [] when the file conforms; otherwise { rule, message, object } per findingLoading
The first conversion or conformance check loads the WebAssembly engine from
a JavaScript module in wasm/. The package can be imported by name in browser
bundlers and in Node.js. If serving the package files directly, serve dist/
and wasm/ as siblings. The engine needs Node.js 22+ or a current browser
with WebAssembly SIMD (Chrome, Firefox, Edge, Safari 16.4+).
Logging
import { Logger } from '@imgly/pdfx-exporter';
Logger.setLogLevel('info'); // 'debug' | 'info' | 'warn' (default) | 'error'
Logger.getLogs(); // most recent 1000 entries
Logger.clearLogs();Migrating from @imgly/plugin-print-ready-pdfs-web 1.x
- Uninstall
@imgly/plugin-print-ready-pdfs-web, install this package and change the import specifiers; the API is unchanged:convertToPDFX, the deprecatedconvertToPDFX3(defaults to PDF/X-3),Loggerand the validation error messages behave as in 1.82 and 1.83. - New:
outputStandard: 'PDF/X-1a',flattenResolution,flattenMode,nonPrinterProfile,checkPDFXandexportPDFX(pages with bleed, or any block). srgboutput is converted as before but is not PDF/X compliant (it never was: sRGB is not a printer profile);checkPDFXsays so. PassnonPrinterProfile: 'reject'to refuse it.- Removed:
ghostscriptArgs. The converter no longer uses Ghostscript, so passing a non-emptyghostscriptArgsthrowsghostscriptArgs is not supported: this build does not use Ghostscript. - Not supported: the
signal,timeoutMs,maxOutputBytesandruntimeoptions added in 1.84. TypeScript rejects them; plain JavaScript ignores them. - The engine uses WebAssembly SIMD, so it needs Safari 16.4+ (CE.SDK itself supports Safari 15.6+); see Loading.
- The ICC profile licences ship in
ICC-PROFILE-LICENSES.md.
License
See LICENSE.md. This software is based in part on the work of the Independent JPEG Group.
