Sorry for posting this to the IText list, but we've tried all other
resources we can find without success.  Any help would be greatly
appreciated!

With iTextSharp, is there a way to scale pages WHILE retaining form
field data and all content?  We've tried two methods, the first of
which allows scaling to occur at the expense of form field data and
some images/annotations.  The second method preserves data and
annotations, but does not subsequently scale (even though we call the
scale and it succeeds).



And code sample that I posted with:


// Problem: Cannot seem to scale pages and preserve form field data or
even, in some cases, the entire content. I have narrowed the problem
//          down to either using the PdfWriter which does allow
scaling at the expense of content and PdfCopy that preserves source
content
//          but won't scale. There are 2 code samples below and the
only difference between them is whether I use the PdfWriter or the
PdfCopy.
//          I did try PdfStamper and it behaves like PdfCopy and won't
allow me to scale the pages but will preserve all content.
                        
                    // Method 1: pdfWriter              
                    // Code below scales pages in the destination
document but loses form field or even all the images resulting
                    // in either the loss of form field data or the
entire page becomes blank

                    iTextSharp.text.Document doc = new
iTextSharp.text.Document(PageSize.LETTER);
                    PdfWriter pdfWriter = PdfWriter.GetInstance(doc,
new FileStream("test.pdf", FileMode.Create));
                    doc.SetPageSize(PageSize.LETTER);
                    doc.Open();
                    PdfContentByte cb = pdfWriter.DirectContent;
                    for (int i = 1; i <= numPages; i++)
                    {
                        doc.SetPageSize(PageSize.LETTER);
                        doc.NewPage();

                        PdfImportedPage page =
pdfWriter.GetImportedPage(pdfReader, i);

                        int rotation = pdfReader.GetPageRotation(i);
                        float origPageWidth = pdfReader.GetCropBox(i).Width;
                        float origPageHeight = pdfReader.GetCropBox(i).Height;
                        float newPageWidth = rect.Width;
                        float newPageHeight = rect.Height;

                        if (rotation == 90 || rotation == 270)
                        {
                            cb.AddTemplate(page, 0, -(newPageWidth /
origPageWidth), (newPageHeight / origPageHeight), 0, 0,
pdfReader.GetPageSizeWithRotation(i).Height);
                        }
                        else if (rotation == 180 || rotation == -180)
                        {
                            cb.AddTemplate(page, -(newPageWidth /
origPageWidth), 0, 0, -(newPageHeight / origPageHeight), 0, 0);
                        }
                        else
                        {
                            cb.AddTemplate(page, newPageWidth /
origPageWidth, 0, 0, newPageHeight / origPageHeight, 0, 0);
                        }
                    }
                    doc.Close();





                    // Method 2: pdfCopy
                    // The code below successfully preserves all form
data but does not scale the pages in the
                    // destination document.

                    iTextSharp.text.Document doc = new
iTextSharp.text.Document(PageSize.LETTER);
                    PdfCopy pdfWriter =  new PdfCopy(doc, new
FileStream("test.pdf", FileMode.Create));
                    doc.SetPageSize(PageSize.LETTER);
                    doc.Open();
                    PdfContentByte cb = pdfWriter.DirectContent;
                    for (int i = 1; i <= numPages; i++)
                    {
                        doc.SetPageSize(PageSize.LETTER);
                        doc.NewPage();

                        PdfImportedPage page =
pdfWriter.GetImportedPage(pdfReader, i);

                        int rotation = pdfReader.GetPageRotation(i);
                        float origPageWidth = pdfReader.GetCropBox(i).Width;
                        float origPageHeight = pdfReader.GetCropBox(i).Height;
                        float newPageWidth = rect.Width;
                        float newPageHeight = rect.Height;

                        if (rotation == 90 || rotation == 270)
                        {
                            cb.AddTemplate(page, 0, -(newPageWidth /
origPageWidth), (newPageHeight / origPageHeight), 0, 0,
pdfReader.GetPageSizeWithRotation(i).Height);
                        }
                        else if (rotation == 180 || rotation == -180)
                        {
                            cb.AddTemplate(page, -(newPageWidth /
origPageWidth), 0, 0, -(newPageHeight / origPageHeight), 0, 0);
                        }
                        else
                        {
                            cb.AddTemplate(page, newPageWidth /
origPageWidth, 0, 0, newPageHeight / origPageHeight, 0, 0);
                        }
                    }
                    doc.Close();

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to