Leonard Rosenthol-3 wrote:
>
> You need to flatten the annotations before you start grabbing the pages.
>
Leonard,
Thank you for your reply. Unfortunately, I was unsuccessful in
discovering how to go about this. The code that follows was my best guess,
as I could only find a "flatten" method on PDFStamper, however, the
following code results in the error: "The resulting file is not a valid PDF
document".
Any specific examples that you could throw my way or point me to would be
greatly appreciated.
Thanks in advance for your help.
Public Function ReturnCompatiblePdfFromInputStream(ByVal FileUpload1 As
HtmlInputFile) As MemoryStream
Dim fileLen As Integer
Dim myStream As System.IO.Stream
' Get the length of the file.
fileLen = FileUpload1.PostedFile.ContentLength
'Create a byte array to hold the contents of the file.
Dim Input(fileLen) As Byte
' Initialize the stream to read the uploaded file.
myStream = FileUpload1.PostedFile.InputStream
' Read the file into the byte array.
myStream.Read(Input, 0, fileLen)
'---- Reset to position 0 before we pass it
myStream.Position = 0
Dim reader As New iTextSharp.text.pdf.PdfReader(myStream)
Dim output_stream2 As New MemoryStream
Dim output_stream As New MemoryStream
' we retrieve the total number of pages
Dim n As Integer = reader.NumberOfPages
' step 1: creation of a document-object
Dim document As New
iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
' step 1.5: Create a PDF Stamper to flatten the document before we
start pulling pages
Dim pdfStamper As iTextSharp.text.pdf.PdfStamper = New
iTextSharp.text.pdf.PdfStamper(reader, output_stream2)
pdfStamper.FormFlattening = True
pdfStamper.Writer.CloseStream = False
pdfStamper.Close()
'---- Reset to position 0 before we pass it
output_stream2.Position = 0
'---- Create a new reader using the results of the flattened PDF
reader = New iTextSharp.text.pdf.PdfReader(output_stream2)
' step 2: we create a writer that listens to the document
Dim writer As iTextSharp.text.pdf.PdfWriter = pdfStamper.Writer
'write pdf that pdfsharp can understand
writer.SetPdfVersion(iTextSharp.text.pdf.PdfWriter.PDF_VERSION_1_4)
' step 3: we open the document
document.Open()
Dim cb As iTextSharp.text.pdf.PdfContentByte
Dim page As iTextSharp.text.pdf.PdfImportedPage
Dim rotation As Integer
Dim i As Integer = 0
While i < n
i += 1
cb = pdfStamper.GetUnderContent(i)
document.SetPageSize(reader.GetPageSizeWithRotation(i))
document.NewPage()
page = writer.GetImportedPage(reader, i)
rotation = reader.GetPageRotation(i)
If rotation = 90 OrElse rotation = 270 Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, _
reader.GetPageSizeWithRotation(i).Height)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, _
0)
End If
End While
'---- Keep the stream open!
writer.CloseStream = False
' step 5: we close the document
document.Close()
output_stream.Position = 0
Return output_stream
End Function
--
View this message in context:
http://itext-general.2136553.n4.nabble.com/PDF-to-PDFA-Conversion-tp3303633p3430418.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
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