473,790 Members | 2,850 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Force Download PDF Problem

I am wishing to force the Open|Save dialog box for a PDF and Excel
file.

I am using the following code:

Response.Clear( );
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "attachment ; filename=" +
saveFilename );
Response.Flush( );
Response.WriteF ile(savePath);

While this works perfect for the Excel file, however, the PDF file does
not open, whether direct from the dialog box or by saving it to disk
and opening it, I get the following error in Adobe Acrobat Reader (v5.0
& v7.0):

"There was an error opening this document. The file is damaged and
could not be repaired."

The original PDF file is okay. Also, the size of the original PDF is
50k, where as the one that is downloaded to the client is 237k.

I have tried various other things such as creating a FileStream and
using Response.Binary Write, and various other ContentTypes, including
application/pdf.

Has anyone had this before, or know of a workaround? Ideally I would
like the dialog box to always appear for this pdf.

Dec 20 '05 #1
5 2807
RCS
I know you're looking for something helpful - but I can say, that looks 100%
correct.. so if nothing else, it doesn't appear to be anything obvious. Good
luck

"gaubo79" <jo********@hot mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I am wishing to force the Open|Save dialog box for a PDF and Excel
file.

I am using the following code:

Response.Clear( );
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "attachment ; filename=" +
saveFilename );
Response.Flush( );
Response.WriteF ile(savePath);

While this works perfect for the Excel file, however, the PDF file does
not open, whether direct from the dialog box or by saving it to disk
and opening it, I get the following error in Adobe Acrobat Reader (v5.0
& v7.0):

"There was an error opening this document. The file is damaged and
could not be repaired."

The original PDF file is okay. Also, the size of the original PDF is
50k, where as the one that is downloaded to the client is 237k.

I have tried various other things such as creating a FileStream and
using Response.Binary Write, and various other ContentTypes, including
application/pdf.

Has anyone had this before, or know of a workaround? Ideally I would
like the dialog box to always appear for this pdf.

Dec 20 '05 #2
1) Use ClearHeaders() and ClearContents() CH is imo important for
authentication issues.
2) Response.End really seems to flush, Response.Flush seems not enough.
3) Not using Response.end seems to be a problem on localhost only so far.

I ran across the R.E issue yesterday,.
Odd, i was trying to avoid this end.

"RCS" <rs****@gmail.c om> schreef in bericht
news:AI******** ********@newssv r24.news.prodig y.net...
I know you're looking for something helpful - but I can say, that looks
100% correct.. so if nothing else, it doesn't appear to be anything
obvious. Good luck

"gaubo79" <jo********@hot mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I am wishing to force the Open|Save dialog box for a PDF and Excel
file.

I am using the following code:

Response.Clear( );
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "attachment ; filename=" +
saveFilename );
Response.Flush( );
Response.WriteF ile(savePath);

While this works perfect for the Excel file, however, the PDF file does
not open, whether direct from the dialog box or by saving it to disk
and opening it, I get the following error in Adobe Acrobat Reader (v5.0
& v7.0):

"There was an error opening this document. The file is damaged and
could not be repaired."

The original PDF file is okay. Also, the size of the original PDF is
50k, where as the one that is downloaded to the client is 237k.

I have tried various other things such as creating a FileStream and
using Response.Binary Write, and various other ContentTypes, including
application/pdf.

Has anyone had this before, or know of a workaround? Ideally I would
like the dialog box to always appear for this pdf.


Dec 20 '05 #3
If, by some chance, you have entered an IIS->asp.net mapping for PDF
documents, delete it. The problem will go away. This happened to me
when I tried to add a mapping so as to allow for asp.net to control
security on PDF documents.

gaubo79 wrote:
I am wishing to force the Open|Save dialog box for a PDF and Excel
file.

I am using the following code:

Response.Clear( );
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "attachment ; filename=" +
saveFilename );
Response.Flush( );
Response.WriteF ile(savePath);

While this works perfect for the Excel file, however, the PDF file does
not open, whether direct from the dialog box or by saving it to disk
and opening it, I get the following error in Adobe Acrobat Reader (v5.0
& v7.0):

"There was an error opening this document. The file is damaged and
could not be repaired."

The original PDF file is okay. Also, the size of the original PDF is
50k, where as the one that is downloaded to the client is 237k.

I have tried various other things such as creating a FileStream and
using Response.Binary Write, and various other ContentTypes, including
application/pdf.

Has anyone had this before, or know of a workaround? Ideally I would
like the dialog box to always appear for this pdf.


Dec 20 '05 #4
Joey,

I certainly haven't entered one, is there anyway it could be there by
default?

I had a look through IIS manager, but couldn't find anything, where
would it be if it was in place?

