PNG images, blank documents, font metrics, and link URIs in the in-house core
2026-11-18T13:26:35.317Z
PNG images, blank documents, font metrics, and link URIs in the in-house core
@signature-kit/pdf-core gains what stamping needs to stop depending on pdf-lib. The png edit operation decodes a PNG (every color type and bit depth, Adam7 interlacing, palette and tRNS transparency) into an 8-bit image XObject with an /SMask when any pixel is not opaque; input is bounded to 16 MiB, 16 Mi pixels, and 64 MiB of decoded scanlines. PdfCore.create({ pages }) writes a new document with blank pages, and PdfCore.fontMetrics(baseFont) returns the WinAnsi Unicode mapping and advance widths of the twelve WinAnsi standard-14 fonts. PdfCore.document now reports the uri of link annotations with a URI action (document payload version 2). PdfCore.pngSize(png) runs the same bounded decoder and returns the image width and height; the decoder rejects animated PNG chunks, bytes after IEND, and image data that inflates beyond its scanlines. The addResource edit operation now fails with pdfCore.INVALID_OPTIONS when the page already binds the name to a different object instead of overwriting it. The wasm module exports three new functions, pdf_core_create, pdf_core_font_metrics, and pdf_core_png_size.
@signature-kit/pdf no longer uses pdf-lib
@cantoo/pdf-lib is no longer a dependency. Visible signatures, structured badges, QR codes, initials and line rubrics, PNG images, footer links, stamp previews, and illustrative documents are drawn as content streams appended through PdfCore.edit, with the same geometry as before; signed PDFs are always updated incrementally, unsigned ones incrementally unless their cross-reference chain needs a rewrite. Text is measured with the Helvetica metrics from PdfCore.fontMetrics and drawn with WinAnsi encoding (Latin-1 plus €, typographic quotes, and dashes); text with characters outside WinAnsi fails with pdf.STAMP_FAILED, as it did before. Every stamp names its fonts and images after the document's next object number, so a later stamp on the same page never repaints an earlier, possibly signed, appearance. Rounded badge corners and lock icons are drawn as cubic curves converted exactly from their quadratic outlines (pdf-lib drew them with the v operator, which bulges the corners slightly). PNG input is validated by the core decoder; stamping no longer inflates PNG data in JavaScript. Failures reported by the core keep their reason, and core limit failures surface as pdf.LIMIT_EXCEEDED. Badge layout no longer adds kerning to measured widths that were drawn without it, so badge text and footer separators sit where they are drawn. mergePdfs uses PdfCore.merge, and removePdfLinkAnchors removes the matching annotations from /Annots.
Breaking changes:
PdfCoreis now required bystampPdfVisibleSignatures,createPdfStampPreview,createIllustrativePdf,loadPdfSignatureDocument,createPdfSignatureTemplateFromBytes, andcreatePdfSignatureBuilderStateFromBytes.layoutPdfSignatureBadge(badge, container, regularFont, boldFont)takesPdfStandardFontmetrics; load them with the newloadPdfStandardFont("Helvetica")from@signature-kit/pdf/stamp.The pdf-lib
PDFPagehelpersvisiblePdfPageSize,pdfCoordinateTupleFromTopLeftRect, andtopLeftRectFromPdfCoordinateTupleare removed; usevisiblePdfPageSizeFromGeometry,pdfCoordinateTupleFromPdfPageGeometry, andtopLeftRectFromPdfPageGeometrywith thecropBoxandrotateof aPdfCore.documentpage.isSafePdfStampPngnow requiresPdfCore.PdfWorker.previewis typed as(input) => Effect<Uint8Array, PdfError>instead of the type ofcreatePdfStampPreview.
ITI conformance tests
The @signature-kit/iti tests build and tamper with PDFs through PdfCore and no longer depend on pdf-lib. The local conformance suites run over both classic cross-reference tables and object-stream PDFs with cross-reference streams.