PDFPipe

The document is wrong

Charts and canvas elements are blank in the PDF

A correctly sized empty rectangle where the chart should be. The axis labels are sometimes there and the plot area never is.

What is actually happening

A canvas element draws imperatively. If the drawing call has not run by the time the page is captured, the canvas is a blank bitmap of the right dimensions, which is exactly what you are looking at. SVG-based charts do not have this problem because the shapes are in the DOM.

Confirming it is this and not something that looks like it

If the chart library can output SVG, switch it for one render. If the chart appears, the cause was the canvas timing and not the data.

The fix

Render the chart to SVG on the server and put the markup in the document. Most chart libraries have a server-side or static rendering mode for exactly this, and the output is vector rather than a bitmap, so it stays sharp at print resolution.

If that was not it

These produce the same symptom often enough to be worth ruling out before assuming the fix above did not work.

  • A chart with an animation duration, where the render catches it partway through
  • A canvas sized by JavaScript from its container, which is zero-width before layout settles
  • WebGL charts, which need a GPU context that a headless render may not have
  • Chart fonts loaded separately, which shift labels after the snapshot

Frequently asked

Does this happen with every rendering engine?

The behaviour behind it is not specific to one tool. A canvas element draws imperatively. Anything rendering HTML to a paged medium has to make the same decision, so the fix travels with you if you change how the render happens.

Will this show up as an error in my logs?

No, and that is what makes it expensive. A document that renders wrong is still a successful render as far as every log line is concerned. It is found by someone opening the file, which is usually the customer.

Related failures

Problems people arrive at from the same starting point, or mistake for this one.

Paste your markup and see the rendered document, without signing up.