?
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
Medium Priority
?
675 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 1400 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 600 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 …
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…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

752 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