Convert Word to PDF
Easily convert Word documents to PDFs using The DynamicPDF API's pdf endpoint.
Convert Word 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 Word document to a PDF using the word
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 specifiesword
as the input and the word document as theresourceName
.
{
"inputs":[
{
"type":"word",
"resourceName":"Doc1.docx"
}]
}
- Add the authorization key as a header.
- Add the Instructions document as a file and the Word document as a file.
curl --location 'https://api.dpdf.io/v1.0/pdf'
--header 'Authorization: Bearer --api-key--
--form 'Instructions=@C:/temp/solutions/word-pdf/instructions.json'
--form 'Resource=@C:/temp/solutions/word-pdf/Doc1.docx'
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 a Word to a PDF using the WordInput
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.
- 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();
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 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();
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();
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.
func main() {
pdfExample := endpoint.NewPdf()
pdfExample.Endpoint.ApiKey = apiKey
wordResource := resource.NewWordResourceWithResourcePath(basePath+"Doc1.docx", "Doc1.docx")
pdfInput := input.NewWordInputWithResource(wordResource)
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 word
input type.
pdf=Pdf()
pdf.api_key=apikey
pdf.add_word(WordResource(documentPath + "Doc1.docx"))
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
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.