PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Jul 10, 2024 10:23 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
PostPosted: Thu Jun 30, 2011 1:23 pm 
Offline

Joined: Thu Jun 30, 2011 1:10 pm
Posts: 1
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


Top
 Profile  
 
PostPosted: Thu Jun 30, 2011 2:58 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
This is not the iTextSharp forum.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group