Skip to main content

POST /v1/pdf/convert/from/email

Images and attachments within .eml and .msg files must be publicly accessible. Resources stored on local file systems or gated behind authentication are not supported for processing.

Attributes

Attributes are case-sensitive and should be inside JSON for POST request. for example: { "url": "https://example.com/file1.pdf" }
AttributeTypeRequiredDefaultDescription
urlstringYes-URL to the source file url attribute
callbackstringNo-The callback URL (or Webhook) used to receive the POST data. see Webhooks & Callbacks. This is only applicable when async is set to true.
marginsstringNo-Set custom margins, overriding CSS default margins. Specify the margins in the format {top} {right} {bottom} {left}. You can usepx,mm,cmorinunits. Also, you can set margins for all sides at once using a single value.
paperSizestringNoA4Specifies the paper size. Accepts standard sizes like ‘Letter’, ‘Legal’, ‘Tabloid’, ‘Ledger’, ‘A0’–‘A6’. You can also set a custom size by providing width and height separated by a space, with optional units: px (pixels), mm (millimeters), cm (centimeters), or in (inches). Examples: ‘200 300’, ‘200px 300px’, ‘200mm 300mm’, ‘20cm 30cm’, ‘6in 8in’.
orientationstringNoPortraitSets the document orientation. Options: Portrait for vertical layout, and Landscape for horizontal layout.
asyncbooleanNofalseSet async to true for long processes to run in the background, API will then return a jobId which you can use with the Background Job Check endpoint. Also see Webhooks & Callbacks
namestringNo-File name for the generated output, the input must be in string format.
expirationintegerNo60Set the expiration time for the output link in minutes. After this specified duration, any generated output file(s) will be automatically deleted from PDF.co Temporary Files Storage. The maximum duration for link expiration varies based on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf templates, documents) consider using PDF.co Built-In Files Storage.
embedAttachmentsbooleanNotrueSet to true to automatically embeds all attachments from original input email MSG or EML files into the final output PDF. Set it to false if you don’t want to embed attachments so it will convert only the body of the input email. True by default.
convertAttachmentsbooleanNotrueSet to false if you don’t want to convert attachments from the original email and want to embed them as original files (as embedded PDF attachments). Converts attachments that are supported into PDF format and then merges into output final PDF. The supported attachment types for conversion are: .eml, .html/.htm, .pdf, .doc, .docx, and .rtf. Non-supported file types are added as PDF attachments (Adobe Reader or another viewer may be required to view PDF attachments).
profilesobjectNo-See Profiles for more information.
    removeHTMLHeadStyleTagsstringNofalseRemoves default styles from the <head> section of Outlook emails to ensure accurate PDF rendering. Set to 'true' to enable.
    removeHTMLBodyStyleTagsstringNofalseRemoves inline and default styles from the <body> section of Outlook emails to ensure accurate PDF rendering. Set to 'true' to enable.
    CustomScriptstringNo-Custom JavaScript code executed on the email content before PDF conversion. Use to modify HTML elements, disable links, or apply custom transformations.
    outputDataFormatstringNo-If you require your output as base64 format, set this to base64
    DataEncryptionAlgorithmstringNo-Controls the encryption algorithm used for data encryption. See User-Controlled Encryption for more information. The available algorithms are: AES128, AES192, AES256.
    DataEncryptionKeystringNo-Controls the encryption key used for data encryption. See User-Controlled Encryption for more information.
    DataEncryptionIVstringNo-Controls the encryption IV used for data encryption. See User-Controlled Encryption for more information.
    DataDecryptionAlgorithmstringNo-Controls the decryption algorithm used for data decryption. See User-Controlled Encryption for more information. The available algorithms are: AES128, AES192, AES256.
    DataDecryptionKeystringNo-Controls the decryption key used for data decryption. See User-Controlled Encryption for more information.
    DataDecryptionIVstringNo-Controls the decryption IV used for data decryption. See User-Controlled Encryption for more information.

Profiles examples

removeHTMLHeadStyleTags

  • Remove default Outlook styles for accurate PDF conversion
{
  "profiles": {
    "removeHTMLHeadStyleTags": "true",
  }
}

removeHTMLBodyStyleTags

  • Remove inline and default styles for accurate PDF conversion
{
  "profiles": {
    "removeHTMLBodyStyleTags": "true"
  }
}
This example removes all inline and default styles from the <body> section of Outlook emails to ensure accurate PDF rendering.

CustomScript

{
  "profiles": {
    "CustomScript": "document.querySelectorAll('a').forEach(a => { a.href = '#' });"
  }
}
This example disables all active links while keeping the link text visible.

Query parameters

No query parameters accepted.

Responses

ParameterTypeDescription
urlstringDirect URL to the final PDF file stored in S3.
outputLinkValidTillstringTimestamp indicating when the output link will expire
pageCountintegerNumber of pages in the PDF document.
errorbooleanIndicates whether an error occurred (false means success)
statusstringStatus code of the request (200, 404, 500, etc.). For more information, see Response Codes.
namestringName of the output file
creditsintegerNumber of credits consumed by the request
remainingCreditsintegerNumber of credits remaining in the account
durationintegerTime taken for the operation in milliseconds

Example Payload

To see the request size limits, please refer to the Request Size Limits.
{
  "url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/email-to-pdf/sample.eml",
  "embedAttachments": true,
  "convertAttachments": true,
  "paperSize": "Letter",
  "name": "email-with-attachments",
  "async": false
}

Example Response

To see the main response codes, please refer to the Response Codes page.
{
  "url": "https://pdf-temp-files.s3.amazonaws.com/980bc13f061344809c75e83ce181851c/Contact_us.pdf",
  "pageCount": 3,
  "error": false,
  "status": 200,
  "name": "Contact_us.pdf",
  "remainingCredits": 60637
}
Inconsistent URL Encoding in cURL Output: When using cURL to make API requests, the output JSON may show URL characters encoded as Unicode escape sequences. For example, the ampersand character (&) may appear as \u0026 in the cURL output. This is normal JSON encoding behavior and does not affect the validity of the URL. The URL will function correctly when used, as JSON parsers automatically decode these escape sequences. If you’re parsing the response programmatically, your JSON parser will handle this conversion automatically.

Code Samples

curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/from/email' \
--header 'x-api-key: *******************' \
--header 'Content-Type: application/json' \
--data-raw '{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/email-to-pdf/sample.eml",
"embedAttachments": true,
"convertAttachments": true,
"paperSize": "Letter",
"name": "email-with-attachments",
"async": false
}'