Sample PDF with File Attachments Inside
A PDF can carry other files inside it — a feature most people discover only when an invoice arrives with its machine-readable XML tucked into the PDF. This sample embeds two attachments: embedded-data.csv (a tiny three-row table) and readme-attachment.txt (one paragraph of plain text), both registered properly in the document's EmbeddedFiles name tree.
What's embedded, exactly
embedded-data.csv—text/csv, 3 data rows (id,name,amount), description string set. Known content, so an extraction test can assert on the bytes.readme-attachment.txt—text/plain, one sentence explaining what it is. Useful for checking that MIME types and descriptions survive a round trip.
What to test with it
- Attachment discovery — your library should report exactly two embedded files, with names, MIME types and descriptions intact. (pdf.js note:
getAttachments()returns aMapin recent versions — code written for the old plain-object return sees zero attachments. We hit this bug ourselves while validating this very file.) - Extraction round-trip — pull
embedded-data.csvout and diff it against the three known rows; encoding bugs show up instantly in theamountcolumn's decimal points. - Attachment UI — many viewers hide attachments behind a paperclip icon nobody notices; check that yours surfaces them at all. The inspector lists them under embedded files.
- Adding more — drop the file into attach files, add a third attachment, and confirm the original two survive the write.
- Tools that should ignore attachments — text extraction should return only the page text, never the attachment contents; splitting is allowed to drop document-level attachments, but should do so consciously, not corrupt them.
Where attached files show up in the real world
Electronic invoicing is the big one: standards like ZUGFeRD and Factur-X are exactly this — a human-readable PDF with the machine-readable XML invoice embedded inside it. Court filings, lab reports with raw data, and email-to-PDF archivers use the same mechanism. If your pipeline touches invoices from EU suppliers, this file is a miniature of what will arrive.
FAQ
Is this the same as a "PDF portfolio"?
Close but no. A portfolio (PDF package) is a container whose main content is the collection of files, with a special navigation UI. This sample is a normal document that happens to carry attachments — the far more common case, and the one libraries support consistently.
Do attachments survive merge / split / compress?
Document-level attachments are the most commonly dropped data in PDF processing — many tools rebuild the document and never copy the EmbeddedFiles tree. That's precisely what this file lets you find out about your toolchain before production does.
Can attachments be malicious?
An attachment is just stored bytes — it can be anything, which is why mail gateways often strip or flag PDFs with embedded executables. These two are inert text files with fully documented contents.
How do I add attachments to my own PDF?
Use the attach files tool — runs entirely in your browser. Programmatically, it's doc.attach() in pdf-lib (remember to await it — it's async, and yes, that's a lesson from this file's own build script).