Hyperlinks. Sometimes you may wish to insert annotations such as links to an external web page specified using a URI or URL. The AddHtml method allows you to specify links but only on text. If, for example, you want to insert a link over content such as an image you need to add it separately. You can do this using code of the following form.
static int AddLinkToUri(Doc doc, XRect rect, string uri) {
int id = doc.AddObject("<< /Type /Annot /Subtype /Link /A << /Type /Action /S /URI /URI () >> /Border [0 0 0] >>");
doc.SetInfo(doc.Page, "/Annots*[]:Ref", id);
doc.SetInfo(id, "/Rect:Rect", doc.Rect.String);
doc.SetInfo(id, "/A/URI:Text", uri);
return id;
}
If you wish to link to a particular page specified by page ID you can use code of the following form.
static int AddLinkToPage(Doc doc, XRect rect, int pageID) {
int id = doc.AddObject("<< /Type /Annot /Subtype /Link /Border [0 0 0] /A << /Type /Action /S /GoTo /D [ /XYZ null null 0] >> >>");
doc.SetInfo(doc.Page, "/Annots*[]:Ref", id);
doc.SetInfo(id, "/Rect:Rect", doc.Rect.String);
doc.SetInfo(id, "/A/D[0]:Ref", pageID.ToString());
return id;
}
|