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 from built-in PDF.co files storage.

For uploading files via API please check Files Upload section.

If you are randomly getting a Too Many Requests or Access Denied error for your input URL, Please try to add cache: to enable built-in URL caching.

You can also encrypt data for output files and decrypt data input files with user-controlled data encryption to learn more.
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
Runs processing asynchronously and returns JobId that you may use with /job/check to check the state of the processing (possible states: working, failed, aborted and success). Must be one of: true, or false.
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
Output link expiration in minutes. The default is 60 (i.e. 60 minutes or 1 hour). After this delay generated output file(s) (if any) will be auto-removed from PDF.co temporary files storage.
Max allowed expiration period depends on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf, documents), please use PDF.co built-in Files Storage instead.
  • 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 from built-in PDF.co files storage.

For uploading files via API please check Files Upload section.

If you are randomly getting a Too Many Requests or Access Denied error for your input URL, Please try to add cache: to enable built-in URL caching.

You can also encrypt data for output files and decrypt data input files with user-controlled data encryption to learn more.
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
Output link expiration in minutes. The default is 60 (i.e. 60 minutes or 1 hour). After this delay generated output file(s) (if any) will be auto-removed from PDF.co temporary files storage.
Max allowed expiration period depends on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf, documents), please use PDF.co built-in Files Storage instead.
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