ITextSharp stamper corrupting pdf

I am trying to rotate various pages in a pdf document using ITextSharp. It appears that it is working because when I open in adobe, everything looks good. However when trying to re-open in itextsharp, various exceptions are thrown. I can tell something is up with the document because adobe always asks if I want to save the changes when opening a document manipulated with itextsharp, which indicates that it fixed the corruption.

The crazy thing is that I don't even have to do any manipulation to the document, just create a new stamper and close it. Below is the code, stripped down to the point where it still corrupts the document.

Any ideas?

Here is my code

Dim byteArray = IO.File.ReadAllBytes(filename)

Using reader = New iTextSharp.text.pdf.PdfReader(byteArray)
     Using stamper = New iTextSharp.text.pdf.PdfStamper(reader, New IO.FileStream(filename, IO.FileMode.OpenOrCreate))
                'I don't even have to do anything for it to corrupt, just use a stamper
                stamper.Close()
     End Using
     reader.Close()
End Using

I figured out the problem. I changed this

IO.FileMode.OpenOrCreate

to

IO.FileMode.Create

And it works fine now. I'm not sure why but if anyone else has this issue, I hope this helps.

链接地址: http://www.djcxy.com/p/46760.html

上一篇: 如何以编程方式将Word文件转换为PDF?

下一篇: ITextSharp印模腐蚀pdf