Skip to main content

Merge PDFs and Other Resources


Merge multiple PDF documents into one combined document.

The DynamicPDF API easily merges multiple PDFs into a combined PDF. You can also merge Word, HTML, and images into a combined PDF.

tip

Check out Getting Started and Task Roadmap if you are new to The DynamicPDF API.

info

Refer to the other solutions on how to convert HTML, images, and Word documents to PDFs. Each type is an input, and multiple inputs are combined together, in the order they occur in the inputs array to form the combined PDF.

Calling Endpoint Directly

The following JSON instructions document illustrates combining two PDF documents, a Word document, an image, an HTML document, and a DLEX report into a combined PDF.

  1. Create an instructions JSON document and add an inputs array.
  2. Add the inputs to the array in the order in which they are to be merged.
{
"inputs": [
{
"type": "pdf",
"resourceName": "DocumentA.pdf"
},
{
"type": "pdf",
"resourceName": "DocumentB.pdf"
},
{
"type": "word",
"resourceName": "Doc1.docx"
},
{
"type": "image",
"scaleX": 0.5,
"scaleY": 0.5,
"resourceName": "testimage.tif"
},
{
"type": "dlex",
"layoutDataResourceName": "creating-pdf-dlex-layout.json",
"resourceName": "samples/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.dlex"
},
{
"type": "html",
"resourceName": "products.html"
}
]
}

Run In Postman

curl -X POST https://api.dpdf.io/v1.0/pdf 
--header "Authorization: Bearer DP--api-key--"
--form "Instructions=@C:/temp/solution/instructions.json"
--form "Resource=@C:/temp/solution/DocumentA.pdf"
--form "Resource=@C:/temp/solution/DocumentB.pdf"
--form "Resource=@C:/temp/solution/testimage.tif"
--form "Resource=@C:/temp/solution/products.html"
--form "Resource=@C:/temp/solution/creating-pdf-dlex-layout.json"
--form "Resource=@C:/temp/solution/Doc1.docx"
--output output.pdf

Calling Endpoint Using Client Library

The following examples illustrate converting two PDFs, a Word document, an image, a DLEX report, and an HTML document into a combined PDF using the six different client libraries.

public static void Run(string apiKey, string basePath, string outputPath)
{
Pdf pdf = new Pdf();
pdf.ApiKey = apiKey;

var inputA = pdf.AddPdf(new PdfResource(basePath + "/merge-pdfs-pdf-endpoint/DocumentA.pdf"));

pdf.AddPdf(new PdfResource(basePath + "/merge-pdfs-pdf-endpoint/DocumentB.pdf"));
pdf.AddWord(new WordResource(basePath + "/users-guide/Doc1.docx"));
ImageInput input = pdf.AddImage(new ImageResource(basePath + "/image-conversion/testimage.tif"));
input.ScaleX = (float)0.5;
input.ScaleY = (float)0.5;

LayoutDataResource layoutData = new LayoutDataResource(basePath + "/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.json");
pdf.AddDlex("samples/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.dlex", layoutData);

HtmlResource resource = new HtmlResource(System.IO.File.ReadAllText(basePath + "/users-guide/products.html"));
pdf.AddHtml(resource);

PdfResponse pdfResponse = pdf.Process();

if (pdfResponse.IsSuccessful)
{
File.WriteAllBytes(outputPath + "/merge-pdfs-solution-output-csharp.pdf", pdfResponse.Content);
}
else
{
Console.WriteLine(pdfResponse.ErrorJson);
}
}
Source: MergeSolution.cs
info

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.

   Follow us on social media for latest news!