Add Attachment to PDF
Edit → Add Attachment to PDF
The Add Attachment to PDF API embeds one or more files into a PDF. You send the PDF as Base64 (docContent), docName, an attachment object or array (each with docName and docContent in Base64), and optionally async. The API returns the PDF with attachments embedded; viewers can open them from the attachment panel. Use the tester below to try it; more details are in the sections that follow.
Try the Add Attachment to PDF API
:::note Quick reference
Endpoint: POST /api/v2/AddAttachmentToPdf · Required: api-key, docContent, docName, attachment
:::
:::info Try it live Use the form below to upload one or more files (or paste a JSON object/array). The API embeds them into your PDF. No code required—fill the fields and click Send request. :::
Overview, parameters, and use cases
- Overview
- Parameters
- Use cases
What is Add Attachment to PDF?
This endpoint embeds one or more files into a PDF so they appear in the document’s attachment panel. You provide the PDF (Base64), output name, and an attachment object or array—each with docName and docContent (Base64). In the tester you can upload file(s) (they’re converted automatically) or paste JSON. Any file type can be attached: text, images, documents, archives.
Key features
- Single or multiple files – One object
{"docName": "file.txt", "docContent": "base64..."}or an array of such objects. - Upload in tester – Use “Upload Attachment(s)”; hold Ctrl/Cmd to select multiple files. docName and docContent are set automatically.
- Manual JSON – Paste a single object or array; it’s converted to the
attachmentsformat the API expects. - Wide format support – Text (.txt, .csv, .log), documents (.pdf, .doc, .docx, .xls, .xlsx), images (.jpg, .png, .gif), archives (.zip, .rar), and others.
:::tip Best for Use when you need to ship a PDF with supporting files (source data, images, spreadsheets) in one package. Combine with Extract Attachment from PDF to retrieve embedded files. :::
API parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| api-key | string | Yes | Your PDF4me API key, Base64 encoded. Get it from the dashboard. |
| docContent | base64 | Yes | PDF file content (Base64). |
| docName | string | Yes | Output PDF file name (e.g. output.pdf). |
| attachment | object/array | Yes | Single object or array of {docName, docContent}; docContent is Base64. Upload via tester or paste JSON. |
| async | boolean | No | Enable asynchronous processing. |
When to use Add Attachment to PDF
- Document packages – Attach source files, spreadsheets, or images to a report or proposal PDF.
- Invoices and contracts – Embed supporting documents (terms, specs) with the main PDF.
- Archiving – Keep related files in one PDF for distribution or compliance.
- Workflows – Attach generated files (e.g. CSV, images) to a PDF before sending.
:::info Need the full API? For request/response schemas and code samples, see Add Attachment to PDF in the PDF4me API docs. :::
Prerequisites
Before using this endpoint, make sure you have:
- A valid PDF4me API key (Get your API Key)
- A PDF document in Base64 format or a public URL to a PDF file
- Attachment files to embed in the PDF
Response Format
The API returns a PDF document with embedded attachments. The attachments can be accessed through the PDF viewer's attachment panel.