My company currently uses Merger 3.0.3 and I'm evaluating an upgrade to 7.0. Our software adds data to a series of forms and then appends each as a mergedocument to a main document. Our code looks like:
Document.Append(MergeDocument)
I see that in ver 7 the Append method is only available for a MergeDocument object and if merges a PDFDocument object. So one possible update to the line above is to declare the main document as a MergeDocument and then run:
MainDocument.Append(New PdfDocument(MergeDocument.Draw()))
The other possibility I'm considering is to write a helper function to handle the merge as:
For each Page in MergeDocument
Document.Pages.Add(Page)
Next
Which of these options would be the most efficient? Is there another method I'm not considering?
I've seen other suggestions here to merge all the documents together and then add the data but that is not an option. I'm trying to minimize the need for an extensive rewrite of code.
Thanks for any help you can offer.
Merging multiple mergedocuments
Re: Merging multiple mergedocuments
Support · Dec 18, 2012Hello,
It is faster and efficient to add the data after the documents are merged, since that is not an option for you, the next best thing is to loop through each MergeDocument page collection and add the pages to the main document as per the second option you have suggested. Below is the sample code.
Document final = new Document();
MergeDocument document1 = new MergeDocument("doc1.pdf");
MergeDocument document2 = new MergeDocument("doc2.pdf");
//add new content to the MergeDocument objects.
foreach (Page p in document1.Pages)
{
p.Elements.Add(new Rectangle(100, 100, 200, 300, RgbColor.Black, RgbColor.Aquamarine));
}
foreach (Page p in document2.Pages)
{
p.Elements.Add(new Rectangle(100, 100, 200, 300, RgbColor.Black, RgbColor.Aquamarine));
}
//copy the pages from MergeDocument objects to the final document object.
foreach (Page p in document1.Pages)
{
final.Pages.Add(p);
}
foreach (Page p in document2.Pages)
{
final.Pages.Add(p);
}
final.Draw(“final.pdf”);
Thanks,
ceTe Software Support Team.
Re: Merging multiple mergedocuments
Forum member · Jul 1, 2020Hi ,
i am loading images(bytes) to pdf document right now.
i want to append PDF bytes data to pdf along with image.
ceTe.DynamicPDF.Document document = new ceTe.DynamicPDF.Document();
]
foreach (var file in files)
{
if (file != null && file.ContentLength > 0)
{
BinaryReader b = new BinaryReader(file.InputStream);
byte[] binData = b.ReadBytes(file.ContentLength);
// Create and add a page to the document
Page page = new Page(PageSize.Letter, PageOrientation.Portrait);
document.Pages.Add(page);
if (file.ContentLength > 0 && file.ContentType.Contains("image"))
{
//valid image
// Create an image
// ceTe.DynamicPDF.PageElements.Image image = new ceTe.DynamicPDF.PageElements.Image(@"C:\NYSIF-logo-new.png", 0, 0);
ceTe.DynamicPDF.PageElements.Image image = new ceTe.DynamicPDF.PageElements.Image(ImageData.GetImage(binData), 0, 0);
//ceTe.DynamicPDF.PageElements.Image image = new ceTe.DynamicPDF.PageElements.Image(@"c:\shutterstock_395012530.gif", 0, 0);
image.SetSize(500, 500);
page.Elements.Add(image);
}
else
{
}
}
}
byte[] MergedDocumentData = document.Draw();
System.IO.File.WriteAllBytes(System.IO.Path.Combine(ConfigurationManager.AppSettings["UploadLocationmultiple"].ToString(), "testjpg.pdf"), MergedDocumentData);
Re: Merging multiple mergedocuments
Support · Jul 1, 2020Hello,
You can append a PDF from byte data. You will need to create a MergeDocument object (instead of Document object). Load the PDF byte data using the PdfDocument object and append this to the MergeDocument using the Append method. You can refer to the documentation on merging documents here
.
Thanks,
ceTe Software Support Team
Re: Merging multiple mergedocuments
Forum member · Aug 6, 2024It might be challenging to merge multiple PDF documents, there are multiple ways to merge PDF files, and even online tools are available for this task. But that will be not safe for your crucial data. For merging multiple PDF files without making any mistakes, users can try the Pcinfotools PDF Merge tool, which I found very well for performing the merging process, it can quickly merge multiple PDF files into a single PDF document without skipping any single document. The number of PDF files that can be merged by the tool is limitless. The plus point of this tool is users can merge password-protected PDF files but you'll need to know the password and it never loses the properties of your PDF files. The software works on every Windows version. With this software, users can merge PDF documents while fully protecting their important PDF files.