PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

constructing pdf document from a given pdf template problem
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1710
Page 1 of 1

Author:  ozgurbey78 [ Thu Jun 30, 2011 1:23 pm ]
Post subject:  constructing pdf document from a given pdf template problem

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

Author:  Thomas Hoevel [ Thu Jun 30, 2011 2:58 pm ]
Post subject:  Re: constructing pdf document from a given pdf template problem

This is not the iTextSharp forum.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/