Link Search Menu Expand Document

PDF from Email

Explore Samples

Description: Convert email files (MSG or EML) code into PDF. Extracts attachments (if any) from input email and embeds into PDF as pdf attachments.

Status Errors

CodeDescription
200The request has succeeded
400bad input parameters
401unauthorized
403not enough credits
405Timeout error. To process large documents or files please use asynchronous mode ( set async parameter to true) and then check the status using /job/check endpoint. If a file contains many pages then specify a page range using pages parameter. The number of pages of the document can be obtained using the endpoint /pdf/info

Example

Sample Request:

! Don’t forget to set x-api-key url param or http header param (preferred) to API key, get yours here

Available Methods

[POST] /pdf/convert/from/email

Generate PDF from MSG or EML file and creates a PDF file with email and attachments (if any). You can set the following params:

Attributes
url required
URL to the source file. Supports links from Google Drive, Dropbox, and PDF.co built-in files storage. To upload files via API, Check out the Files Upload section.

Note: If you experience intermittent Too Many Requests or Access Denied errors, please try to add cache: to enable built-in URL caching. (e.g cache:https://example.com/file1.pdf)

For data security, you have the option to encrypt output files and decrypt input files. Learn more about user-controlled data encryption.
embedAttachments optional, True by default
Set 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.
convertAttachments optional, true by default
Set 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 by API (DOC, DOCx, HTML, PNG, JPG .etc) into PDF and merges into output final PDF. Non-supported file types are added as PDF attachments (Adobe Reader or another viewer may be required to view PDF attachments).
async optional
Set async to true for long processes to run in the background, API will then return a jobId which you can use with /job/check endpoint to check the status of the process and retrieve the output while you can proceed with other tasks without waiting for this process to finish.
margins optional
set to CSS style margins like 10px, 5mm, 5in for all sides or 5px 5px 5px 5px (the order of margins is top, right, bottom, left).
paperSize optional
Letter is set by default. Can be Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6 or a custom size. Custom size can be set in px (pixels), mm or in (inches) with width and height separated by space like this: 200 300, 200px 300px, 200mm 300mm, 20cm 30cm or 6in 8in.
orientation optional
Set to Portrait or Landscape. Portrait by default.
profiles optional
Use this parameter to set additional configurations for fine-tuning and extra options, The input must be in string format. Explore PDF.co knowledgebase for profile examples.
name optional
File name for the generated output, The input must be in string format.
expiration optional
Set the expiration time for the output link in minutes (default is 60 i.e 60 minutes or 1 hour), 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. Learn more

To store permanent input files (e.g. re-usable images, pdf templates, documents), Consider using PDF.co built-in Files Storage.
  • Method: POST
  • URL: /v1/pdf/convert/from/email

Query parameters

No query parameters accepted.

Body payload

{
    "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 responses

JSON POST /pdf/convert/from/url
{
    "url": "https://pdf-temp-files.s3.amazonaws.com/980bc13f061344809c75e83ce181851c/Contact_us.pdf",
    "pageCount": 3,
    "error": false,
    "status": 200,
    "name": "Contact_us.pdf",
    "remainingCredits": 60637
}

Code Snippet

CURL
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
}'

[POST] /pdf/convert/from/email (with orientation and paper size)

Attributes
url required
URL to the source file. Supports links from Google Drive, Dropbox, and PDF.co built-in files storage. To upload files via API, Check out the Files Upload section.

Note: If you experience intermittent Too Many Requests or Access Denied errors, please try to add cache: to enable built-in URL caching. (e.g cache:https://example.com/file1.pdf)

For data security, you have the option to encrypt output files and decrypt input files. Learn more about user-controlled data encryption.
httpusername optional
HTTP auth user name if required to access source url.
httppassword optional
HTTP auth password if required to access source url.
name optional
File name for the generated output. Must be a string.
expiration optional
Set the expiration time for the output link in minutes (default is 60 i.e 60 minutes or 1 hour), 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. Learn more

To store permanent input files (e.g. re-usable images, pdf templates, documents), Consider using PDF.co built-in Files Storage.
profiles optional
Use this parameter to set additional configurations for fine-tuning and extra options. Explore PDF.co knowledgebase for profile examples. Must be a string. profiles string may contain a JSON string containing options like orientation, paper size, and margins. Example: {'orientation': 'landscape', 'paperSize': 'letter', 'margins': '5mm'}
Available attributes inside profiles parameter
margins optional
set to CSS style margins like 10px, 5mm, 5in for all sides or 5px 5px 5px 5px (the order of margins is top, right, bottom, left).
paperSize optional
Letter is set by default. Can be Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6 or a custom size. Custom size can be set in px (pixels), mm or in (inches) with width and height separated by space like this: 200 300, 200px 300px, 200mm 300mm, 20cm 30cm or 6in 8in.
orientation optional
Set to Portrait or Landscape. Portrait by default.
  • Method: POST
  • URL: /v1/pdf/convert/from/email

Query parameters

No query parameters accepted.

Body payload

{
    "url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/email-to-pdf/sample.eml",
    "embedAttachments": true,
    "name": "email-with-attachments",
    "async": false,
    "profiles": "{\"orientation\": \"landscape\", \"paperSize\": \"letter\" }"
}

Example responses

/pdf/convert/from/email with Orientation and paper Size
{
    "url": "https://pdf-temp-files.s3.amazonaws.com/1baff39add874c509b2c2675ba7734fc/email-with-attachments.pdf",
    "pageCount": 3,
    "error": false,
    "status": 200,
    "name": "email-with-attachments",
    "remainingCredits": 616243,
    "credits": 168
}

Code Snippet

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

Samples