DynamicPDF API Word and Excel Conversion
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.
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
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();
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();
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;
The follow example illustrates creating a PDF document from a Word document.
var pdf = new Pdf();
var resource = new WordResource( basePath + "Doc1.docx", "Doc1.docx");
var word =new WordInput(resource);
pdf.inputs.push(word);
The follow example illustrates creating a PDF document from a Excel document.
TBD
The following example illustrates creating a PDF from a Word document.
Pdf pdf = new Pdf();
pdf.setApiKey(apiKey);
WordResource wordResource = new WordResource(basePath + "Doc1.docx");
pdf.addWord(wordResource, PageSize.LETTER, PageOrientation.PORTRAIT, (float)1.0);
PdfResponse pdfResponse = pdf.process();
The following example illustrates creating a PDF from a Excel document.
Pdf pdf = new Pdf();
pdf.setApiKey(apiKey);
ExcelResource excelResource = new ExcelResource(basePath + "sample-data.xlsx");
pdf.addExcel(excelResource, PageSize.LETTER, PageOrientation.PORTRAIT, (float)1.0);
PdfResponse pdfResponse = pdf.process();
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.getInputs().add(word);
return pdf;
The following example illustrates creating a PDF from a Word document.
$pdf = new Pdf();
$pdf->ApiKey =$apikey;
$pdf->AddWord(new WordResource($path . "Doc1.docx"));
$pdfResponse = $pdf->Process();
The following example illustrates creating a PDF from a Excel document.
$pdf = new Pdf();
$pdf->ApiKey =$apikey;
$pdf->AddExcel(new ExcelResource($path . "sample-data.xlsx"));
$pdfResponse = $pdf->Process();
You can also add a resource using an input, as this Word example illustrates.
$pdf = new Pdf();
$pdf->ApiKey =$apikey;
$wordResource = new WordResource($path . "Doc1.docx");
$wordInput = new WordInput($wordResource);
array_push($pdf->Inputs, $wordInput);
$pdfResponse = $pdf->Process();
The following example illustrates creating a PDF from a Word document.
pdfExample := endpoint.NewPdf()
pdfExample.Endpoint.BaseUrl = "https://api.dpdf.io/"
pdfExample.Endpoint.ApiKey = "DP--api-key--"
wordResource := resource.NewWordResourceWithResourcePath("./resources/word-pdf/Doc1.docx", "Doc1.docx")
pdfInput := input.NewWordInputWithResource(wordResource)
pdfExample.Inputs = append(pdfExample.Inputs, pdfInput)
resp := pdfExample.Process()
The following example illustrates creating a PDF from a Excel document.
TBD
The follow example illustrates using the word
input type.
pdf=Pdf()
pdf.api_key=apikey
pdf.add_word(WordResource(documentPath + "Doc1.docx"))
response = pdf.process()
The follow example illustrates using the excel
input type.
pdf=Pdf()
pdf.api_key=apikey
pdf.add_excel(ExcelResource(documentPath + "sample-data.xlsx"))
response = pdf.process()
You can also add a resource using an input, as this Word example illustrates.
pdf=Pdf()
wordResource = WordResource(documentPath + "Doc1.docx")
word = WordInput(wordResource)
pdf.inputs.append(word)
return pdf
Refer to our online documentation for more information on the word and excel input types.