Solved

I'm trying to export a stored procedure to a PDF file, how to resolve attempt to open PDF file, I get error: Adobe Reader could not open 'xxx.pdf' because it is either not a supported file ...?

Posted on 2013-12-10
3
658 Views
Last Modified: 2013-12-11
I am developing my first ASP.NET C# application using VS2010.
I try to write a stored procedure to a PDF file but when I open the PDF file,
I get the following error:

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

My code is in the attached file:
PDF-Code.txt
0
Comment
Question by:zimmer9
3 Comments
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 350 total points
ID: 39709223
The code that you are using is ok for excel file but not for PDF file. Actually the code that you are using just generates an HTML page which is formatted (and then extension of xls) is used to fool Excel in thinking that it is an excel file. If you change the extension to .htm it will show you an HTML table.

Now PDF is a different game altogether so if you need to generate the PDF file then follow this step by step article:

http://www.dotnetfunda.com/articles/show/977/pdf-generator-in-net-dynamically-generate-pdf-in-aspnet

Also in earlier question you have accepted an answer, can you confirm that it is a correct answer:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28313579.html
0
 
LVL 12

Expert Comment

by:jitendra patil
ID: 39711105
hi,
chinmay is right the pdf is a different game.you cannot directly generate a pdf by changing the content type of the file name, for this purpose you need a pdf generating engines such as itextsharp.

see the below links which may help you out.
.pdf generator in .NET - Dynamically generate .pdf in ASP.NET
Exporting a DataTable to PDF
Convert Datatable to PDF
hope this helps.
0
 
LVL 11

Assisted Solution

by:Angelp1ay
Angelp1ay earned 150 total points
ID: 39711206
Let me try to explain with an analogy.

Each file type (e.g. xls, pdf, docx) has a specific data structure. It's like a language. The Excel application speaks xls. Adobe Reader speaks pdf.

The data you dump out with response.write must be in a language matching the file type you claim. You're writing out tab delimited text. This is not valid in the pdf language. Adobe Reader has no idea what it means. You need to instead write out pdf 'words'.

The reason it works with Excel is because the Excel application is multi-lingual. The file you're claiming to be an xls is actually not an xls, but Excel can also speak tab delimited text and is smart enough to auto-detect the language and open it anyway.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this first video of the three-part Xpdf series, we introduce and describe Xpdf, a library containing nine command line utilities that perform various functions on PDF files. We show where the library is located and how to download it, discuss its…
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question