Repository navigation
Description
Existing documentation URL(s)
What changes are you suggesting?
The example's successful invoice path should produce a readable PDF invoice as the bytes of its application/pdf attachment.
Additional information
Summary
The documented invoice Worker returns success and passes a PDF attachment to its email binding. PDF validation reports structural damage in the generated file.
Runtime or environment
Published Cloudflare developer documentation and its production source baseline. Local probe used Node v26.13.1 and qpdf 12.4.2.
Steps to reproduce
- Copy the TypeScript blocks from the Email attachments tutorial into one
probe.mtsfile in page order. Name the handlerconst worker = {...}so the local probe can call it. - Append the fixture below. Run it with a recent Node that can strip TypeScript syntax and with qpdf available. The fake binding writes the attachment bytes to a file and makes no network calls.
- Run
TZ=UTC LANG=C node probe.mtsand thenqpdf --check invoice-42.pdf.
Reproduction script: probe.mts fixture to append
import { writeFile } from "node:fs/promises";
const request = new Request("https://example.test/send-invoice", {
method: "POST",
body: JSON.stringify({
customerEmail: "recipient@example.test",
invoiceData: {
number: "42", customerName: "Example Customer", date: 0, dueDate: 0, total: 5,
},
}),
});
const response = await worker.fetch(request, {
DOMAIN: "example.test",
EMAIL: {
async send({ attachments }) {
const attachment = attachments[0];
await writeFile(attachment.filename, Buffer.from(attachment.content));
return { messageId: "fixture" };
},
},
});
console.log(response.status, await response.text());Actual behavior
The local handler returned HTTP 200 with Invoice sent. qpdf exited 3 and reported file is damaged, (offset 400): xref not found, and recovered stream length: 148. The example declares a fixed stream length of 200 and a fixed cross-reference location even though invoice text changes. The check exercised attachment generation and did not send an email.
Evidence
- Expected source: Email attachments tutorial, PDF attachments, which describes generating and sending a PDF invoice.
- Failure source: PDF attachment handler and generator and the qpdf output above.
- Evidence provenance: observed
- Local verification: reproduced
- Reproduction completeness: complete
Restoration check
Run the documented invoice path with the fixture and a second invoice with a longer customer name. The captured file for each invoice opens as a PDF, contains its invoice data, and qpdf --check returns exit 0 without repair warnings.
Triage assessment
- Impact level: P2
- Assessment status: supported
- Impact basis: Copying the worked example produces a damaged invoice attachment and the handler reports success.
- Workaround status: available
- Workaround basis: Use valid PDF bytes from a PDF tool or a separately generated invoice with the same email attachment API.
Activity
[Email Service] Fix PDF attachment, signup recovery, and complaint re…