Posted by a ceTe Software moderator
Hello,
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.