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
673 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 13

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

*Adobe Acrobat 9 was used for this article. Particular steps may vary depending on software versions. 1. Create a framework of your form in Word, leaving space where you’d ultimately like the Adobe fields to appear.  (Note: I use the blank lines …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In this second video of the Xpdf series, we discuss and demonstrate the PDFimages utility, which, in a single command, is able to extract all the images from a PDF file and save each one in a separate image file (PBM, PPM, or JPG). Download and inst…

717 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