Set a Custom Filename for Generated Documents
Last updated March 23, 2026
By default, PDFMonkey names generated files using an internal identifier. You can override this by passing a _filename key in the document’s metadata – this works for both PDFs and images.
Setting the filename via the API
Include the _filename key inside the meta object when you create or update a document:
curl https://api.pdfmonkey.io/api/v1/documents \
-X POST \
-H 'Authorization: Bearer YOUR_SECRET_KEY' \
-H 'Content-Type: application/json' \
-d '{
"document": {
"document_template_id": "YOUR_TEMPLATE_ID",
"status": "pending",
"payload": { "name": "Jane Doe" },
"meta": {
"_filename": "invoice-2050-03.pdf"
}
}
}'
The meta field accepts a JSON object. You can include other metadata keys alongside _filename – see API Documents reference for full details.
Setting the filename from the Dashboard
- Open a document in the Document Editor.
- Switch to the Meta data tab.
- Enter the
_filenamekey and your desired name:
{
"_filename": "invoice-2050-03.pdf"
}
- Click Save, then Generate.
For a full walkthrough, see Generate Documents from the Dashboard.
File extension handling
PDFMonkey manages the file extension automatically based on the output format (PDF, PNG, WebP, or JPG):
- If you include the matching extension (e.g.
invoice.pdffor a PDF template), PDFMonkey strips it and re-appends it to keep the filename clean. - If you omit the extension, PDFMonkey appends the correct one for you.
- If you include a mismatched extension (e.g.
.pngon a PDF document), it is treated as part of the name and the correct extension is still appended.
Filename sanitization
PDFMonkey sanitizes the _filename value to ensure it is safe for all file systems:
| Rule | Example |
|---|---|
| Accented characters are transliterated to ASCII | cafe-resume becomes cafe-resume |
| Characters other than letters, digits, dashes, underscores, and spaces are replaced with a dash | report@2050/03 becomes report-2050-03 |
| Consecutive dashes are collapsed | report---final becomes report-final |
| Leading and trailing dashes are removed | -my-file- becomes my-file |
| Whitespace is trimmed from both ends | " invoice " becomes "invoice" |
For example, an input of "Facture n 2050/03" for a PDF template produces the filename Facture n-2050-03.pdf.
Works with images too
The _filename key works the same way for image output formats. The extension is adjusted to match the image type (.webp, .png, or .jpg):
{
"meta": {
"_filename": "social-card-march",
"_type": "png"
}
}
This produces a file named social-card-march.png.
Frequently asked questions
What happens if I don’t set a custom filename?
PDFMonkey uses an internal default name. If you need predictable filenames for archival or downstream systems, always set _filename.
Can I use dynamic data in the filename?
Not directly inside the _filename value. However, in most integration platforms (Zapier, Make, n8n) you can use dynamic fields or expressions to build the filename string before passing it to PDFMonkey.
Is there a maximum filename length?
There is no explicit limit enforced by PDFMonkey, but keep filenames reasonable (under 200 characters) to avoid issues with file systems and browsers.
Related pages
- API Documents reference – full parameter documentation for
metaand other fields - Generate PDFs with the API – end-to-end generation workflow
- Generate Documents from the Dashboard – using the Meta data tab
- Output Formats – image generation and meta keys like
_type - Download URL – how to retrieve the generated file
Frequently asked questions
- How do I set a custom filename for a PDFMonkey document?
- Pass a "_filename" key in the document's meta field. Via the API, include it in the meta object when creating or updating a document: "meta": { "_filename": "invoice-2050.pdf" }. In the Dashboard, enter it in the Meta data tab of the Document Editor.
- Does PDFMonkey add the file extension automatically?
- Yes. If you include the correct extension (.pdf, .png, .webp, .jpg), PDFMonkey strips it and re-adds it to keep the filename clean. If you omit the extension, PDFMonkey appends it automatically based on the output format.
- What characters are allowed in the custom filename?
- PDFMonkey sanitizes the filename: accented characters are transliterated to ASCII, any character that is not a letter, digit, dash, underscore, or space is replaced with a dash, and consecutive or leading/trailing dashes are removed.