Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Link directly to a .pdf from a TOC in a .chm

40 views
Skip to first unread message

V Bowman

unread,
Oct 18, 2001, 1:29:17 PM10/18/01
to
I need to link directly to a .pdf file from a TOC in a .chm file. I want the
.pdf to open in a separate, secondary window. If that's not possible,
opening in the topic window might be okay.

Is there a way to do this? I am using FAR to build the .chm. If someone
could let me know how to get this to work, it would be greatly appreciated.

Thanks,
Veronica


Pete Lees

unread,
Oct 18, 2001, 3:55:41 PM10/18/01
to
Veronica Bowman <veronic...@bmc.com> wrote:

> I need to link directly to a .pdf file from a TOC in a .chm file. I want
the
> .pdf to open in a separate, secondary window.

I think the method you use depends on where the .pdf file is located.

If the .pdf file is on a Web site, you'd just use a standard URL as the
target of the TOC entry. For example:

http://www.domain.com/pdf/sample.pdf

In this case, the <object> tag in the .hhc file looks like this:

<LI> <OBJECT type="text/sitemap">
<param name="Name" value="Entry title in TOC">
<param name="Local" value="http://www.domain.com/pdf/sample.pdf">
<param name="WindowName" value="SecWindow">
</OBJECT>

If the .pdf file is stored in the same local directory as the .chm, I think
you can use JavaScript to write a hidden Shortcut control into whatever is
the current topic. Clicking the TOC entry executes the control, which opens
the .pdf file in the Acrobat Reader (or in Acrobat, if you have the full
package installed).

The procedure is as follows:

1) Paste the following code into a new text file. (Acknowledgements to Jeff
Hall, who posted the code to this newsgroup a little while ago. I've
modified it slightly to get the desired result.)

//---CHMPATH.JS START---
// Create the document.chmfile object for each page
var chmfile = new Object();
chmfile.fullname = "";
chmfile.name = "";
chmfile.path = "";
chmfile.page = "";
getchmfile();

function getchmfile(){
var ra, sl, a, X, Y, Z;
ra = /:/;
a = location.href.search(ra);
sl = "::";
Y = location.href.lastIndexOf(sl);
if (a == 4) {// file: or http:
Y = location.href.lastIndexOf("/");
chmfile.page = unescape(location.href.substring(Y+1));
if(location.href.substring(0,4) == "file"){
chmfile.path = unescape(location.href.substring(8, Y+1));
}
}
else {
if (a == 2) X = 14; // mk:@MSITStore:
if (a == 7) X = 7; // ms-its:
chmfile.fullname = unescape(location.href.substring(X, Y));
Z = chmfile.fullname.lastIndexOf("\\");
chmfile.path = unescape(chmfile.fullname.substring(0, Z+1));
chmfile.name = unescape(chmfile.fullname.substring(Z+1));
chmfile.page = unescape(location.href.substring(Y+3));
}
}

// Write a Hidden Shortcut Link Object in JavaScript

var pdffile = "sample.pdf";

with(document) {
open();
write('<OBJECT id=ShortCutLink type="application/x-oleobject"');
write(' classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"');
write(' codebase="hhctrl.ocx"');
write(' >');
write(' <PARAM name="Command" value="ShortCut">');
write(' <PARAM name="Item1" value=",'+chmfile.path+pdffile+',">');
write('</OBJECT>');
close();
}
//---CHMPATH.JS END---

2) Save the file as "chmpath.js", and store it in the same directory as your
help project files.

3) Link the file to every HTML file in your .chm by adding the following
line to the <head> sections:

<script language="JavaScript" src="chmpath.js"></script>

4) Specify the following as the target URL for the TOC entry:

javascript:ShortCutLink.Click();

So in this case, the <object> tag in the .hhc file looks like this:

<LI> <OBJECT type="text/sitemap">
<param name="Name" value="Entry title in TOC">
<param name="Local" value="javascript:ShortCutLink.Click();">
</OBJECT>

If you have compiled the .pdf file into the .chm -- which I believe is now
possible with IE 5.5 SP2, although it wasn't with earlier versions of IE --
the target URL should be:

ms-its:filename.chm::/sample.pdf

So in this case, the <object> tag in the .hhc file looks like this:

<LI> <OBJECT type="text/sitemap">
<param name="Name" value="Entry title in TOC">
<param name="Local" value="ms-its:filename.chm::/sample.pdf">
<param name="WindowName" value="SecWindow">
</OBJECT>

I haven't been able to test this, though, so I don't know for sure that it
works.

Pete


Martin Nielsen

unread,
Oct 20, 2001, 2:28:01 AM10/20/01
to
How does JScript work in CHMs? I mean, is it reliable? What happens if the
user disabled scripting in the browser - does this affect javascript in CHM
files as well?

--
Chris

Pete Lees

unread,
Oct 20, 2001, 7:36:58 AM10/20/01
to
Chris <no...@no.spam.com> wrote:

I'm not sure that there is any way for Internet Explorer users to disable
scripting (or ActiveX controls or cookies) for files that are already on
their local computers. However, .chm files that are opened from a Web page
or accessed over an intranet would presumably be a different matter. This is
from IE's help file:

"Any files already on your local computer are assumed to be very safe, so
minimal security settings are assigned to them. You cannot assign a folder
or drive on your computer to a security zone."

There *are* settings that you can change in your browser that will affect
how .chm files display. For example, if you clear the Show Pictures checkbox
in the browser (Tools > Internet Options > Advanced), all the images in your
.chm files will be replaced by placeholders. And changing the default text
size in the browser (View > Text Size) will also have an effect in most
cases.

Pete


0 new messages