Hyper link methods

You will find a general example for the use of hyperlink here.

Version :
09.11.2021, 08:27 Uhr

Hyper link methods

static int is_valid(ItemRef itemRef)

Does the reference point to an existing bookmark?

Name Type Default Description
Return int   1 : Yes, the ref points to an existing hyperlink.

0 : No frame referenced. Do not use this reference as to be a hyperlink.
itemRef ItemRef - Any ItemRef or 0

Version 1.4.1 R383, 28. June 2007

priint:comet InDesign® Plug-Ins

item::defined

static int count(ItemRef frameRef)

Get the number of hyperlinks in a textframe.

Name Type Default Description
Return int   ≥ 0 : Number of hyperlinks in the text of the frame

-1 : Error
frameRef ItemRef 0 Valid frame reference

0 : Current script frame

v4.1.8 R29140, 21. Sep 2021

priint:comet InDesign® Plug-Ins, comet_pdf

get_nth, get_pos, itemlist::hyperlinks

static int get_nth(
  ItemRef frameRef,
  int nth,
  int* start = 0,
  int* len = 0)

Get the nth hyperlink of a text frame. The results are not sorted by text positions! For a sorted list of hyperlinks of a text please use the itemlist::hyperlinks function.

Name Type Default Description
Return int   0 or error code
frameRef ItemRef 0 Valid frame reference

0 : Current script frame
start int* 0 ≠ 0 : After successful execution, the variable contains the start position of the hyperlink in the text.

0 : Ignore
len int* 0 ≠ 0 : NAfter successful execution, the variable contains the length of the hyperlink in the text.

0 : Ignore

Visit all hyperlinks of a frame.

int by_nth (ItemRef fr)
{
    ItemRef	hy	= item::alloc ();
    int		count	= hyperlink::count (fr);
    int		i, start, len;
for (i = 0; i < count; i++) { hyperlink::get_nth (fr, i, hy, &start, &len); wlog ("", "XXXXX %d : %d %d\n", i+1, start, len);
start = hyperlink::get_pos (hy, &len); wlog ("", "YYYYY %d : %d %d\n", i+1, start, len); }
return 0; }

v4.1.8 R29140, 21. Sep 2021

priint:comet InDesign® Plug-Ins, comet_pdf

count, get_pos, itemlist::hyperlinks

static int get_pos(ItemRef hyRef, int* len = 0)

Determine text position and length of a hyperlink in a text.

Name Type Default Description
Return int   ≥ 0 : Text position of the hyperlink (0-based)

-1 : Error
hyRef ItemRef - Valid reference to a hyperlink of a text.
len int* 0 ≠ 0 : After successful execution, the variable contains the length of the hyperlink in the text.

0 : Ignore

Visit all hyperlinks of a frame in the order of their text positions.

int by_list (ItemRef fr)
{
    ItemList 	hys	= itemlist::hyperlinks (fr);
    ItemRef	hy	= item::alloc ();
    int	i, start, len;
for (i = 0; i < itemlist::length (hys); i++) { itemlist::get (hys, hy, i);
start = hyperlink::get_pos (hy, &len); printf ("YYYYY %d : %d %d\n", i+1, start, len); }
return 0; }

v4.1.8 R29140, 21. Sep 2021

priint:comet InDesign® Plug-Ins, comet_pdf

count, get_nth, itemlist::hyperlinks

static ItemRef get_source(
  ItemRef frameRef,
  ItemRef hyRef = 0,
  int* startpos = 0,
  int* endpos = 0)

Retreive the hyper link of a given frame.

Name Type Default Description
Return ItemRef/int   0 : No hyper link set

hyRef : The hyper link

UID of hyper link : The frame is linked but hyRef is 0
frameRef ItemRef 0 valid frame

0 : current script frame
hyRef ItemRef 0 allocated variable for the result or 0
startPos int* 0 (in/out) If the variable is not 0 and its value is >= 0, the function looks for a hyper link at this text position. If there is a hyper link, the variable will get the hyper links start position.
endPos int* 0 (in/out) end of text range to search for hyper links. Used only if startPos != 0 ist. On successful return, the variable contains the end position of the found hyper link.

Hyper links are not sorted by their text positions. So if you search inside a text range you can NOT be sure, that you retreive the first hyper link in the text (you even get ONE, not even the first!). See below for an example of how to walk through the hyper links of a text.

