Re: [NTG-context] linking to an external PDF file

2018-10-08 Thread Pablo Rodriguez
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 > > 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 

Re: [NTG-context] linking to an external PDF file

2018-10-08 Thread Hans van der Meer
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 

Re: [NTG-context] linking to an external PDF file

2018-10-08 Thread Henning Hraban Ramm
Am 2018-10-07 um 20:05 schrieb Hans Hagen :

> On 10/7/2018 6:26 PM, Alan Bowen wrote:
>> A how-to question that has come up:
>> Is there a way to establish to hyperlink to a specific page or footnote in 
>> an external PDF document?
> -- first.tex --
> 
> \setupinteraction[state=start]
> 
> \starttext
> 
>whatever \footnote[whatever:1]{whatever 1}
> 
>\goto{note 3}[second::whatever:3]
>\goto{note 4}[second::whatever:4]


BTW if you don’t know a reference name (from a foreign PDF), you can link to 
the page like this:

\goto{TEST}[../../somepdffile::page(23)]

i.e. it works even with paths.

Greetlings, Hraban
---
https://www.fiee.net
http://wiki.contextgarden.net
https://www.dreiviertelhaus.de
GPG Key ID 1C9B22FD

___
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
___

Re: [NTG-context] linking to an external PDF file

2018-10-07 Thread Hans Hagen

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
___

Re: [NTG-context] linking to an external PDF file

2018-10-07 Thread Pablo Rodriguez
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,

Pablo
-- 
http://www.ousia.tk
___
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
___

Re: [NTG-context] linking to an external PDF file

2018-10-07 Thread Hans Hagen

On 10/7/2018 8:19 PM, Pablo Rodriguez wrote:

On 10/7/18 8:05 PM, Hans Hagen wrote:

On 10/7/2018 6:26 PM, Alan Bowen wrote:

A how-to question that has come up:

Is there a way to establish to hyperlink to a specific page or footnote
in an external PDF document?


Many thanks for your reply, Hans.

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

-
  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
___

Re: [NTG-context] linking to an external PDF file

2018-10-07 Thread Pablo Rodriguez
On 10/7/18 8:05 PM, Hans Hagen wrote:
> On 10/7/2018 6:26 PM, Alan Bowen wrote:
>> A how-to question that has come up:
>>
>> Is there a way to establish to hyperlink to a specific page or footnote 
>> in an external PDF document?

Many thanks for your reply, Hans.

Is there a way to hyperlink to an attached document? I mean, no matter
whether it has been generated by ConTeXt or not.

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
___
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
___

Re: [NTG-context] linking to an external PDF file

2018-10-07 Thread Hans Hagen

On 10/7/2018 6:26 PM, Alan Bowen wrote:

A how-to question that has come up:

Is there a way to establish to hyperlink to a specific page or footnote 
in an external PDF document?

-- first.tex --

\setupinteraction[state=start]

\starttext

whatever \footnote[whatever:1]{whatever 1}

\goto{note 3}[second::whatever:3]
\goto{note 4}[second::whatever:4]

\in{note (1)}[whatever:1]
\in{note (2)}[whatever:2]
\in{note (3)}[second::whatever:3]
\in{note (4)}[second::whatever:4]

\page

whatever \footnote[whatever:2]{whatever 2}

\goto{note 3}[second::whatever:3]
\goto{note 4}[second::whatever:4]

\in{note (1)}[whatever:1]
\in{note (2)}[whatever:2]
\in{note (3)}[second::whatever:3]
\in{note (4)}[second::whatever:4]

\stoptext

-- second.tex --


\setupinteraction[state=start]

\starttext

whatever \footnote[whatever:3]{whatever 3}

\goto{note 1}[first::whatever:1]
\goto{note 2}[first::whatever:2]

\in{note (1)}[first::whatever:1]
\in{note (2)}[first::whatever:2]
\in{note (3)}[whatever:3]
\in{note (4)}[whatever:4]

\page

whatever \footnote[whatever:4]{whatever 4}

\goto{note 1}[first::whatever:1]
\goto{note 2}[first::whatever:2]

\in{note (1)}[first::whatever:1]
\in{note (2)}[first::whatever:2]
\in{note (3)}[whatever:3]
\in{note (4)}[whatever:4]

\stoptext

--

the \in ref to the other doc will work ok in a next beta (normally one 
will use a proper project / component structure for such cases)


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
___

[NTG-context] linking to an external PDF file

2018-10-07 Thread Alan Bowen
A how-to question that has come up:

Is there a way to establish to hyperlink to a specific page or footnote in
an external PDF document?

Alan
___
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
___