From: Hans van der Meer <havdmeer@ziggo.nl>
To: NTG ConTeXt <ntg-context@ntg.nl>
Subject: Re: linking to an external PDF file
Date: Mon, 8 Oct 2018 10:09:11 +0200 [thread overview]
Message-ID: <4C90F3DD-A248-4C3A-A5CD-E46E85DD5AC7@ziggo.nl> (raw)
In-Reply-To: <ca1b4ed4-2f49-ec0e-82d1-7f72ba45c9ce@xs4all.nl>
[-- Attachment #1.1: Type: text/plain, Size: 6083 bytes --]
I am embedding links to an UR in my documents. Although it is used in XML-documents, you might be able to use the gist of this code that generates a clickable link. Perhaps you find it useful.
dr. Hans van der Meer
% Return the code when clicking the link.
\def\URIReturnCode#1{\ctxlua{tex.print(hvdm.urireturncode("#1"))}}
— Some Lua code needed:
-- Check URI
socket.http.TIMEOUT = 5 -- set URI timeout in seconds
hvdm.urireturncode = function (theuri)
-- Differentiate between file and http protocols.
local first,last = string.find(theuri, "file://")
if first == nil then
-- We have http to search for.
local content, status, authinfo = socket.http.request{
method = "HEAD",
url = theuri,
}
return type(status) == "number" and status or "failure"
else
-- We must ascertain the existence of the file.
local thefile = io.open(string.sub(theuri, last+1, -1), "r")
if thefile then
io.close(thefile)
return "200"
else
return "404"
end
end
end
% ..... Place an url link .....................................................
% BEWARE: spaces in file names must be %20 in the link !!!
% This global definition of the URLbase cannot be missed.
\def\THEURLBASE{http://}
% Signal the occurence of timeout on URI search.
\newif\ifURItimeout
\startxmlsetups xmlcommon:urlbase
\edef\THEURLBASE{\xmlstrippednolines{#1}{.}}
% Reset the URI timeout for new URLbase.
\global\URItimeoutfalse
\stopxmlsetups
\startxmlsetups xmlcommon:url
% Define the full uri.
\edef\theurl{\THEURLBASE\xmlatt{#1}{link}}
% File suffix should be one of the list.
\doifelse{\FileSuffixList{\xmlatt{#1}{link}}
{pdf,jpg,jpeg,html,png,tif,tiff}}{\empty}
{\def\suffix{.impossible}}% no suffix from the list here
{\def\suffix{\empty}}% one of the list is present
% First try link as given, beware of unreachable site.
\ifURItimeout
% For previously timeout on this site.
\else
\edef\returncode{\URIReturnCode{\theurl}}
\doif{\returncode}{failure}
{
\global\URItimeouttrue
\errorcall{#1}{url access fails for \THEURLBASE\xmlatt{#1}{link}}
}
\fi
% On URI timeout there is no hope to find the file.
\ifURItimeout
\else
% When there is no suffix from the list, try several.
\doifnot{\suffix}{\empty}
{
\scratchcounter=200\relax
\ifnum\returncode=\scratchcounter\else
\def\suffix{.pdf}
\edef\returncode{\URIReturnCode{\theurl\suffix}}
\fi
\ifnum\returncode=\scratchcounter\else
\def\suffix{.jpg}
\edef\returncode{\URIReturnCode{\theurl\suffix}}
\fi
\ifnum\returncode=\scratchcounter\else
\def\suffix{.jpeg}
\edef\returncode{\URIReturnCode{\theurl\suffix}}
\fi
\ifnum\returncode=\scratchcounter\else
\def\suffix{.html}
\edef\returncode{\URIReturnCode{\theurl\suffix}}
\fi
\ifnum\returncode=\scratchcounter\else
\def\suffix{.png}
\edef\returncode{\URIReturnCode{\theurl\suffix}}
\fi
\ifnum\returncode=\scratchcounter\else
\def\suffix{.tiff}
\edef\returncode{\URIReturnCode{\theurl\suffix}}
\fi
\ifnum\returncode=\scratchcounter\else
\def\suffix{.tif}
\edef\returncode{\URIReturnCode{\theurl\suffix}}
\fi
}
% Give up if returncode other then 200.
\ifnum\returncode=200\relax
% Page number might be added.
\doifelse{\xmlatt{#1}{page}}{\empty}
{\let\thep\empty}
{\edef\thep{\letterhash page=\xmlatt{#1}{page}}}
% Place the link, ref-attribute prevales in the presentation.
\doifelse{\xmlatt{#1}{ref}}{\empty}
{\edef\temp{\xmlatt{#1}{link}}}
{\edef\temp{\xmlatt{#1}{ref}}}
\goto
{\FirstLastCharacters{\temp}{\xmlatt{#1}{maxsize}}}
[url(\theurl\suffix\thep)]
\else
\errorcall{#1}
{\THEURLBASE\xmlatt{#1}{link} not found (\returncode)}
\fi
\fi % end of URItimeout
\stopxmlsetups
> On 8 Oct 2018, at 00:39, Hans Hagen <j.hagen@xs4all.nl> wrote:
>
> On 10/7/2018 8:41 PM, Pablo Rodriguez wrote:
>> On 10/7/18 8:33 PM, Hans Hagen wrote:
>>> On 10/7/2018 8:19 PM, Pablo Rodriguez wrote:
>>>> [...]
>>>> Is there a way to hyperlink to an attached document? I mean, no matter
>>>> whether it has been generated by ConTeXt or not.
>>>> i have no clue what you mean
>> Is there a way to link to a page or a destination (such as in
>> https://www.adobe.com/content/dam/acom/en/devnet/pdf/PDF32000_2008.pdf#page=500
>> or
>> https://www.adobe.com/content/dam/acom/en/devnet/pdf/PDF32000_2008.pdf#nameddest=G12.2456615)
>> to a document that is attached (using \attachment) in ConTeXt?
>> I hope it is clear now,
> it points to the media mess .. which relates to either or not obsolete stuff (flash related)
>
> anyway, i don't know as i never embed pdf docs and if i would i'd have no reason to refer to them (it probably depends on a viewer extracting the attachment, caching it and then providing access: it makes no sense to waste time on features that are not supported or maybe only by acrobat unless it's a well paid projects in which case throw away code is a bit less waste of time because it brings foon on the table)
>
> Hans
>
> -----------------------------------------------------------------
> Hans Hagen | PRAGMA ADE
> Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
> tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : http://www.pragma-ade.nl / http://context.aanhet.net
> archive : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
[-- Attachment #1.2: Type: text/html, Size: 21880 bytes --]
[-- Attachment #2: Type: text/plain, Size: 492 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2018-10-08 8:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-07 16:26 Alan Bowen
2018-10-07 18:05 ` Hans Hagen
2018-10-07 18:19 ` Pablo Rodriguez
2018-10-07 18:33 ` Hans Hagen
2018-10-07 18:41 ` Pablo Rodriguez
2018-10-07 22:39 ` Hans Hagen
2018-10-08 8:09 ` Hans van der Meer [this message]
2018-10-08 17:58 ` Pablo Rodriguez
2018-10-08 8:08 ` Henning Hraban Ramm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C90F3DD-A248-4C3A-A5CD-E46E85DD5AC7@ziggo.nl \
--to=havdmeer@ziggo.nl \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).