hello all - again, i have a small number of PDFs (see attached) that dont play well with iTextSharp. when i open my outputted file get the error message: "There was an error processing a page. There was a problem reading this document (18)."
if i comment out the stampers GetPdfLayers method, OR the stampers SetField method contained in my loop everything works fine. but when used in unison i get the error above. thanks for the help, here is my code Jason http://old.nabble.com/file/p26376799/Error18.pdf Error18.pdf http://old.nabble.com/file/p26376799/Error18.fdf Error18.fdf 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 sStream, sValue As String Dim htFields As New Hashtable Dim enField As IDictionaryEnumerator Dim iTextByte As Byte() Dim aEnc As New System.Text.ASCIIEncoding Try Dim sPDF As String = "C:\error18.pdf" 'Read PDF & FDF into memory iTextReader = New PdfReader(sPDF) iTextFDF = New FdfReader(sPDF.Replace(".pdf", ".fdf")) iTextStamper = New PdfStamper(iTextReader, memStm) iTextReader.Close() 'Watermark Code If iTextStamper.GetPdfLayers.Contains("SEAS Draft Watermark") Then ' For iPage = 1 To iTextStamper.Reader.NumberOfPages ' iTextByte = iTextStamper.Reader.GetPageContent(iPage) ' sStream = aEnc.GetString(iTextByte) ' sStream = sStream.Replace("DRAFT COPY", "") ' iTextStamper.Reader.SetPageContent(iPage, aEnc.GetBytes(sStream)) ' Next End If '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 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)) 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 iTextByte = Nothing memStm.Flush() memStm = Nothing htFields = Nothing aEnc = Nothing End Try MsgBox("Done") End Sub -- View this message in context: http://old.nabble.com/GetPdfLayers-method-for-Stamper-yields-Error-message-on-outputted-PDF-tp26376799p26376799.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/