Thanks

Joey wrote:
If, by some chance, you have entered an IIS->asp.net mapping for PDF
documents, delete it. The problem will go away. This happened to me
when I tried to add a mapping so as to allow for asp.net to control
security on PDF documents.

gaubo79 wrote:
I am wishing to force the Open|Save dialog box for a PDF and Excel
file.

I am using the following code:

Response.Clear( );
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "attachment ; filename=" +
saveFilename );
Response.Flush( );
Response.WriteF ile(savePath);

While this works perfect for the Excel file, however, the PDF file does
not open, whether direct from the dialog box or by saving it to disk
and opening it, I get the following error in Adobe Acrobat Reader (v5.0
& v7.0):

"There was an error opening this document. The file is damaged and
could not be repaired."

The original PDF file is okay. Also, the size of the original PDF is
50k, where as the one that is downloaded to the client is 237k.

I have tried various other things such as creating a FileStream and
using Response.Binary Write, and various other ContentTypes, including
application/pdf.

Has anyone had this before, or know of a workaround? Ideally I would
like the dialog box to always appear for this pdf.


Dec 21 '05 #5
Response.ClearH eaders();
Response.ClearC ontent();
Response.Conten tType="applicat ion/octet-stream";
Response.AddHea der("content-disposition","a ttachment; filename=" +
saveFilename);
Response.WriteF ile(savePath);
Response.End();

This works fine, many thanks.

Dec 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5245
by: Matthew Sims | last post by:
Is it possible to force a download without using the readfile function? My website setup consists of my server that serves the web pages plus a high-speed file server elsewhere on the internet that servers my files. I'm currently using header("Location: abc.com") to redirect my users to this other site but can't force a download. I can get it to work using readfile() but that means the file moves from the high-speed server through my...
2
12642
by: Jonathan Driller | last post by:
I am attempting to block repeat downloads from a site. I need to have a landing page pass a referer to a secured page. I have tried a meta refresh redirect and several Javascript redirect strategies but none pass the referer. How can I force this since the referer property is read only? I have set up an .htaccess file so it will only let people into a secure directory if they come from an internal page on my site. This is done by...
0
1216
by: Jake | last post by:
How can I force an image download with IE using ASP.net?? Here is the catch: the image I want to force a write with is located on another web server. I can only reference the image with a URL. If the image is on my machine, I use the response.wrifefile method. After setting up my headers I can force an image download. However, I can't get this to work if I reference the image via a url.
4
21954
by: Kevin Muenzler, WB5RUE | last post by:
How do I force a browser to download a file instead of displaying it? In other words I have a page with MP3 and WMA files on it and I would like for the visitor to download the file instead of play it without having to right-click and save. How can I force the browser to pop up the "save file as" dialog box instead of playing it? I know that I can encapsulate it in a zip file which will download and open WinZip. Thanks
4
1701
by: tma | last post by:
Short of zipping my file, are there any other alternatives to the below? I'm trying to add anchors in code and I need the link to force a download of the .pdf rather than open a new window or worse, open the file in the current client browser window. Is there something I can change about the anchor itself to force this behavior? I did not have any success with the "content-disposition" articles suggested. Here is my very normal anchor...
0
2662
by: comp.lang.php | last post by:
I have a form that when you click the "Generate Report" submit button, it will force download a CSV file, required for this project. On the very same page you also have a "Search" submit button, when you press it it should generate search results in a new page. However, when you click the "Generate Report" submit button, the moment you try to THEN click the "Search" submit button, the "Search" submit button NEVER goes to a new page but...
2
2354
by: comp.lang.php | last post by:
class ReportGenerator { function ReportGenerator() {} /** * Generate the HTTP headers necessary for this file type. Can be called statically *
3
2468
by: Bouffa | last post by:
Hello everyone, I suppose you all know force-download scripts. The problem is that these scripts don't allow files to be splitted when downloading them via a download manager. I've found a solution to enable download resuming, but now, it remains the splitting problem. Does anyone have any idea ?
0
2680
by: jinnareddy | last post by:
Hi, I'm unable to download a file that is having a 2-byte char in its name (e.g.テ) using force download option. Though, am able to download file names involving ASCII chars. I have tried URL encoding too, but with no success. Can someone provide details on how to handle the 2-byte char URLs and download the files? Appreciate your suggestions/help in resolving it. Here is my code:
1
1818
by: JP SIngh | last post by:
Hi All We have a page which we want to allow our users to download files. Can someone point to peice of code that we can use to force the download as opposed to opening the files in the browser. Only one issue here the code need to work with UNC path like \\myserver\files\ and not just c:\inetpub\wwwroot\files
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7530
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.