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
625 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
In a previous article published here at Experts Exchange, Signature Image with Transparent Background (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_12380-Signature-Image-with-Transparent-Background.html), I explained how to cre…
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now