Print Page | Close Window

LinkToFile Destination ID / Zoom

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2143
Printed Date: 14 Aug 25 at 6:01AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: LinkToFile Destination ID / Zoom
Posted By: samuelms
Subject: LinkToFile Destination ID / Zoom
Date Posted: 10 Feb 12 at 4:34PM
Is there an API available to link to a local file and set a destination id to load within that file?

Here is the API I'm aware of to link to a page within another file:
http://www.quickpdflibrary.com/help/quickpdf/AddLinkToFile.php - http://www.quickpdflibrary.com/help/quickpdf/AddLinkToFile.php

However, I'd like to:
    1.) Link to a destination id 
    OR 
    2.) Link to a page at a specific X,Y location with a specific bounding box Width, Height with a specific zoom

At the moment I do not believe this is possible.  :(  Is this something we can expect soon (really soon?)

Also, this may be possible using javascript :: see  http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf - http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf  page 133 openDoc method's cDest argument.  Note that the cDest argument says  "(optional, Acrobat 8.0)".  So..  I'm not sure how many pdf viewers 1.) support javascript and 2.) would support that method argument.

I may try the javascript route...  but I'd REALLY love to find a non-javascript route as I don't know that javascript has wide support.  See  http://stackoverflow.com/questions/9219807/using-javascript-inside-a-pdf - http://stackoverflow.com/questions/9219807/using-javascript-inside-a-pdf



Replies:
Posted By: kevindebenu
Date Posted: 17 Apr 12 at 8:01AM
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);



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk