The following code causes the resulting pdf to open with the following error. 
If the iteration is reduced by 1 (to 52), no error is generated.

[cid:[email protected]]

public void BasicTest()
{
    byte[] pdf = data.pdf.Resource1.test;

    for (int x = 0; x < 53; x++)
    {
        pdf = AddBlankPage(pdf, new int[] { x + 2 });

        PdfReader reader = new PdfReader(pdf);
        Document document = new Document();

        using (MemoryStream ms = new MemoryStream())
        {
            PdfWriter writer = PdfWriter.GetInstance(document, ms);

            document.Open();
            PdfContentByte cb = writer.DirectContent;

            int pageCount = reader.NumberOfPages;

            for (int i = 0; i < pageCount; i++)
            {
                document.NewPage();
                PdfImportedPage page = writer.GetImportedPage(reader, i + 1);

                cb.AddTemplate(page, 0, 0);

                if (x == i)
                {
                    ColumnText ct = new ColumnText(cb);
                    ct.SetSimpleColumn(36, 580, 100, 40);
                    ct.AddText(new Phrase(string.Format("Line# {0}", x)));
                    ct.Go();
                }

                page.Reset();
            }

            ms.Flush();
            document.Close();
            pdf = ms.ToArray();
        }
    }

    System.IO.File.WriteAllBytes("C:\\Test.pdf", pdf);

}

private byte[] AddBlankPage(byte[] input, int[] pageNumbers)
{
    byte[] pdf = null;

    using (MemoryStream ms = new MemoryStream())
    {
        PdfReader reader = new PdfReader(input);
        iTextSharp.text.Rectangle psize = reader.GetPageSize(1);
        Document document = new iTextSharp.text.Document(psize, 0, 0, 0, 0);
        PdfStamper stamper = new PdfStamper(reader, ms);

       for (int i = 0; i < pageNumbers.Length; i++)
            stamper.InsertPage(pageNumbers[i], new 
iTextSharp.text.Rectangle(psize));

        stamper.Close();
        reader.Close();
        document.Close();
        pdf = ms.ToArray();
    }

    return pdf;
}


Ron Lindsey
Senior Software Engineer
Epiq Systems
Class Action & Claims Solutions
10300 SW Allen Boulevard
Beaverton, OR  97005
Phone:  503.350.5255
Fax: 503.350.5255
www.epiqsystems.com<http://www.epiqsystems.com>

Managed technology for the global legal profession



This communication (including any attachment(s) is intended solely for the 
recipient(s) named above and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication to include any copy that may 
reside in your sent box. Thank you for your cooperation. 

<<inline: image001.png>>

Attachment: test.pdf
Description: Adobe PDF document

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Ciosco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to