On 10/8/18 10:09 AM, Hans van der Meer wrote:
I am embedding links to an URL 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.
Many thanks for your reply, dr. Hans van der Meer. Sorry, but I’m afraid I don’t see the way of generating an URL to a non-external document in your code. After all, the document is embedded in the PDF document itself. Pablo
% 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
mailto: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=... or https://www.adobe.com/content/dam/acom/en/devnet/pdf/PDF32000_2008.pdf#named...) 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