Reputation: 69
I am creating a wide variety of variable data statements(90+) for the same client. We print 10K or so of each statement per business day. Some statements have a particular logo in the upper left of the page, others intentionally omit this. Some statements have an image and/or text near the bottom, others intentionally do not. These, along with many others, are added/omitted per statement.
I am not sure if it is possible, but is it possible to 'layer' PDFs on top of each other? If so, I am thinking I could add 'layers' depending on the need of each statement. Then the resulting 'layered' PDF would become my base document that I could then proceed with adding data to.
Otherwise I am thinking I'd need to create a PDF for each potential scenario.
(BTW, I have tried to conditionally add these items as images directly, but it slows things down quite a bit.)
Edit I have tried to use this code but the final output only shows the last template added.
string[] templates = new string[]{
pdfTemplate
,thingsTemplate
};
using (FileStream filestream = new FileStream(finalTemplate, FileMode.OpenOrCreate, FileAccess.Write))
using (iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER))
using (PdfWriter writer = PdfWriter.GetInstance(document, filestream))
{
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
for (int i = 0; i < templates.Length; i++)
{
page = writer.GetImportedPage(new PdfReader(templates[i]), 1);
cb.AddTemplate(page, 1f, 0, 0, 1, 0, 0);
}
document.Close();
}
Upvotes: 2
Views: 450
Reputation: 77528
Yes, it is possible to layer different PDFs on top of each other.
Take a look at the Layers example. We have a file with 4 pages: layers_orig.pdf, then we add the 4 pages to a single page: layers.pdf.
Well, not exactly the way you would add them, but what you're describing is called superimposing and the Stationery example is more or less doing what you're asking.
We create a PDF, but while creating it, we add some company stationery. This is the stationery: stationery.pdf. This is the final result: text_on_stationery.pdf.
You can add as many stationery templates as you want in the process.
Upvotes: 2