Reputation: 90
I tried to overlap a model pdf, to see the differences between that and my new pdf.
here is my code:
PdfReader reader = new PdfReader(WorkDir + "\\model.pdf");
PdfImportedPage page = writer.GetImportedPage(reader, 1);
pdfOut.NewPage();
if (checkBox1.Checked) writer.DirectContent.AddTemplate(page, 0, 0);
I only want to put the page only if I check the checkbox1. But if checkbox1 is not checked, the outout pdf file is very large and the overlapped file is not visible.
I removed the overlap part:
PdfReader reader = new PdfReader(WorkDir + "\\model.pdf");
//PdfImportedPage page = writer.GetImportedPage(reader, 1);
pdfOut.NewPage();
//if (checkBox1.Checked) writer.DirectContent.AddTemplate(page, 0, 0);
and the file size is now ok.
What am I doing wrong? I think that the DirectContent element adds the page, but is not visible. That can explain why the output file is so big( with overlap part file size is 700KB, without only 4KB)
Upvotes: 0
Views: 424
Reputation: 95918
The data of the page are already added to the new document when importing the page
PdfImportedPage page = writer.GetImportedPage(reader, 1);
The later writer.DirectContent.AddTemplate(page, 0, 0);
only makes it visible.
Thus, you might want
PdfReader reader = new PdfReader(WorkDir + "\\model.pdf");
pdfOut.NewPage();
if (checkBox1.Checked)
{
PdfImportedPage page = writer.GetImportedPage(reader, 1);
writer.DirectContent.AddTemplate(page, 0, 0);
}
Upvotes: 1