I am working on an update to our app that merges customer data and a Word document to produce a .pdf file. The update I’m working on nvolves then overlaying another pdf file with our existing pdf file.
The overlay process we have right now is working (except for another issue which I have created another thread for) but no tables exist in the overlayed final pdf file.
The code we did have was code to copy Text and Images to the new document. I found that we need to add a section to copy Tables to the new document (I’m assuming). I started doing that but I am not sure where to go after using the TableAbsorber to Visit() the overlay page. You can see my code below, and my comment “don’t know what to do here” for copying the tables on basePage/Pdf to overlayPage/Pdf.
Any help would be greatly appreciated!
Document basePDFdoc = new Document(basePDF.FullName);
Document overlayPDFdoc = new Document(overlayPDF.FullName);
foreach(OverlayPageMapping mapping in overlayPageMappings)
{
Page basePage = basePDFdoc.Pages[mapping.basePageNumber];
Page overlayPage = overlayPDFdoc.Pages[mapping.overlayPageNumber];
// Copy text to new document
Aspose.Pdf.Text.TextFragmentAbsorber tfAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber();
tfAbsorber.Visit(overlayPage);
foreach (Aspose.Pdf.Text.TextFragment textFragment in tfAbsorber.TextFragments)
{
AsposeAddText(basePage, textFragment);
}
tfAbsorber = null;
// Copy images to new document
ImagePlacementAbsorber imageAbsorber = new ImagePlacementAbsorber();
imageAbsorber.Visit(overlayPage);
foreach (ImagePlacement image in imageAbsorber.ImagePlacements)
{
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms);
basePage.AddImage(ms, image.Rectangle);
}
}
// Copy tables to new document
Aspose.Pdf.Text.TableAbsorber tableAbsorber = new Aspose.Pdf.Text.TableAbsorber();
tableAbsorber.Visit(overlayPage);
foreach (Aspose.Pdf.Text.AbsorbedTable absorbedTable in tableAbsorber.TableList)
{
// don't know what to do here
}
imageAbsorber = null;
}
basePDFdoc.Save(outputFile.FullName);