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?
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.
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.
@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.
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)..
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.