Link to home
Start Free TrialLog in
Avatar of AccurateDesign
AccurateDesign

asked on

Link to a Bookmark in a PDF using ASP

I have to update the PDF in this page and it has a sidebar that links to various bookmarks in PDFs... but it is not working for some reasons.

This was made back in 2008, so is it possible that the code has changed since then?


Here is the link
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

What is not working?  Seems to work fine in chrome
Avatar of AccurateDesign
AccurateDesign

ASKER

if you click on Introduction, it should go to page 3 to the header Introduction, but it is not working for me

Also the red subtitles on the left don't seem to be working as well
Ok, in your embed code try using below code. I am taking this from http://tools.ietf.org/html/rfc3778#page-3

#nameddest=Introduction or #page=3

Where you have

 <embed id="PDF_Area" name="PDF_Area" class="pdf_width" src="pdfs/ICTC_HRGuide_Intro.pdf#" />

Open in new window


change to
 <embed id="PDF_Area" name="PDF_Area" class="pdf_width" src="pdfs/ICTC_HRGuide_Intro.pdf#nameddest=Introduction" />

Open in new window

or
 <embed id="PDF_Area" name="PDF_Area" class="pdf_width" src="pdfs/ICTC_HRGuide_Intro.pdf#page=3" />

Open in new window


If you are doing this dynamically, then you need to use below assuming your url ends like
http://mysite.com/index.asp?pdf=ICTC_HRGuide_Intro.pdf?bookmark=introduction

Notice I changed the # to a ?

 <embed id="PDF_Area" name="PDF_Area" class="pdf_width" src="pdfs/ICTC_HRGuide_Intro.pdf#nameddest=<%=bookmark%>" />

Open in new window

Edit to last code:

 <embed id="PDF_Area" name="PDF_Area" class="pdf_width" src="pdfs/ICTC_HRGuide_Intro.pdf#nameddest=<%=request.querystring("bookmark")%>" />

Open in new window


However, to be super safe:
bookmark=request.querystring("bookmark")
if bookmark<>"" then
    bookmark=replace(bookmark,"'","")
    bookmark=replace(bookmark,"<","")
    bookmark=replace(bookmark,">","")
end if
 <embed id="PDF_Area" name="PDF_Area" class="pdf_width" src="pdfs/ICTC_HRGuide_Intro.pdf#nameddest=<%=bookmark%>" />

Open in new window

nice! it works, but in Firefox for some reason the nameddest don't work but linking to a page it works... worst case I guess I could link to pages instead of anchors

Works in Firefox
http://myaccuratedev.com/clients/ICTC/08-088/pdfs/ICTC_HRGuide_Intro.pdf#page=3

Not working in Firefox
http://myaccuratedev.com/clients/ICTC/08-088/pdfs/ICTC_HRGuide_Intro.pdf#nameddest=introduction

Weirdly, this works in IE only
http://myaccuratedev.com/clients/ICTC/08-088/pdfs/ICTC_HRGuide_Intro.pdf#introduction
Turns out apparently the only browser it doesn't work is in Chrome, unless I add "nameddest" in the URL but then it doesn't work in IE and Firefox.

Is there a way to detect Chrome and add "nameddest" in the URL?
I would just use the page.  What I see here, http://tools.ietf.org/html/rfc3778#page-3 is there is a difference between a bookmark and nameddest.  Maybe you need to add a nameeddest in the pdf as well as the bookmark.   Are you generating the pdf's dynamically?

The page seems the easy route.
I would like to, but the client is expecting to work the same way since I am doing an update with a newer PDF.

So I found a code below, not sure if it's the right syntax (really new in ASP)... but it is not working

<%
If (Sys.Browser.agent == Sys.Browser.Chrome) Then
	Response.Write("is chrome")
End If
%>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
works perfectly!

here is the final code I ended up using:

<%
'Detecting the Chrome browser to add later on some specific code'
dim agent, isChrome
isChrome=0
agent=lcase(Request.ServerVariables("HTTP_USER_AGENT"))
if instr(agent,"chrome") then 
	isChrome=1
end if

'If the current browser is Chrome add some special code'
if isChrome=1 then
	goToBookmark = "#nameddest="
	else
	goToBookmark = "#"	
end if
%>

Open in new window


and later in the page I called this variable and now the bookmark linking feature works fine in IE, Firefox and Chrome... yay! :)
This was a good question. I learned something new in researching this.  Bookmark vs Named Destination.   Thanks for the points.