L2wis
L2wis

Reputation: 294

Stream PDF to browser and utilise Adobe PDF parameters such as #search, #zoom, #page

This one is killing me! In ASP Classic I'm trying to stream users a pdf file, so far i've got the following code:

Response.Buffer = False
'This is download
Response.ContentType = ContentTypeFromFile(DownloadFileName)
'Set file name
Response.AddHeader "Content-Disposition", "inline; filename=myfile.pdf#search=fox"
Response.binarywrite "c:/myfile.pdf"

However it's not working and the ? and # are changed to _ when I run it which causes the file download to break.

I found the same question asked on here but it was 3 years ago and I've tried doing what the accepted answer suggested without any success.

Can anyone help me?

Link to the old question: https://stackoverflow.com/search?q=open+pdf+with+search

Upvotes: 1

Views: 3687

Answers (1)

L2wis
L2wis

Reputation: 294

Okay finally I worked this one out! The answer given in the other question is the actual answer, understanding it however was the tricky part!

Have this code in your page:

<%
response.Clear

Response.Buffer = False
'This is download
Response.ContentType = "application/pdf"
'Set file name
Response.AddHeader "Content-Disposition", "inline; filename=myfile.pdf"

set stream = Server.CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1 ' binary
stream.LoadFromFile("c:\test.pdf")

Response.BinaryWrite(stream.Read)

Response.End()
%>

And then you pass the parameters to the adobe reader through the url! So if the code above is in a page called: default.asp

then do this: http://www.yoururl.com/default.asp#search=fox&zoom=20&page=2

and it will work a treat! Not in google chrome mind you! I googled about getting this sort of thing working in chrome however google didn't code in parameters into their pdf viewer.

Upvotes: 1

Related Questions