Skip to content

Migrate printed HTML or react-pdf to Pressjet

Start with a document people already receive. Keep its CSS, fonts and images beside it, and save reference PDFs for representative inputs. Include the longest document and a case with repeated table headers.

From Puppeteer

Capture the print-ready HTML your application passes to Chrome. Preserve @page, print CSS, page breaks and running headers. Supply images and fonts as inline data or attachments to keep rendering reproducible. If JavaScript fills the page, run that data preparation in the application and pass the resulting HTML to Pressjet.

pressjet check invoice.html
pressjet render invoice.html -o pressjet.pdf

The check reports unsupported CSS and missing resources. Compare extracted text, the first and last rows on each page, and page-edge headers. Move material differences into test fixtures.

From react-pdf

Keep the invoice data and component boundaries. Use semantic HTML to express the layout through the React WASM adapter. Map the document to an html element with a language and title, page boundaries to print CSS, headings and paragraphs to their HTML elements, and repeated rows to an HTML table with thead. The example renders the old and new components with the same data.

import { renderPdf } from '@pressjet/wasm/react';

const { pdf, diagnostics } = await renderPdf(renderer, <Invoice data={data} />, {
  stylesheets: [invoicePrintCss],
});

Run both comparisons

Use a shell with Node.js and Poppler. Download the WASM tarball from the GitHub release and install it alongside the renderers in a clean directory.

npm install react react-dom puppeteer-core @react-pdf/renderer /path/to/pressjet-wasm-0.1.0-beta.6.tgz
cp /path/to/pressjet/examples/migration/render.mjs .
mkdir -p puppeteer react-pdf
CHROME_PATH=/path/to/chrome node render.mjs puppeteer puppeteer
node render.mjs react-pdf react-pdf

Each comparison checks the ordered text on both pages, writes the two PDFs and reports the Pressjet diagnostics. Review the finished PDFs before migrating customer templates.