Convert Excel to PDF
Easily convert Excel documents to PDFs using The DynamicPDF API's pdf endpoint.
Convert Excel documents to PDFs using the pdf
endpoint. Call the pdf
endpoint directly or using one of our client libraries.
Check out Getting Started and Task Roadmap if you are new to The DynamicPDF API.
Calling Endpoint Directly
Convert from a Excel document to a PDF using the excel
element in a JSON instructions document.
The following example illustrates the steps in converting a simple word document to a PDF.
- Create an
instructions.json
document that specifiesexcel
as the input and the word document as theresourceName
.
{
"inputs":[
{
"type":"excel",
"resourceName":"sample-data.xlsx"
}]
}
- Add the authorization key as a header.
- Add the Instructions document as a file and the Excel document as a file.
curl --location 'https://api.dpdf.io/v1.0/pdf'
--header 'Authorization: Bearer --api-key--
--form 'Instructions=@C:/temp/solutions/excel-pdf/instructions.json'
--form 'Resource=@C:/temp/solutions/excel-pdf/sample-data.xlsx'
See the Merge PDFs and Other Resources for more information on how you can merge multiple Word documents and other resources into a combined PDF.
Calling Endpoint Using Client Library
Easily convert Excel to a PDF using the ExcelInput
class or its equivalent using the C#, Java, Node.js, PHP, Go, or Python. More details and examples are provided in the pdf Inputs documentation.
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 Excel document.
Pdf pdf = new Pdf();
pdf.ApiKey = apiKey;
pdf.AddExcel(new ExcelResource(basePath + "/sample-data.xlsx"));
PdfResponse pdfResponse = pdf.Process();
The follow example illustrates creating a PDF document from a Excel document.
static async ExcelExample(basePath) {
var pdf = new Pdf();
var resource = new ExcelResource( basePath + "sample-data.xlsx", "sample-data.xlsx");
var excel =new ExcelInput(resource);
pdf.inputs.push(excel);
await this.ProcessAndSave(pdf, "excel-output.pdf");
}
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();
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();
The following example illustrates creating a PDF from a Excel document.
func main() {
pdfExample := endpoint.NewPdf()
pdfExample.Endpoint.ApiKey = apiKey
excelResource := resource.NewExcelResourceWithResourcePath(basePath+"sample-data.xlsx", "sample-data.xlsx")
pdfInput := input.NewExcelInputWithResource(excelResource)
pdfExample.Inputs = append(pdfExample.Inputs, pdfInput)
resp := pdfExample.Process()
res := <-resp
if res.IsSuccessful() == true {
os.Remove(outputPath)
os.WriteFile(outputPath, res.Content().Bytes(), os.ModeType)
} else {
fmt.Print(res.ErrorJson())
}
}
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()
Refer to our online documentation for more information on the excel
input type.
The pdf
endpoint takes a JSON instructions document that provides instructions for creating, transforming, merging, and formatting inputs into a combined PDF. Refer to documentation on the instructions schema for information on how to use the pdf
endpoint.