Pdf4me Merge unites two or possibly multiple PDFs by concatenating them. As a result providing a single Pdf file joined in the order the files are provided.
// create merge object
var merge = new Merge()
{
// documents
Documents = new System.Collections.Generic.HashSet()
{
new Document()
{
DocData = File.ReadAllBytes("myFirstPdf.pdf"),
Name = "myFirstPdf.pdf",
},
new Document()
{
DocData = File.ReadAllBytes("mySecondPdf.pdf"),
Name = "mySecondPdf.pdf",
},
},
// action
MergeAction = new MergeAction()
};
// merge
var res = await Pdf4meClient.Pdf4me.Instance.MergeClient.MergeAsync(merge);
// extract the merged PDF and writing it to disk
byte[] mergedPdf = res.Document.DocData;
File.WriteAllBytes("mergedPdf.pdf", mergedPdf);
// setup the mergeClient
MergeClient mergeClient = new MergeClient(pdf4meClient);
// create merge object
Merge merge = new Merge();
// documents
List documents = new ArrayList();
Document doc1 = new Document();
doc1.setDocData(Files.readAllBytes(Paths.get("myFirstPdf.pdf")));
documents.add(doc1);
Document doc2 = new Document();
doc2.setDocData(Files.readAllBytes(Paths.get("mySecondPdf.pdf")));
documents.add(doc2);
merge.setDocuments(documents);
// action
merge.setMergeAction(new MergeAction());
// merge
MergeRes res = mergeClient.merge(merge);
// extracting the generated PDF and writing it to disk
byte[] mergedPdf = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("mergedPdf.pdf"), mergedPdf);
// setup the pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')
// create merge object
const mergeReq = {
// documents
documents: [
{
docData: fs.readFileSync(path.join(__dirname, 'myFirstPdf.pdf')).toString('base64'),
},
{
docData: fs.readFileSync(path.join(__dirname, 'mySecondPdf.pdf')).toString('base64'),
},
],
// action
mergeAction: {},
}
// merge
pdf4meClient.merge(mergeReq)
.then(function(mergeRes) {
// extract the merged PDF and writing it to disk
const pdf = Buffer.from(mergeRes.document.docData, 'base64')
fs.writeFileSync(path.join(__dirname, 'mergedPdf.pdf'), pdf)
})
.catch(err => {
console.log(err)
})
$mergedPdf = $client->pdf4me()->pdfMerge([
"documents" => [
[
'docData' => $client->getFileData('myFirstPdf.pdf')
],
[
'docData' => $client->getFileData('mySecondPdf.pdf')
]
]
]);
// extracting the generated PDF
$mergedPdf = base64_decode($createMerge->document->docData);
// and writing it to file
file_put_contents('mergedPdf.pdf', $mergedPdf);
# setup the merge_client
merge_client = MergeClient(pdf4me_client)
# create the merge object
merge = Merge(
documents=[
Document(
doc_data=FileReader().get_file_data('myFirstPdf.pdf')
),
Document(
doc_data=FileReader().get_file_data('mySecondPdf.pdf')
)
],
merge_action=MergeAction()
)
# merge
res = merge_client.merge(merge=merge)
# extracting the generated PDF
merged_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('mergedPdf.pdf', 'wb') as f:
f.write(merged_pdf)
// merge
byte[] mergedPdf = await Pdf4meClient.Pdf4me.Instance.MergeClient.Merge2PdfsAsync(
File.ReadAllBytes("myFirstPdf.pdf"),
File.ReadAllBytes("mySecondPdf.pdf")
);
// and writing the generated PDF to disk
File.WriteAllBytes("mergedPdf.pdf", mergedPdf);
// setup the mergeClient
MergeClient mergeClient = new MergeClient(pdf4meClient);
// merge and writing the generated PDF to disk
byte[] mergedPdf = mergeClient.merge2Pdfs(new File("myFirstPdf.pdf"), new File("mySecondPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("mergedPdf.pdf"), mergedPdf);
// setup the pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')
// merge
pdf4meClient.merge2pdfs(
fs.createReadStream(path.join(__dirname, 'myFirstPdf.pdf')),
fs.createReadStream(path.join(__dirname, 'mySecondPdf.pdf'))
)
.then(pdf => {
// and writing the generated PDF to disk
fs.writeFileSync(path.join(__dirname, 'mergedPdf.pdf'), pdf)
})
.catch(err => {
console.log(err)
})
$mergedPdf = $client->pdf4me()->merge2Pdfs(
[
"file1" => __DIR__.'/myFirstPdf.pdf'
"file2" => __DIR__.'/mySecondPdf.pdf'
]
);
//writing it to file
file_put_contents('mergedPdf.pdf, $mergedPdf);
# setup the merge_client
merge_client = MergeClient(pdf4me_client)
# merge
merged_pdf = merge_client.merge_2_pdfs(
file1=FileReader().get_file_handler(path='myFirstPdf.pdf'),
file2=FileReader().get_file_handler(path='mySecondPdf.pdf')
)
# writing the generated PDF to disk
with open('mergedPdf.pdf', 'wb') as f:
f.write(merged_pdf)
Logging information about the request, e.g. timestamp.
Page
Name
Type
Description
Notes
documentId
String
Globally unique Id.
pageId
String
Globally unique Id.
pageNumber
Integer
PageNumber, starting with 1.
rotate
double
By how much the page was rotated from its original orientation.
thumbnail
byte
Thumbnail representing this particular page.
sourceDocumentId
String
Id of the document it was created from, e.g. in case of an extraction, the result's sourceDocumentId is the Id of the PDF the pages have been extracted from.
sourcePageNumber
Integer
Page number of the original page in the original document, e.g. let's assume document B consists of page number 4 of document A (extraction). Thus, document B's only page's sourcePageNumber is number 4.