Skip to main content

DynamicPDF API Word and Excel Conversion

· 4 min read
James A Brannan
Developer Evangelist

The DynamicPDF API pdf endpoint now supports Word and Excel conversion to PDF.

For example, in the following instructions document, the sample-data.xlsx excel file and the sample-doc.docx word file are both converted to PDFs and then merged to return a combined PDF.

{
"author": "Alex Smith",
"title": "Word and Excel Example",
"inputs": [
{
"type": "excel",
"resourceName": "sample-data.xlsx"
},
{
"type": "word",
"resourceName": "sample-doc.docx"
}
]
}

The following illustrates the processing performed by the instructions document.

The instructions first converts the Excel document to a PDF, it then converts the Word document to a PDF. The two interim PDFs are then merged into a combined PDF. The pdf endpoint then returns the combined PDF as binary.

Running the instructions in Postman results in a combined PDF.

Client API Example Code

Here are examples illustrating both Word conversion to PDF and Excel conversion to PDF.

The following example illustrates creating a PDF from a Word document.

Pdf pdf = new Pdf();
pdf.ApiKey = apiKey;
pdf.AddWord(new WordResource(basePath + "/Doc1.docx"));
PdfResponse pdfResponse = pdf.Process();
Source: WordConversion.cs

The following example illustrates creating a PDF from a Excel document.

Pdf pdf = new Pdf();
pdf.ApiKey = apiKey;
pdf.AddExcel(new ExcelResource(basePath + "/sample-data.xlsx"));
PdfResponse pdfResponse = pdf.Process();
Source: ExcelConversion.cs
tip

You can also add a resource using an input, as this Word example illustrates.

Pdf pdf = new Pdf();
WordResource wordResource = new WordResource(basePath + "Doc1.docx");
WordInput word = new WordInput(wordResource);
pdf.Inputs.Add(word);
return pdf;

Refer to our online documentation for more information on the word and excel input types.