Create an URL hyper link for gFrame. If the frame is already linked, delete this link. Please note, the hyperlinks are invisible by default. The script therfor collect all UI settings of the old link and set the new one in the same way. Feel free to change the script, so that the very first link becomes visible too.

int main ()
{
    ItemRef		hy		= item::alloc ();
    ItemRef		src		= item::alloc ();
    int		visible	= 0;
    int		width		= 0;
    int		style		= 0;
    int		hilite		= 0;
    ItemRef		colref		= item::alloc ();
    int		result;
if (hyperlink::get_source (gFrame, src)) { visible = hyperlink::visible (src); width = hyperlink::borderwidth (src, &style); hilite = hyperlink::hilight (src); hyperlink::color (colref, src);
hyperlink::delete_ (src); } result = hyperlink::frame_create_urldest (   hy,   "not shared",   gFrame,   "http://www.priint-ii.com", 0); if (!result) return 0;
if (visible) hyperlink::appearance (hy, width, hilite, colref, 1, style);
return 0; }

Visit all hyper links of the text model.

int main ()
{
    ItemRef		hy		= item::alloc ();
    int			start		= 0;
    int			end		= -1;
    int			p		= 0;
while (1) { if (p >= frame::textlength (gFrame, 1)) break; start = p; end = p; if (hyperlink::get_source (gFrame, hy, &start, &end)) { wlog ("", "[%d, %d] : '%s'\n", start, end, hyperlink::name (hy)); p = end; } else p = p +1; }
return 0; }

3.4 R7021, 18. Nov. 2014
Parameter startPos and endPos since v3.4 R7022, 21. Nov. 2014

priint:comet InDesign® Plug-Ins

static int create_pagedest(
  ItemRef createdItem,
  char* name,
  ItemRef frameRef,
  int startpos,
  int endpos,
  char* destDoc,
  int pageNum,
  float zoomPercent = 0.0,
  int destType = 0,
  float zoomRLeft = 0.0,
  float zoomRTop = 0.0,
  float zoomRRight = 0.0,
  float zoomRBottom = 0.0)

Create a new hyper link from a text to a page. Links are shown in respect to the document settings for hyperlinks. Use hyperlink::appearance to change the visibilty of the link.

Name Type Default Description
Return int   0 or error code
createdItem ItemRef - Allocated result reference

0 : ignore result
otherwise : with item::alloced reference
name String or char* - Name of hyper link. If empty, up to 32 characters of the current text are used
frameRef ItemRef - text frame of hyper link source
0 : text frame of script
startpos int - start position inside the text. Text positions are relative to the textmodel, not to the scripts place holder.
endpos int - end position inside the text, must be greater than startPos. Text positions are relative to the textmodel, not to the scripts place holder.
destDoc String or char* - Destination document for the link.

0, "", or current document path: Refer to a page inside the SAME document

otherwise : Path to any existing InDesign® document. The document does not have to be opened. Please take care to refer to InDesign® documents here!
pageNum int - destination page (1-based)
After jumping to the destination, the destination page size can changed
zoomPercent float 0.0 zoom factor for destination page (1.0 means 100%). Allowed range is 0.05 - 40.0.

0.0 : do not change
destType int Fixed Page position according to the "Zoom" popup in the "Hyperlink" dialog of panel "Hyperlinks"

kBookmarkDestInheritZoom
kBookmarkDestFitWindow
kBookmarkDestFitWidth
kBookmarkDestFitHeight
kBookmarkDestFitView
kBookmarkDestFitVisible

You will get the "Fixed" setting by setting zoomPercent to 0.0.
With the following parameters you can change the destinations view rectangle. In our tests we could NOT create hyperlinks using this zoom box well. In addition, JavaScript and the used C++-API differs in this point. Anyway, we set the given values into the document without any warranty.
zoomRLeft float 0.0 left side of view rectangle
zoomRTop float 0.0 top side of view rectangle
zoomRRight float 0.0 right side of view rectangle
zoomRBottom float 0.0 bottom side of view rectangle

#include "internal/types.h"


priint:comet InDesign® Plug-Ins, comet_pdf

create_urldest, frame_create_pagedest, frame_create_urldest

static int create_urldest(
  ItemRef createdItem,
  char* name,
  ItemRef frameRef,
  int startpos,
  int endpos,
  char* url,
  int shared = 1)

Create a new hyper link from a text to an URL. Links are shown in respect to the document settings for hyperlinks. Use hyperlink::appearance to change the visibilty of the link.

