简体   繁体   中英

Export to pdf in asp.net + vb.net using itextsharp

I am trying to export gridview(HTML Based) to a pdf in asp.net+vb.net(backend). When I click on the Export to PDF button the download window shows, but when you click on open Adobe reader will open but displays the message

" Adobe Reader Could not open 'test[1].pdf' because it is either not a supported file type or because the file has been damaged ( for example, it was sent as an email attachment and wasn't correctly decoded) " .

The coding for export to pdf is same for 5 different reports of which 4 are working fine, as well as export to Excel is also working fine for all 5 reports. I searched on google but was not able to find the correct answer. Does it have any relation with the itextsharp dll version? ( I am using itextsharp version 3.1.1.0)

This type of problem commonly occurs with ASP.NET web forms when you fail to explicitly call Response.End() immediately after you call the Document object's Close() method. When you fail to call Response.End() , the web form appends it's HTML markup to the PDF output stream and corrupts the document.

You can verify this by saving the PDF to a local drive and opening it with any text editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM