hello all
i have been searching for an answer since this morning for this.
all i am trying to do here is opening a pdf file that has 1 page with some nice pictures. this pdf file is supposed to be my template. so i need to be able to open and copy this pdf into the pdf file which is what i am trying to produce however every page of it must be in the form and layout of the only page in my template.
i am able to open my pdf template and stamp it using a stamper class. as below:
Code:
string fileNameExisting = pdfTemplatePath;
string fileNameNew = @reportSetOutputDir + "/" + pdfDocName;
PdfReader pdfReader = null;
using (var existingFileStream = new FileStream(fileNameExisting, FileMode.Open))
{
var newFileStream = new FileStream(fileNameNew, FileMode.Create);
// Open existing PDF
pdfReader = new PdfReader(existingFileStream);
// PdfStamper, which will create
var stamper = new PdfStamper(pdfReader, newFileStream);
var form = stamper.AcroFields;
var fieldKeys = form.Fields.Keys;
foreach (string fieldKey in fieldKeys)
{
form.SetField(fieldKey, "REPLACED!");
}
AcroFields testForm = stamper.AcroFields;
stamper.FormFlattening = true;
stamper.Close();
}
after above code, fileNameNew is created with the 1 page as in the template. but then i open it and try to add pages to it and it loses the template page and starts inserting blank white pages.
as below:
Code:
Document doc = new Document();
PdfWriter.GetInstance(doc, stampedFileStream);
doc.Open();
doc.NewPage();
doc.Add(new iTextSharp.text.Paragraph(scheduleReportSet.Name));
for (int i = 0; i < sourceFileNamesArr.Count; i++)
{
doc.NewPage();
doc.Add(new iTextSharp.text.Paragraph(FetchReportItemName(i)));
iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(sourceFileNamesArr[i]);
gif.Alignment = iTextSharp.text.Image.ALIGN_JUSTIFIED_ALL;
gif.ScaleToFitLineWhenOverflow = true;
gif.ScaleToFit(doc.PageSize.Width - 50, doc.PageSize.Height);
doc.Add(gif);
}
can someone tell me how can i clone the template page which i have in my pdf after stamping operation from my template file?
i am waiting for your responses very urgently.
Thank you
Taylan Ozgur Sevinc