i have a webapp that teachers use to fill out forms for special education.

i just started using iTextSharp (latest v.) to take a data entry PDF and
it's data via FDF, and render it into a completely new PDF containing just
the original PDFs image.  i do this to ensure i get the smallest file size
possible when printing.

i have an intermittent error that appears when the new printed PDF is served
up to the browser.  i get:
"There was an error processing a page. Could not find XObject named '%s'." 
this ultimately locks up my browser.

strangely enough, all signs point to this being a usage/load issue as it
only happens to the PDFs that alot of users are interfacing with
simultaneously.

i'm not sure if its my code (see below) or the forms themselves (see
attached).  i find it interesting that i can not produce the error late at
night when the server usage is down.  also on a separate test server, using
the same code, same PDFs, and zero usage everything works great!

i appreciate any advice/insight anyone can provide.

Jason

Code:

    Private Sub OutputForm()
        Dim iTextReader As PdfReader
        Dim iTextStamper As PdfStamper
        Dim iTextWriter As PdfWriter
        Dim iTextDoc As Document
        Dim iTextImage As Image
        Dim iTextPage As PdfImportedPage
        Dim iTextFDF As FdfReader
        Dim memStm As New MemoryStream
        Dim iPage As Integer
        Dim sValue As String
        Dim htFields As New Hashtable
        Dim enField As IDictionaryEnumerator

        Try
            Dim sPDF As String = "C:\Form1.pdf"

            'Read PDF & FDF into memory
            iTextReader = New PdfReader(sPDF)
            iTextFDF = New FdfReader(sPDF.Replace(".pdf", ".fdf"))
            iTextStamper = New PdfStamper(iTextReader, memStm)
            iTextReader.Close()

            'Field Code
            htFields = iTextFDF.Fields
            enField = htFields.GetEnumerator
            While enField.MoveNext
                sValue = iTextFDF.GetFieldValue(enField.Key.ToString)
                If sValue.Length > 0 Then
                    iTextStamper.AcroFields.SetField(enField.Key.ToString,
sValue)
                End If
            End While
            iTextStamper.FormFlattening = True
            iTextStamper.Close()

            'Create/Open Writer
http://old.nabble.com/file/p26344825/Form1.pdf Form1.pdf 
http://old.nabble.com/file/p26344825/Form1.fdf Form1.fdf 
            iTextReader = New PdfReader(memStm.ToArray)
            iTextDoc = New Document(IIf(iTextReader.GetPageSize(1).Height <
iTextReader.GetPageSize(1).Width,  iTextReader.GetPageSize(1).Rotate,
iTextReader.GetPageSize(1)), 0, 0, 0, 0)
            iTextWriter = PdfWriter.GetInstance(iTextDoc, New
FileStream("c:\Output.pdf", FileMode.Create))
            iTextWriter.SetFullCompression()
            iTextDoc.Open()

            'Copy each page from Reader to Writer as image
            For iPage = 1 To iTextReader.NumberOfPages
                iTextPage = iTextWriter.GetImportedPage(iTextReader, iPage)
                iTextImage = Image.GetInstance(iTextPage)
                If iTextReader.GetPageSize(iPage).Height <
iTextReader.GetPageSize(iPage).Width Then
                    iTextImage.RotationDegrees = 90
                End If
                iTextDoc.Add(iTextImage)
            Next
            iTextDoc.Close()

        Catch ex As Exception
            System.Diagnostics.EventLog.WriteEntry("iText", ex.Source & " "
& ex.Message & " " & ex.StackTrace)
        Finally
            iTextReader = Nothing
            iTextStamper = Nothing
            iTextWriter = Nothing
            iTextDoc = Nothing
            iTextImage = Nothing
            iTextPage = Nothing
            iTextFDF = Nothing
            memStm.Flush()
            memStm = Nothing
            htFields = Nothing
        End Try
    End Sub

-- 
View this message in context: 
http://old.nabble.com/Could-not-find-XObject-named-%27-s%27.-Browser-locks-up.-tp26344825p26344825.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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