Skip to main content

Add Attachment to PDF

EditAdd 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. :::

Loading API Tester...

Overview, parameters, and 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 attachments format 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. :::

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.

Get Help