Name Type Default Description
Return int   0 or error code
createdItem ItemRef - Allocated result reference

0 : ignore result
otherwise : with item::alloced reference
name String or char* - Name of hyper link. If empty, up to 32 characters of the current text are used
frameRef ItemRef - text frame of hyper link source
0 : text frame of script
startpos int - start position inside the text. Text positions are relative to the textmodel, not to the scripts place holder.
endpos int - end position inside the text, must be greater than startPos Text positions are relative to the textmodel, not to the scripts place holder.
url String or char* - Destination, valid URL. To create an email hyperlink, use urls of the following format mailto:name@...subject=... (wherby the subject part is optional)
shared int 1 since v3.3 R3820, 4. June 2013 Create a shared destination inside the document? For backward compatibility the default is set to 1 but we recommend setting it to 0.

0 : No
1 : Yes

#include "internal/text.h"
#include "internal/types.h"

The following script sets a email link to the current text selection.

#include "internal/types.h"
#include "internal/text.h"
int main() { int start, len; ItemRef hy = 0; char hname [512]; char hlink [512]; ItemRef colref = 0; int err = 0;
textmodel::selection (&start, &len); if (start == kEnd || len <= 0) { showerror ("No text selection."); return 0; }
strcpy(hname, "Paul"); strcpy(hlink, "mailto:paul@werk.ii.com?subject=cScript question");
hy = item::alloc (); err = hyperlink::create_urldest(   hy,   hname,   0, start, start + len,   hlink,   0); // do not create a shared destination inside the document if (err) { showerror ("Could NOT create hyperlink."); item::release(hy); return 0; }
colref = item::alloc (); color::define_rgb ("", 255, 128, 0, 0, colref); hyperlink::appearance (   hy,   1, // border width is of type int!   kOutlineHyperlinkHilight,   colref,   1, // visible   1); // dashed
item::release(hy); item::release(colref);
return 0; }

v1.4.1, R406, 4. Juli 2007
Parameter shared since v3.3 R3820, 4. Jun 2013

priint:comet InDesign® Plug-Ins, comet_pdf

create_pagedest, bookmark
create_pagedest, frame_create_pagedest, frame_create_urldest

static int frame_create_pagedest(
  ItemRef createdItem,
  char* name,
  ItemRef frameRef,
  char* destDoc,
  int pageNum,
  float zoomPercent = 0.0,
  int destType = 0,
  float zoomRLeft = 0.0,
  float zoomRTop = 0.0,
  float zoomRRight = 0.0,
  float zoomRBottom = 0.0)

Create a new hyper link from a frame to a page. Links are shown in respect to the document settings for hyperlinks. Use hyperlink::appearance to change the visibilty of the link.

Name Type Default Description
Return int   0 or error code
createdItem ItemRef - Allocated result reference

0 : ignore result
otherwise : with item::alloced reference
name String or char* - Name of hyper link. If empty, up to 32 characters of the current text are used
frameRef ItemRef - text frame of hyper link source
destDoc String or char* - Destination document for the link.

0, "", or current document path: Refer to a page inside the SAME document

otherwise : Path to any existing InDesign® document. The document does not have to be opened. Please take care to refer to InDesign® documents here!
pageNum int - destination page (1-based)
After jumping to the destination, the destination page size can changed
zoomPercent float 0.0 zoom factor for destination page (1.0 means 100%). Allowed range is 0.05 - 40.0.

0.0 : do not change
destType int Fixed Page position according to the "Zoom" popup in the "Hyperlink" dialog of panel "Hyperlinks"

kBookmarkDestInheritZoom
kBookmarkDestFitWindow
kBookmarkDestFitWidth
kBookmarkDestFitHeight
kBookmarkDestFitView
kBookmarkDestFitVisible

You will get the "Fixed" setting by setting zoomPercent to 0.0.
With the following paramters you can change the destinations view rectangle. In our tests we could NOT create hyperlinks using this zoom box well. In addition, JavaScript and the used C++-API differs in this point. Anyway, we set the given values into the document without any warranty.
zoomRLeft float 0.0 left side of view rectangle
zoomRTop float 0.0 top side of view rectangle
zoomRRight float 0.0 right side of view rectangle
zoomRBottom float 0.0 bottom side of view rectangle

#include "internal/text.h"
#include "internal/types.h"

v1.4.1, R446, 27. Aug 2007

priint:comet InDesign® Plug-Ins, comet_pdf

frame_create_urldest, create_pagedest, create_urldest

static int frame_create_urldest(
  ItemRef createdItem,
  char* name,
  ItemRef frameRef,
  char* url,
  int shared = 1)

Create a new hyper link from a frame to an URL. Links are shown in respect to the document settings for hyperlinks. Use hyperlink::appearance to change the visibilty of the link.

Name Type Default Description
Return int   0 or error code
createdItem ItemRef - Allocated result reference

0 : ignore result
otherwise : with item::alloced reference
name String or char* - Name of hyper link. If empty, the default name "Hyperlink" is used.
0 : text frame of script
url String or char* - Destination, valid URL
shared int 1 Is the hyper link shared or not?
0 : not shared (only valid inside this document)
1 : Yes, shared

v1.4.1, R446, 27. Aug 2007

priint:comet InDesign® Plug-Ins, comet_pdf

create_pagedest, bookmark, frame_create_pagedest, create_pagedest, create_urldest

static char* name(ItemRef hy)

Find the hyperlinks name. Further calls to the function will override the result string!

Name Type Default Description
Return char*   Name of hyperlink or ""

The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. Learn more about functions returning r/o char* values.

hy ItemRef - Valid hyperlink reference

Dump the hyperlinks name to the default log file.

wlog ("", "%s\n", hyperlink::name (hy));

Keep the functions result for later usages:

char		hyName[64];
strcpy (hyName, hyperlink::name (hy));


priint:comet InDesign® Plug-Ins

setname

static ItemRef destination(ItemRef dest, ItemRef hy)

Find a hyperlinks destination.

Name Type Default Description
Return ItemRef   dest in returned on successs, otherwise 0.
hy ItemRef - Valid hyperlink reference
dest ItemRef - With item::alloc allocated variable for the destination reference.

Create a bookmark for the hyperlinks destination.

int main ()
{
    ItemRef	hy	= item::alloc ();
    ItemRef	dest	= item::alloc ();
    ItemRef	bk	= item::alloc ();
hyperlink::create_pagedest (hy, 0, gFrame, 20, 30, "", 5); bookmark::create2 (   bk,   0,   hyperlink::destination (dest, hy),   hyperlink::name (hy),   "");
return 0; }


priint:comet InDesign® Plug-Ins

static int visible(ItemRef hy)

Hyperlink visible or not?

Name Type Default Description
Return int   0 : unvisible
1 : visible
hy ItemRef - Valid hyperlink reference


priint:comet InDesign® Plug-Ins

show, hide

static int hilight(ItemRef hy)

Hilite state of the hyperlink.

Attention

The hilight state is not used in InDesign® , it only matters when the file is exported to PDF. To change the visibilty of a hyperlink, please use show and hide.

Name Type Default Description
Return int   kNoHyperlinkHilight
kInvertHyperlinkHilight
kInsetHyperlinkHilight
kOutlineHyperlinkHilight
hy ItemRef - Valid hyperlink reference

#include "internal/text.h"
#include "internal/types.h"


priint:comet InDesign® Plug-Ins

appearance, show, hide

static int borderwidth(ItemRef hy)

Borderwidth of an hyperlink..

Name Type Default Description
Return int   Get the thickness of the border of the hyperlink

1 : thin
2 : medium
3 : thick
hy ItemRef - Valid hyperlink reference


priint:comet InDesign® Plug-Ins

appearance

static ItemRef color(ItemRef colRef, ItemRef hy)

Get the color of the hyperlink border.

Name Type Default Description
Return ItemRef   Returning colRef in case of success, otherwise 0
hy ItemRef - Valid hyperlink reference


priint:comet InDesign® Plug-Ins

appearance

static ItemRef setname(ItemRef hy, char* newname)

Change the name of a hyperlink.

Name Type Default Description
Return int   0 or error code.
hy ItemRef - Valid hyperlink reference
newname String or char* - New name. The name must not by empty!


priint:comet InDesign® Plug-Ins

name

static ItemRef show(ItemRef hy)

Show the hyperlinks border.

Name Type Default Description
Return int   0 or error code.
hy ItemRef - Valid hyperlink reference


priint:comet InDesign® Plug-Ins

visible, hide

static ItemRef hide(ItemRef hy)

Hide the hyperlinks border.

Name Type Default Description
Return int   0 or error code.
hy ItemRef - Valid hyperlink reference


priint:comet InDesign® Plug-Ins

visible, show

static ItemRef appearance(
  ItemRef hy,
  int borderwidth,
  int hstate,
  ItemRef colRef = 0,
  int visible = -1,
  int dashed = -1)

Change the appearance of a hylerlink.

Name Type Default Description
Return int   0 or error code.
hy ItemRef - Valid hyperlink reference
borderwidth int - thickness of the border of the hyperlink

-1 : Leave untouched
1 : thin
2 : medium
3 : thick
hstate int - Choose on of the following values, it only matters when the file is exported to PDF.

-1 : Leave untouched
kNoHyperlinkHilight
kInvertHyperlinkHilight
kInsetHyperlinkHilight
kOutlineHyperlinkHilight

The value kNoHyperlinkHilight does not change the borders visibility, use the parameter visible to change the visibility..
colRef ItemRef 0 border color
0 : Farbe unverändert lassen
visible int -1 Visible or not?

-1 : Leave untouched
1 : Visible
0 : Unvisible
dashed int -1 Dashed border?

-1 : Leave untouched
0 : No, solid frame
1 : Yes. dashed frame

#include "internal/types.h"

Set an orage border.

int main ()
{
    ItemRef	hy	= item::alloc ();
    ItemRef	colid	= item::alloc ();
hyperlink::create_pagedest (hy, 0, gFrame, 20, 30, "", 5);
color::define_rgb ("", 255, 128, 0, 0, colid); hyperlink::appearance (   hy,   hyperlink::borderwidth (hy),   hyperlink::hilight (hy),   colid,   1);
return 0; }

Parameter visible und dashed seit Version 1.4.2 R 520, 7. Dez. 2007

priint:comet InDesign® Plug-Ins, comet_pdf

borderwidth, hilight, color, show, hide

static ItemRef goto_source(ItemRef hy)

Jump to the hyperlinks source.

Name Type Default Description
Return int   0 or error code.
hy ItemRef - Valid hyperlink reference


priint:comet InDesign® Plug-Ins

static ItemRef goto_destination(ItemRef hy)

Jump to the hyperlinks destination.

Name Type Default Description
Return int   0 or error code.
hy ItemRef - Valid hyperlink reference


priint:comet InDesign® Plug-Ins

static int find(
  LinkList resultList,
  ItemRef docRef,
  char* crossRefName,
  long classid,
  long id,
  long id2 = 0,
  long id3 = 0,
  char* sid = 0,
  int findInBook = 1,
  int inclSection = 1,
  int intStyle = 1,
  int numType = 0,
  int abbrev = 1,
  int calcTextPos = 0)

Find all cross reference destinations of a given name and a given Comet ID. Cross reference destinations are created using textmodel::insert_crossref, with the <w2cross> tag or using the product pool panel submenu Insert Cross Reference. A detailed description about Comet cross references is found here.

While creating cross reference destinations, InDesign® takes care of unique names by appending a counter to the names. This is the reason why you may have more than one cross reference destination with the same name and ID in the document. The find function ignores this counter and will find all cross reference destinations beginning with the given name and/or Comet ID string containing of classid, ID, ID2, ID3 and StringID of the given Comet-ID.

Cross reference destinations in overset will not be found!

You may wish to search all documents of the book containing the given document. In this case all documents of the book will be opened and closed in the background automatically. The Comet document watch mechanism is turned off in this situation.

After successfully searching the destinations, all results are collected and sorted by their page numbers in a LinkList. To get the appropriate page names you can give some information about the page name format to the function (inclSection, intStyle, numType, numType):

ab v3.3 R3116, 13.08.2012 If classid is 0, hyperlink and/or text anchor names are not appended by the Comet object ID. Use sid to check the beginning of the anchor names.

ab v3.3 R3116, 13.08.2012 By set crossRefName to "ANCHORS#" (exactly this!) you can search for text anchors instead of hyperlinks.

Name Type Default Description
Return int   0 or error code.
resultList LinkList - Allocated result list. The list will be cleared at thne beginn of the search. You can walk through this list using the itemlist functions. Use the functions of the module link::crossref to get information about the cross reference destinations.
docRef ItemRef - Document to search in
0 : current front document
crossRefName String oder char* - Name of the destination to search for. Find all destinations beginning with the given name. May be 0 or empty.

"ANCHORS#" : Search for text anchors instead of hyperlinks. To filter only anchors this names beginning of "what ever" set classid to 0 and sid to "what ever".
classid int 0 class id of the following Comet object

0 : Do not append the Comet object to names of hyperlinks and/or anchors
id, id2, id3 int 0, 0, 0 Comet-Object-ID
sid String oder char* 0 Comet-StringID.

classid 0 : Look for hyperlink/anchor names beginning with sid only
findInBook int 0 Search in all documents of the documents book too?
inclSection, intStyle, numType, abbrev int 1, 1, 0, 1 Document page name formatting hints, see page::get_str
calcTextPos int 0 Calculation of xy text coordinates is expensive. Turn on only if you need it!

0 : Not neeed
1 : Calculate coordinates (in points relative to the text frame). Y is the baseline position.

#include "internal/types.h"
int main ()
{
    LinkList	lks	= linklist::alloc ();
    int		res	= hyperlink::find (lks, 0, "", 9, 4, 2008, "Matthias Seidel", 1, 1, 1, 0, 0);
    Link		lk;
wlog ("", "Crossrefs in document\n"); for (lk = linklist::first (lks); lk; lk = linklist::next (lks)) { wlog ("", "%s --> '%s'\n",   link::crossref::name (lk), link::crossref::destination (lk)); wlog ("", "\tPage %d (%d in '%s')\n",   link::crossref::page (lk, 0), link::crossref::page (lk, 1), link::crossref::document (lk, 1)); wlog ("", "\tPagename %s (%s)\n",   link::crossref::pagename (lk, 0), link::crossref::pagename (lk, 1)); } linklist::release (lks); return 0; }

Create a button for every hyperlink pointing to an text anchor. Clicking the button will jump to the same text anchor. The (long) function wcross is not necessary here but may serve as an example how to retreive the link data.

#include "internal/text.h"
#include "internal/types.h"
int wcross (Link lk) { int hasSource = item::defined (link::crossref::hyperlink_ref (lk)); int hasDest = item::defined (link::crossref::anchor_ref (lk)); int type = link::crossref::type (lk);
// headline if (hasSource && hasDest) { wlog ("", "Hyperlink '%s' --> '%s'\n",   link::crossref::name (lk),   link::crossref::destination (lk)); } else if (hasDest) { wlog ("", "Destination '%s'\n",   link::crossref::destination (lk)); } else { wlog ("", "Wrong cross reference %d --> %d\n",   item::getint (link::crossref::hyperlink_ref (lk)),   item::getint (link::crossref::anchor_ref (lk))); }
// hyperlink data if (hasSource) { wlog ("", "\t=== Source ===\n"); wlog ("", "\tFrame %d, page %d\n",   item::getint (link::crossref::src_frame (lk)),   page::get (link::crossref::src_frame (lk))); wlog ("", "\tText %d-%d\n",   link::crossref::src_textpos (lk),   link::crossref::src_textpos (lk)+link::crossref::src_textlen (lk)); }
// anchor data if (hasDest) { if (type == 0) { wlog ("", "\t=== Text anchor ===\n"); wlog ("", "\tPage %d (%d in '%s')\n",   link::crossref::page (lk, 0),   link::crossref::page (lk, 1),   link::crossref::document (lk, 1)); wlog ("", "\tPage name %s (%s)\n",   link::crossref::pagename (lk, 0),   link::crossref::pagename (lk, 1)); wlog ("", "\tFrame %d\n",   item::getint (link::crossref::frame (lk))); wlog ("", "\tText position %d\n",   link::crossref::pos (lk)); wlog ("", "\tCoordinates [%f x %f]\n",   link::crossref::x (lk),   link::crossref::y (lk)); wlog ("", "\tBbox [%f, %f] - [%f, %f]\n",   link::crossref::left (lk),   link::crossref::top (lk),   link::crossref::right (lk),   link::crossref::bottom (lk)); } else if (type == 1) { wlog ("", "\t=== Page ===\n"); wlog ("", "\tPage %d (%d in '%s')\n",   link::crossref::page (lk, 0),   link::crossref::page (lk, 1),   link::crossref::document (lk, 1)); wlog ("", "\tPage name %s (%s)\n",   link::crossref::pagename (lk, 0),   link::crossref::pagename (lk, 1)); } else { wlog ("", "\t=== URL ===\n"); wlog ("", "\t'%s'\n", link::crossref::info (lk)); }
wlog ("", "\n"); }
return 0; }
int main () { LinkList lks = linklist::alloc (); int res = 0; Link lk; ItemRef fr; ItemRef btn = item::alloc (); ItemRef action = item::alloc (); float l, t, r, b; ItemList buttons = itemlist::alloc (); ItemList states = itemlist::alloc (); float offset; int i; char path [2000];
res = hyperlink::find (   lks, // result list   0, // front document   "", // Hyperlink names   0, // classID (ignore Comet IDs)   0, 0, 0, // ID, ID2, ID3 (ignored if classID == 0)   "", // StringID or anchor name   0, // find in book   1, 1, 0, 1, // page name formatting   1); // Calculate text pos of anchor if (res) { wlog ("", "# Error %d (%s) while retreiving cross references\n",   res,   serror (res)); return 0; }
document::path (path); wlog ("", "Crossrefs in document '%s'\n", path);
for (lk = linklist::first (lks); lk; lk = linklist::next (lks)) { wcross (lk);
if (0 && link::crossref::type (lk) == 0 && item::defined (link::crossref::hyperlink_ref (lk))) { // One text model can contain N hyperlinks offset = 10.0; for (i = 0; i < itemlist::length (buttons); i++) { itemlist::get (buttons, fr, i); if (item::getint (fr) == item::getint (link::crossref::src_frame (lk))) { offset += 52.0; } }
// Create a simple text frame fr = link::crossref::src_frame (lk); frame::bbox (fr, &l, &t, &r, &b); frame::create2 (btn, kRectangle, l, b+offset, l+150.0, b+offset+42.0, page::get (fr)); frame::append (btn, ">> "); frame::append (btn, link::crossref::destination (lk)); itemlist::append (buttons, fr);
// Make *btn* a button itemlist::clear (states); itemlist::append (states, btn); itemlist::create_multistate (btn, states, 1);
// and finally a the action behavior::add_action (btn, 2, 1, action); behavior::change_action_data (btn, action, "", item::getint (link::crossref::anchor_ref (lk)), 2); } }
linklist::release (lks); return 0; }

Version 2.1 R668, 9. April 2008

priint:comet InDesign® Plug-Ins

find1, linklist, link, page::get_str

static char* find1(
  int* res,
  char* property,
  int nth,
  ItemRef docRef,
  char* crossRefName,
  long classid,
  long id,
  long id2 = 0,
  long id3 = 0,
  char* sid = 0,
  int findInBook = 1,
  int inclSection = 1,
  int intStyle = 1,
  int numType = 0,
  int abbrev = 1)

Find on property of one cross reference destination with the given name and Comet-ID. For all other information see find.

Name Type Default Description
Return char*   Get the retreived property as char* string. "" in case of any errors.

The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. Learn more about functions returning r/o char* values.

res int*|float*|String or char* - Pointer to hold the property data. May be 0. If not null, the data type must correspond to the given property (see below).
property String or char* - Property name as string

Property Type Description
Document char* Name of the document
DocumentFolder Folder of the document
DocumentPath Full path of the document
Page int 1-based book relative page number
DocumentPage 1-based document relative page number
PageName char* book dependent page name
DocumentPageName documents page name dependent on (inclSection, intStyle, numType, numType)
Name Complet name of reference definition
Destination Complete Comet-ID
FrameLeft float Text frame coordinates in points
FrameTop
FrameRight
FrameBottom
TextPosX Text coordinates in points releativ to the text frame (y is the baseline position)
TextPosY
TextPos int Text position of the reference anchor
nth int - Number of found reference

0 : First
-1 : Last
otherwise : This (0-based). If link doesn't exists, the function will return "" (error).
docRef ItemRef - Document to search in
0 : current front document
crossRefName String or char* - Name of the destination to search for. Find all destinations beginning with the given name. May be 0 or empty.
classid int 0 class id of the following Comet object
id, id2, id3 int 0, 0, 0 Comet-Object-ID
sid String or char* 0 Comet-StringID.
findInBook int 1 Search in all documents of the documents book too?
inclSection, intStyle, numType, abbrev int 1, 1, 0, 1 Document page name formatting hints, see page::get_str

int main ()
{
    int 		i;
    float		f;
    char		s[256];
wlog ("", "\n"); wlog ("", "Document %s\n", hyperlink::find1 (s, "Document",   0, 0, "", 3, 9, 4, 2008, "Matthias Seidel", 1, 1, 1, 1, 1)); wlog ("", "Docfolder %s\n", hyperlink::find1 (s, "Docfolder",   0, 0, "", 3, 9, 4, 2008, "Matthias Seidel", 1, 1, 1, 1, 1)); wlog ("", "Docpath %s\n", hyperlink::find1 (s, "Docpath",   0, 0, "", 3, 9, 4, 2008, "Matthias Seidel", 1, 1, 1, 1, 1)); wlog ("", "Page %s\n", hyperlink::find1 (&i, "Page",   0, 0, "", 3, 9, 4, 2008, "Matthias Seidel", 1, 1, 1, 1, 1)); wlog ("", "X %s\n", hyperlink::find1 (&f, "TextPosX",   0, 0, "", 3, 9, 4, 2008, "Matthias Seidel", 1, 1, 1, 1, 1)); wlog ("", "Y %s\n", hyperlink::find1 (&f, "TextPosY",   0, 0, "", 3, 9, 4, 2008, "Matthias Seidel", 1, 1, 1, 1, 1)); return 0; }

Version 2.1 R668, 9. April 2008

priint:comet InDesign® Plug-Ins

find1, linklist, link, page::get_str

static int delete_all(
  ItemRef docRef = 0,
  int direct = 0,
  int saveSteps = 0)

Remove all hyperlinks from a document. Documents older than Comet 2.1 R 704, 8. Mai 2008 can contain a long list of unused hyperlinks. If you try to remove this hyperlinks using the Hyperlink panel, InDesign® may crash. In this case, try this function. If you use direct = 1, all hyperlinks remove directly from the document structure without any tests or updates. The document is saved and reloaded in this case automatically. (Be sure to save converted new documents before deleting hyperlinks!)

Name Type Default Description
Return int   0 or errr code.
docRef ItemRef 0 Document to work on

0 : Current front document
direct int 0 see above
saveSteps int 0 (direct = 0 only) : save the document after every step

Version 2.1 R 704, 8. Mai 2008

priint:comet InDesign® Plug-Ins

static int delete_(ItemRef hl)

Delete a hyperlink or a hyperlink anchors. Used anchors are unable to delete from the document.

Name Type Default Description
Return int   0 or errr code.
hl ItemRef Valid hyperlonk or hyperlink anchor  

int main ()
{
    LinkList	lks	= linklist::alloc ();
    int		res	= hyperlink::find (lks, 0, "", 0, 9, 4, 2008, "Matthias Seidel", 1, 1, 1, 0, 0);
    Link		lk;
for (lk = linklist::first (lks); lk; lk = linklist::next (lks)) { hyperlink::delete_ (link::crossref::hyperlink_ref (lk)); } linklist::release (lks); return 0; }

v3.3 R3238, 25.10.2012

priint:comet InDesign® Plug-Ins

hyperlink::find

static int get_next_unique_key(ItemRef docRef = 0)

Get next available unique hyperlink key of a document. The function is useful if you want to create hyperlinks using TaggedText. For more information see here.

Name Type Default Description
Return int   Next available unique hyperlink key

-1 : Error
docRef ItemRef 0 Document to search for the key
0 : current documenz

v4.1 R22201, 12. Apr 2018

priint:comet InDesign® Plug-Ins

hyperlink::find, textmodel::insert

This class has no child classes.

The example demostrates the usage of the hyperlink methods. Be sure to use the hyper links destination if you link the hyper link against a bookmark - not the hyper link itself.

int main ()
{
    ItemRef	hy	= item::alloc ();
    ItemRef	dest	= item::alloc ();
    ItemRef	colid	= item::alloc ();
    ItemRef	bk	= item::alloc ();
hyperlink::create_pagedest (hy, 0, gFrame, 20, 30, "", 5); wlog ("", "name : %s\n", hyperlink::name (hy)); wlog ("", "visible : %d\n", hyperlink::visible (hy)); wlog ("", "border : %d\n", hyperlink::borderwidth (hy)); wlog ("", "hstate : %d\n", hyperlink::hilight (hy));
color::define_rgb ("", 255, 128, 0, 0, colid);
hyperlink::appearance (hy, 5, 1, colid); wlog ("", "border : %d\n", hyperlink::borderwidth (hy)); wlog ("", "hstate : %d\n", hyperlink::hilight (hy));
// Bookmark for the hyper link bookmark::create2 (   bk,   0,   hyperlink::destination (dest, hy),   hyperlink::name (hy),   "");
return 0; }

Author
Paul Seidel
Version
09.11.2021, 08:27 Uhr
Since
Plugin Version 1.3.4
See Also
bookmark

Alphabetic index HTML hierarchy of classes or Java