One way to achieve this is to first add a link using the AddLinkToFile function, then use the GetAnnotActionID and GetActionDest functions to obtain a DestID. Then the SetDestProperties function can be used to change the link annotation to a different type.
It's not possible to link to a particular area and set the zoom too. But you can link to an area using the FitR destination type, and you can link to a left/top/zoom using the XYZ destination type.
Here's an example:
string SourceFile = "source.pdf"; string TargetFile = "target.pdf"; int DestPage = 2; int DestZoom = 500; double DestBoxLeft = 300; double DestBoxTop = 500; double DestBoxWidth = 200; double DestBoxHeight = 150;
// Create a target document containing two pages QP.DrawText(100, 700, "Target Page 1"); QP.NewPage(); QP.DrawText(100, 700, "Target Page 2");
// On the second page, draw a box and add some text to // the top left corner of the box QP.DrawBox(DestBoxLeft, DestBoxTop, DestBoxWidth, DestBoxHeight, 0); QP.DrawText(DestBoxLeft + 5, 500 - QP.GetTextHeight() - 5, "Box is here");
// Save the target file QP.SaveToFile(TargetFile);
// Create a source document QP.NewDocument(); QP.SetTextAlign(1);
// Draw a label for the first hotspot and add a link to any position // on the target page (123 is used here, it will be discarded later) QP.DrawTextBox(100, 700, 100, 20, "Open Target (FitR)", 0); QP.AddLinkToFile(100, 700, 100, 20, TargetFile, DestPage, 123, 1, 1); // Get the new annotation's action, and the destination of that action, // then use the DestID to change the destination properties to "FitR", // supplying the Left, Top, Right and Bottom values. Zoom is set to // zero, it will be ignored for "FitR" int ActionID = QP.GetAnnotActionID(QP.AnnotationCount()); int DestID = QP.GetActionDest(ActionID); int DestType = 5; // FitR QP.SetDestProperties(DestID, 0, DestType, DestBoxLeft, DestBoxTop, DestBoxLeft + DestBoxWidth, DestBoxTop - DestBoxHeight);
// Draw a label for the second hotspot and add a link to any position // on the target page (123 is used here, it will be discarded later) QP.DrawTextBox(100, 650, 100, 20, "Open Target (XYZ)", 0); QP.AddLinkToFile(100, 650, 100, 20, TargetFile, DestPage, 123, 1, 1);
// Get the DestID as before, but use XYZ for this one. The // Right and Bottom parameters are ignored ActionID = QP.GetAnnotActionID(QP.AnnotationCount()); DestID = QP.GetActionDest(ActionID); DestType = 1; // XYZ QP.SetDestProperties(DestID, DestZoom, DestType, DestBoxLeft, DestBoxTop, 0, 0);
QP.SaveToFile(SourceFile);
|