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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c#, case, if 4 36
Web page design problem 3 39
C# Get Current Exchange Rate from XE 9 40
bulk load multiple users for aspnetusers table 2 12
PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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) …
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…

738 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