PDFCrowd Blog
Product updates, tips & tricks

Attach Files to Your PDFs

Sometimes a PDF needs to travel with other files - the XML behind an invoice, the spreadsheet behind a report, the original source document. PDFCrowd now lets you embed those files right inside the PDF you generate, so everything stays together as one file.

Pass the path of an existing local file and call addAttachment() once for each attachment:

client.addAttachment('invoice-data.xml')
client.addAttachment('terms.pdf')
client.convertUrlToFile('https://example.com/invoice', 'invoice.pdf')

That's it — the files are embedded and travel with the document.

Embed invoice XML in PDF/A-3

A common use is carrying machine-readable data alongside a human-readable document — for example, an XML version of an invoice attached to the PDF, so downstream systems can process it automatically. PDF/A-3 can contain arbitrary file types, making it a suitable container for a PDF and its XML data:

client.setConformance('PDF/A-3b')       # PDF/A-3 allows embedded files
client.addAttachment('invoice-data.xml')
client.convertUrlToFile('https://example.com/invoice', 'invoice.pdf')

Embedding XML in PDF/A-3 is only one part of an e-invoice standard. Check the required XML profile, metadata, attachment relationship, and validation rules for the format and recipient you need to support.

See Create PDF/A and Tagged PDFs for more on conformance levels.

Good to know

  • Multiple files — call addAttachment as many times as you need.
  • Any file type — XML, spreadsheets, images, other PDFs.
  • Works with encryption — regular PDFs can contain attachments and be password-protected. PDF/A documents cannot be encrypted.
  • Not just HTML to PDF — also available in the PDF to PDF and Image to PDF APIs.

In WordPress

In the Save as PDF plugin, open Expert Settings → PDF Format and use the new Attachments option in the Save as PDF plugin — no code required.

Common PDF attachment use cases

  • Reports and audits — attach the source spreadsheet or CSV so recipients can inspect the data behind a generated report.
  • Document delivery packs — keep terms, contracts, technical drawings, or datasheets with the main PDF instead of distributing a separate archive.
  • Source and rendered versions — embed the original document next to its rendered PDF so both remain together throughout a workflow.

Available now in PDFCrowd API client 6.7.0 (converter 24.04) and the Save as PDF WordPress plugin 4.6.0.