0

I'm trying to write a pdf file to the browser and when the client print the pdf the filename sent to the printer is the name of the file. But now i'm getting the name of the asp page sent to the browser "loadfile.asp"

Because I can't put a title in my page when i'm using Response.ContentType = "application/pdf", I've added a page that do a server.Transfer.

But everytime the code pass trought the Response.ContentType = "application/pdf" the title get blanked.

So here's my code : First Page :

<html>
<head>
<title>
    <%= Request.QueryString("File") & ".PDF" %>
</title>
</head>
<body>

<%

Server.Transfer "loadfileAfter.asp"

%>
</body>
</html>

Here's the Second Page (loadfileAfter.asp) :

    Response.ContentType = "application/pdf"
    Response.AddHeader "content-disposition", "Filename=" & Request.QueryString("File") & ".PDF"
    Const adTypeBinary = 1


    strFilePath = "D:\" &  Request.QueryString("File") & ".PDF" 'This is the path to the file on disk. 

    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = adTypeBinary
    objStream.LoadFromFile strFilePath

    Response.BinaryWrite objStream.Read

    objStream.Close
    Set objStream = Nothing

I tought that this line would help :

Response.AddHeader "content-disposition", "Filename=" & Request.QueryString("File") & ".PDF"

But it did not change a thing.

Thanks for your help

GregM
  • 2,634
  • 3
  • 22
  • 37
  • Is this browser-specific? How is the PDF sent to the printer - is it sent by the browser, or by the plugin inside the browser (like Adobe Reader) – G. Stoynev Apr 03 '13 at 16:00
  • Yeah adobe reader ! sorry I've should have said it. and it don't seems to be browser specific – GregM Apr 03 '13 at 16:22
  • I don't think writing pdfs is something Classic ASP can do out of the box. ABCpdf is a popular third party component. http://www.websupergoo.com/abcpdf-1.htm – John Apr 03 '13 at 22:13
  • check this link: http://classicasp.aspfaq.com/files/directories-fso/how-do-i-send-the-correct-filename-with-binarywrite.html – Flakes Apr 05 '13 at 07:30
  • @GregM, I have same issue. did you find any solution for this case? – mhesabi Nov 24 '13 at 10:28

1 Answers1

1

This one worked for me:
Response.AddHeader "content-disposition", "attachment; filename=""" & fileName & """"