Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Creating pdf file using C# causes "Adobe reader cannot open file" error

Back to Forum: Tech Off
  • User profile image


    I am using VS 2010 and C#. I am trying to create a pdf file in web application.

    I am trying to convert a dataset to pdf file. The pdf file is getting generated, but when i try to open the pdf, i am getting the error as "Adobe reader could not open "sample.pdf" because it is either not a supported file type or because the file has been damaged"

    I have tried with "application/pdf" as well as "application/octet-stream". Both are giving the same error.

    How to fix this?

    Thank you

  • User profile image

    Having read through the code, I believe the only adequate explanation is an incredibly astounding amount of ignorance on your part.

    A PDF file is not a serialised .NET DataSet object.

    How on earth did you get this idea that dumping a POCO to the client with a certain MIME type would work?

    What you're doing is just another re-hash of 'converting' an Excel spreadsheet to an Access database by changing the file extension from .xls to .mdb, it only "works" becuase of things you don't understand.

    If you want to learn about strategies for PDF generation, read through a thread I made a few days ago.

    How on earth did you get employed?

  • User profile image


    There really is a first time for everything. you dont really learn everything the time you start working. It is through mistakes that you learn. I got "iText" now. will try it using that.

  • User profile image

    @venkatzeus: While Webbo's response was a bit harsh, your first post does demonstrate a lack of basic understanding of how computers work. It would be like renaming hello.doc to hello.pdf and expecting your Word document to magically become a PDF.

    iTextSharp is a free .NET library to create PDFs with. You could also try creating a text document from the data and then printing it to one of the many free PDF printers. A final option (albeit an expensive one) is to buy Acrobat Server and use its API to create a PDF.

  • User profile image

    windows and office suite are very forgiving when it comes to hacking a mime type onto a file, changing it's extension and hoping the os (and/or called program) figures out what to do with it... but only for formats that office internally supports and only on windows. unfortunately, pdf is not a microsoft-centric format so these specialized libraries that know how to write adobe's document description language are needed. a lot is going on in a pdf (some would argue too much)..

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.