Warnings
9 warning codes in daeepdf 1.2.0. An export finishes even when part of a template can't print, and says what on the file's warnings, each with one of these codes. With strict it throws instead.
Each entry says what leads to it, what the PDF holds instead, and how to get rid of it, with an example that was run in Chrome against 1.2.0.
Fonts and text
Text an export couldn't draw. daeepdf draws only the fonts a template declares with @font-face, as TTF, OTF or TTC files, and fallbackFont. Unlike Chrome's print, it never takes a font installed on the computer, so text with no font of its own is left out, and these warnings say which font and why. Every warning comes back on PdfFile.warnings as a PdfWarning, each message once, and is logged to the console as it happens.
'font-not-declared'Text was left out because no font the template declares can draw it.
It comes from text whose
font-familynames no font the template declares with@font-face. A family that was never declared counts, and so do a generic one likesans-serifand text with nofont-familyat all, which falls to the browser's default font: daeepdf draws only the template's own fonts. A declared font that failed to load counts too, after its own'font-not-loaded'. Vertical text is checked the same way, and so is the text of a header or footer, which uses the template's fonts.A text or choice field draws its value in its own font, else in the nearest ancestor's, else in any font the template declares, so it is left out only when the template declares none at all, and the warning names the field. That holds with
fillable: falsetoo. Checkboxes and radio buttons need no font.The text is left out: it isn't drawn and isn't in the PDF's text, so it can't be found or copied. Its box, background and borders still print, and the text around it keeps its place, since Chrome laid it all out. Chrome's print would draw it in a font from the computer. There is one warning per family, or per field, however often it appears.
To fix it, declare the font with
@font-facein the template's<style>, pointing at a TTF, OTF or TTC file, and name it infont-family. Or setfallbackFont: text in no declared font then prints in that font, with no warning.import pdf from 'daeepdf' const html = `<style> @font-face { font-family: Inter; src: url('/fonts/inter-var.ttf'); } body { font: 12pt Inter; } .brand { font-family: Roboto, sans-serif; } </style> <p>Set in Inter</p> <p class="brand">Set in Roboto, which the template never declares</p>` const file = await pdf.render(html) file.warnings.map((w) => w.code) // ['font-not-declared'] file.warnings[0]?.message // 'Font "Roboto" is not registered – text skipped. Declare it with @font-face …' // With a fallback font, that paragraph prints in it const fixed = await pdf.render(html, { fallbackFont: '/fonts/inter-var.ttf' }) fixed.warnings // []'font-not-loaded'A font the template declares couldn't be loaded, so nothing is drawn in it.
It comes from a
@font-facewhose file couldn't be used: the fetch failed or came back with an error status, the file was still loading whenloadTimeoutran out, it is over 64 MB once itsContent-Encodingis decoded, or it isn't a TTF, OTF or TTC file. WOFF and WOFF2 are the usual case: daeepdf embeds a font as it is and can't unpack them. The message names the font, its URL and which of these it was.Of a
srclist, daeepdf fetches the firsturl()that aformat()or the file's extension marks as TTF, OTF or TTC, else the firsturl(), and the bytes decide what it is. It reads nolocal()font, so a face with onlylocal()sources gets no warning here, only'font-not-declared'for its text. A header or footer's own@font-facerules are loaded the same way, and afallbackFontthat fails is reported under the familydaeepdf-fallback.Text set in the font has no font left: it prints in the next family of its
font-familylist that loaded, or infallbackFont, or it is left out with a'font-not-declared'warning. A failed fetch isn't remembered, so the next export asks for the file again.To fix it, serve the font as a TTF, OTF or TTC file from a URL the page can fetch: the same origin, or one that allows it with CORS. The browser's network panel shows the failed request.
import pdf from 'daeepdf' const html = `<style> @font-face { font-family: Brand; src: url('/fonts/brand.ttf'); } body { font: 12pt Brand; } </style> <p>Set in Brand</p>` // The file isn't on the server, so the fetch comes back 404 const file = await pdf.render(html) file.warnings.map((w) => w.code) // ['font-not-loaded', 'font-not-declared'] file.warnings[0]?.message // 'Could not load font "Brand" from /fonts/brand.ttf: Failed to fetch font … 404' // A fallback font catches its text, though the font itself is still reported const caught = await pdf.render(html, { fallbackFont: '/fonts/inter-var.ttf' }) caught.warnings.map((w) => w.code) // ['font-not-loaded']'glyph-missing'Under PDF/A or PDF/UA, characters no font has a glyph for were left out.
It comes only with
pdfAorpdfUA, which both forbid drawing a font's.notdefglyph, the shape a font draws for a character it lacks. A character is missing when its own font, the other families of itsfont-familylist and every other font the template declares all lack it. Chrome's print would find it in a font on the computer, which daeepdf never uses.Each such character is left out of the drawing, its width kept as space so the line doesn't close up. It stays in the PDF's text, so it can still be found and copied. One warning counts them all: "PDF/A and PDF/UA: 2 character(s) have no glyph in any registered font".
Without
pdfAorpdfUAthere is no warning: the character draws as its font's.notdefglyph.To fix it, declare a font that covers those characters, a Noto font for the script for instance, and list it in
font-familyafter the main one: each character the first font lacks is taken from the next family that has it.import pdf from 'daeepdf' const html = `<style> @font-face { font-family: Inter; src: url('/fonts/inter-var.ttf'); } body { font: 12pt Inter; } </style> <p>Total: 42 元</p>` // Inter has no Chinese characters, so 元 has no glyph const file = await pdf.render(html, { pdfA: true }) file.warnings.map((w) => w.code) // ['glyph-missing'] // Without PDF/A it draws as Inter's .notdef glyph, and nothing is said const plain = await pdf.render(html) plain.warnings // []
Images and CSS
What an export skipped or simplified: images it couldn't read or draw, stylesheets a template can't load, 3D transforms, and the safety limits that warn when they're reached. The export still finishes, and everything else in it prints as it should. With strict, any of these makes the export throw 'strict' instead.
'image-skipped'An image, canvas or SVG couldn't be read or drawn, and was left out.
For an
<img>, or aurl()image inbackground-image,mask-image,border-image-sourceorlist-style-image, the message gives the reason and the URL: the file couldn't be fetched (an error status, a network failure, orloadTimeoutrunning out for a CSS image), adata:URL is malformed, the bytes are no image format daeepdf knows, or the format is one it doesn't draw: GIF, BMP and ICO, which Chrome's print draws, are skipped, as is TIFF, while JPEG, PNG, WebP, AVIF and SVG print. An image the browser can't decode is skipped too, as is one over 50 megapixels that must be decoded, and a PNG or decoded image past the export's 64-megapixel raster budget. So is abackground-imagelayer that is neither aurl(), animage-set()nor a gradient.A
<canvas>over 16 megapixels is skipped, as is one with a side longer than the browser can back. A template has no scripts, so its canvases are always blank. An SVG that can't be drawn as vectors is drawn from the browser's own rendering, and when the browser can't load it either, as with broken markup, it is skipped with "SVG rasterization failed". UnderpdfA, a CMYK JPEG without a color profile is converted to sRGB, and skipped when the browser can't decode it.Nothing is drawn in the image's place. Its box keeps the size, background and border Chrome gave it. Each message is reported once, so a missing URL used ten times is one warning. An
<img>still loading whenloadTimeoutruns out is left out with this warning too, "still loading after the 10 s loadTimeout".To fix it, use JPEG, PNG, WebP, AVIF or SVG files the page can fetch, convert a GIF to PNG, and keep a PNG under 50 megapixels. The message says which file.
import pdf from 'daeepdf' const gif = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' const file = await pdf.render(` <img src="/images/logo.png" alt="Logo" style="width: 1in"> <img src="/images/chart.png" alt="Chart" style="width: 1in; height: 1in"> <img src="${gif}" alt="Spacer" style="width: 1in; height: 1in">`) file.warnings.map((w) => w.code) // ['image-skipped', 'image-skipped'] file.warnings.map((w) => w.message.split(':')[0]) // ['Image skipped – could not be fetched', 'Image skipped – GIF is not supported']'stylesheet-removed'A
<link>stylesheet or an@importin the template was removed.A template's CSS goes in its own
<style>blocks andstyleattributes, which daeepdf parses and scopes to the template. Each<link rel="stylesheet">is removed with this warning, and so is each@importrule in a<style>block, the rest of the block kept. Every other<link>is removed too, analternate stylesheetamong them, without a warning. A header or footer is checked the same way.The document is laid out without those rules, so what they styled prints with the template's own CSS. Your app's stylesheets are another matter: with
useAppStyles, the default, the page's own<link>and<style>sheets apply to the template, and nothing here touches them.To fix it, put the stylesheet's rules in a
<style>block of the template. CSS your app and its templates share can stay in the app's stylesheets withuseAppStyleson, or go in a string you add to each template.import pdf from 'daeepdf' const file = await pdf.render(`<link rel="stylesheet" href="/css/print.css"> <style> @import url('/css/brand.css'); @font-face { font-family: Inter; src: url('/fonts/inter-var.ttf'); } body { font: 12pt Inter; } </style> <p>Styled by the <style> block alone</p>`) file.warnings.map((w) => w.code) // ['stylesheet-removed', 'stylesheet-removed']'unsupported-css'An element with a 3D transform was drawn with no transform at all.
It comes from a transform with depth: a
transformthat Chrome computes to a 3D matrix, asrotateX(),rotateY()andperspective()make, or atranslatewith a z part, arotateabout an axis, or ascalewith three values. A 3D function that leaves the element flat, liketranslateZ(0)orrotateY(0deg), computes to a 2D matrix and gets no warning, and neither does theperspectiveproperty on its own.The element and everything in it print as if its transform were
none, its 2D part included, in the place it would have without one. Chrome's print draws the 3D projection; daeepdf has no 3D drawing and draws the element flat rather than at a wrong angle.To fix it, use a 2D transform:
rotate(),scale(),skew(),translate()andmatrix()print with no warning.import pdf from 'daeepdf' const card = (transform: string) => pdf.render(`<style> @font-face { font-family: Inter; src: url('/fonts/inter-var.ttf'); } body { font: 12pt Inter; } </style> <div style="width: 2in; padding: 12pt; border: 1pt solid; transform: ${transform}">Card</div>`) const tilted = await card('perspective(400px) rotateY(20deg)') tilted.warnings.map((w) => w.code) // ['unsupported-css'], and the card prints untransformed const turned = await card('rotate(-3deg)') turned.warnings // []'limit-reached'The export reached one of its safety limits, and drew something more simply or left it out.
daeepdf bounds what a template can make an export spend, so a runaway or crafted template can't hang the page or exhaust its memory. Seven limits warn when they're reached, each once per export, and the message says which.
The raster budget, 64 megapixels per export: filters, masks, conic gradients, border images, canvases, SVGs drawn from the browser's rendering, PNG images and images the browser decodes are left out past it, and color bitmap glyphs draw their outline instead. Background and mask layers: past the first 32 of a
background-imageormask-image, the rest aren't drawn. The page-break pass: past 30 fixes a page (300 for a short document), later page ends aren't fixed, so a line or a box can be cut by a page's edge, part on each page.Copies of
clip-pathshapes: a box with one that spans pages gets a copy on each page, at most 1,000,000 path segments per export; past that, later ones clip to their bounding box. Links and fields in fixed content: those inposition: fixedelements are copied to every page, at most 50,000 annotations per export; past that, a fixed element's links and fields stay on its own page while its drawing still repeats. Fonts for text the browser draws: past 12 MB per layout, text in an SVG drawn as an image, or under a filter or mask, prints in the browser's fallback font. A fillable field's font: past 4,096 glyphs, its fields carry only its Latin characters.Every other limit works without a warning. The limits list has each one, its value and what happens past it.
To fix it, ask less of the export: fewer or smaller raster effects, photos as JPEG rather than PNG (a JPEG is embedded as it is and costs nothing of the raster budget), and less in fixed elements. A document that hits the page-break cap, which takes about 300 pages of text, has to be split into several exports to print whole.
import pdf from 'daeepdf' // 33 stacked gradient layers, one more than daeepdf draws const layers = Array.from({ length: 33 }, (_, i) => `linear-gradient(${i * 11}deg, #0001, transparent)`) const file = await pdf.render(`<div style="height: 2in; background-image: ${layers.join(', ')}"></div>`) file.warnings.map((w) => w.code) // ['limit-reached'] file.warnings[0]?.message // 'Layers past the first 32 of a background-image or mask-image are skipped.'
Accessibility and navigation
Markup that pdfUA or bookmarks needs and the template lacks. The PDF is still written: 'alt-missing' leaves figures a PDF/UA checker will fail, and 'bookmark-target-missing' leaves one bookmark out of the outline.
'alt-missing'Under PDF/UA, images had no alternative text.
It comes only with
pdfUA. PDF/UA requires alternative text on every figure, and each<img>and inline<svg>is a figure in the tagged PDF, its alternative text its accessible name as Chrome's tagged print takes it:aria-labelledby,aria-label,alt, an SVG's<title>, thentitle. One counts when it has none of them.alt=""marks an image as decoration, which needs no text. Background images and canvases aren't figures, and never count.One warning counts them all: "PDF/UA: 2 image(s) have no alternative text". The PDF is still written and still declares PDF/UA-2, but those figures break its rule, so a PDF/UA checker will fail it.
To fix it, give each image an
altthat says what it shows, oralt=""when it only decorates. An inline SVG takes a<title>or anaria-label.import pdf from 'daeepdf' const file = await pdf.render(`<html lang="en"><style> @font-face { font-family: Inter; src: url('/fonts/inter-var.ttf'); } body { font: 12pt Inter; } </style> <p>Quarterly report</p> <img src="/images/photo.jpg" alt="The team at the spring offsite" style="width: 2in"> <img src="/images/logo.png" style="width: 0.5in"> <img src="/images/logo.svg" alt="" style="width: 0.5in">`, { pdfUA: true, title: 'Quarterly report' }) file.warnings.map((w) => w.code) // ['alt-missing']: the PNG logo has no alt file.warnings[0]?.message // 'PDF/UA: 1 image(s) have no alternative text – add alt (or alt="" for …''bookmark-target-missing'A bookmark pointed at an id no element has, or a page past the last, and was left out.
It comes from a
Bookmarkin abookmarkslist whoseBookmark.targetnames an id that no element in the laid-out document has: a typo, a section the template doesn't hold this time, or an element that isdisplay: none.bookmarks: truebuilds the outline from the headings themselves and never warns.A
{ page }target past the document's last page warns the same way, naming the page and the last one.The bookmark is left out of the outline, and the warning names it and its target. Its
Bookmark.childrenstay, each moved up a level into its place.To fix it, give the element the id, or leave the bookmark out of the list when its section isn't there.
import pdf from 'daeepdf' const file = await pdf.render(`<style> @font-face { font-family: Inter; src: url('/fonts/inter-var.ttf'); } body { font: 12pt Inter; } </style> <h1 id="summary">Summary</h1> <h2>Totals</h2>`, { bookmarks: [{ title: 'Summary', target: '#summary' }, { title: 'Totals', target: '#totals' }], }) file.warnings.map((w) => w.code) // ['bookmark-target-missing']: no element has id="totals" file.warnings[0]?.message // 'The bookmark "Totals" points at #totals, which no element has – left out.' // The outline holds Summary alone