It is not possible to merge existing PDFs together with PDFreactor without generating a PDF from an HTML source document. However, there is a workaround for that. You can convert an empty HTML document to PDF and then merge existing PDFs with it. This can be done using the following code:
Java
PDFreactor pr = new PDFreactor();
Configuration conf = new Configuration();
// An "empty" HTML document
conf.setDocument("<html>");
// Make the document really small so that the PDFs can overlay it
conf.setUserStyleSheets(new Resource().setContent("@page { size: 1in 1in; }"));
conf.setMergeSettings(new MergeSettings()
// Set merge mode to "Overlay" to overlay the "empty" page over the existing PDFs
.setMode(MergeMode.OVERLAY)
// Merge the existing PDFs
.setMergeDocuments(
new Resource().setUri("url/to/documentA.pdf"),
new Resource().setUri("url/to/documentB.pdf"),
new Resource().setUri("url/to/documentC.pdf")
)
);
pr.convertAsBinary(conf);C#
PDFreactor pr = new PDFreactor();
Configuration conf = new Configuration();
// An "empty" HTML document
conf.Document = "<html>";
// Make the document really small so that the PDFs can overlay it
conf.UserStyleSheets = new List<Resource>
{
new Resource { Content = "@page { size: 1in 1in; }" }
};
conf.MergeSettings = new MergeSettings {
// Set merge mode to "Overlay" to overlay the "empty" page over the existing PDFs
Mode = MergeMode.OVERLAY;
// Merge the existing PDFs
MergeDocuments = new List<Resource>
{
new Resource { Uri = "url/to/documentA.pdf" },
new Resource { Uri = "url/to/documentB.pdf" },
new Resource { Uri = "url/to/documentC.pdf" }
}
};
pr.ConvertAsBinary(conf);PHP
$pr = new PDFreactor();
$conf = [];
// An "empty" HTML document
$conf["document"] = "<html>";
// Make the document really small so that the PDFs can overlay it
$conf["userStyleSheets"] = [
[ "content" => "@page { size: 1in 1in; }" ]
];
$conf["mergeSettings"] = [
// Set merge mode to "Overlay" to overlay the "empty" page over the existing PDFs
"mode" => MergeMode::OVERLAY,
// Merge the existing PDFs
"mergeDocuments" => [
[ "uri" => "url/to/documentA.pdf" ],
[ "uri" => "url/to/documentB.pdf" ],
[ "uri" => "url/to/documentC.pdf" ]
]
];
$pr->convertAsBinary($conf);JavaScript/Node.js
pr = new PDFreactor();
conf = {};
// An "empty" HTML document
conf.document = "<html>";
// Make the document really small so that the PDFs can overlay it
conf.userStyleSheets = [
{ content: "@page { size: 1in 1in; }" }
];
conf.mergeSettings = {
// Set merge mode to "Overlay" to overlay the "empty" page over the existing PDFs
mode: PDFreactor.MergeMode.OVERLAY,
// Merge the existing PDFs
mergeDocuments: [
{ uri: "url/to/documentA.pdf" },
{ uri: "url/to/documentB.pdf" },
{ uri: "url/to/documentC.pdf" }
]
};
pr.convertAsBinary(conf);Python
pr = PDFreactor()
conf = {}
# An "empty" HTML document
conf["document"] = "<html>"
# Make the document really small so that the PDFs can overlay it
conf["userStyleSheets"] = [
{ "content": "@page { size: 1in 1in; }" }
]
conf["mergeSettings"] = {
# Set merge mode to "Overlay" to overlay the "empty" page over the existing PDFs
"mode": PDFreactor.MergeMode.OVERLAY,
# Merge the existing PDFs
"mergeDocuments": [
{ "uri": "url/to/documentA.pdf" },
{ "uri": "url/to/documentB.pdf" },
{ "uri": "url/to/documentC.pdf" }
]
}
pr.convertAsBinary(conf)Ruby
pr = PDFreactor.new()
conf = {}
# An "empty" HTML document
conf["document"] = "<html>"
# Make the document really small so that the PDFs can overlay it
conf["userStyleSheets"] = [
{ content: "@page { size: 1in 1in; }" }
]
conf["mergeSettings"] = {
# Set merge mode to "Overlay" to overlay the "empty" page over the existing PDFs
"mode": PDFreactor::MergeMode::OVERLAY,
# Merge the existing PDFs
"mergeDocuments": [
{ uri: "url/to/documentA.pdf" },
{ uri: "url/to/documentB.pdf" },
{ uri: "url/to/documentC.pdf" }
]
}
pr.convertAsBinary(conf)REST
{ "document": "<html>", "userStyleSheets": [{ "content": "@page { size: 1in 1in; }" }], "mergeSettings": { "mode": "OVERLAY", "mergeDocuments": [{ "uri": "url/to/documentA.pdf" }, { "uri": "url/to/documentB.pdf" }, { "uri": "url/to/documentC.pdf" }]} }