Add a link item to a document to jump to another

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Add a link item to a document to jump to another

Post by lidds »

I have a document loaded and I give the user the option to create a duplicate copy of the document and then crop it, which all works fine. These two document are then linked within my database and this means that they are always load together in the viewer. This procedure is able to be repeated so, basically the user could duplicate the original document any number of times and apply different crop regions.

What I want to be able to do is place an element (maybe a link annot) that when the user click it, it jumps to a document that is already loaded.

I have tried to illustrate this below:
DocLink.png
Obviously I am aware that I will have to intercept the event, but I am wondering of the best way to achieve this?

One important thing to note is that this CANNOT be saved to the PDF but need to be placed as an Annotation element that can be exported to an annotation export file.

Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Add a link item to a document to jump to another

Post by Sasha - Tracker Dev Team »

Hello Simon,

To see the sample on how to add link annotations, get the CoreAPIDemo project from here:
https://github.com/tracker-software/PDFCoreSDKExamples
There you can see the sample "7.2. Add Link annotations".
You will have to use the GoToR action to go to another document:
https://sdkhelp.pdf-xchange.com/vi ... t_AddGotoR

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add a link item to a document to jump to another

Post by lidds »

Alex,

Thanks for the advise. I'm still currently working on this, but am using the following code to add the link. The link works fine, however it does not appear as an annotation element in the comments pane and therefore I cannot export this to an annotation file.

Am I doing something wrong?

Code: Select all

		Dim firstPage As IPXC_Page = Me.docPreview.Doc.CoreDoc.Pages(0)
        Dim rcPage As PXC_Rect = firstPage.Box(PXC_BoxType.PBox_PageBox)
        Dim pxsInst As IPXS_Inst = DirectCast(Me.docPreview.Inst.GetExtension("PXS"), PDFXEdit.IPXS_Inst)
        Dim auxInst As IAUX_Inst = DirectCast(Me.docPreview.Inst.GetExtension("AUX"), PDFXEdit.IAUX_Inst)

        Dim nText As UInteger = pxsInst.StrToAtom("Link")
        Dim nCX As Double = ((rcPage.right - rcPage.left) / 2)
        Dim nCY As Double = ((rcPage.top - rcPage.bottom) / 2)
        Dim rcOut As PXC_Rect = New PXC_Rect
        rcOut.left = (nCX - 200)
        rcOut.bottom = (nCY + 250)
        rcOut.right = (nCX + 150)
        rcOut.top = (nCY + 300)

        Dim annot As IPXC_Annotation = firstPage.InsertNewAnnot(nText, rcOut, 0)
        Dim aData As IPXC_AnnotData_Link = CType(annot.Data, IPXC_AnnotData_Link)

        Dim AL As IPXC_ActionsList = Me.docPreview.Doc.CoreDoc.CreateActionsList
        Dim dest As PXC_Destination = New PXC_Destination
        dest.nPageNum = (firstPage.Number + 1)
        dest.nType = PXC_DestType.Dest_XYZ
        dest.nNullFlags = 15
        AL = Me.docPreview.Doc.CoreDoc.CreateActionsList
        AL.AddGoto(dest)
        annot.Actions(PXC_TriggerType.Trigger_Up) = AL
        annot.Data = aData
Link.png
Thanks

Simon
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add a link item to a document to jump to another

Post by lidds »

Actually thinking about this a little more, this link item could work. However is there a way to add some text to the link e.g. "Jump to document"

Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Add a link item to a document to jump to another

Post by Sasha - Tracker Dev Team »

Hello Simon,

There is no link text whatsoever. The link annotation itself is only a clickable area on the page that executes the Actions list provided. Also, it does not appear in the Comments pane. To add some text to the link, you will have to add it as a page's content and then add the link itself on top of it.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add a link item to a document to jump to another

Post by lidds »

Alex,

I am using the following code to add a link to the document, which works great. Apart from the fact that I am assigning a grey dash border to the link boundary, however this border does not display unless I click the link. It is almost like the page needs to do a refresh or something?

Code: Select all

Dim firstPage As IPXC_Page = Me.docPreview.Doc.CoreDoc.Pages(0)
        Dim rcPage As PXC_Rect = firstPage.Box(PXC_BoxType.PBox_PageBox)

        Dim pxsInst As IPXS_Inst = DirectCast(Me.docPreview.Inst.GetExtension("PXS"), PDFXEdit.IPXS_Inst)
        Dim auxInst As IAUX_Inst = DirectCast(Me.docPreview.Inst.GetExtension("AUX"), PDFXEdit.IAUX_Inst)

        Dim nText As UInteger = pxsInst.StrToAtom("Link")
        Dim nCX As Double = ((rcPage.right - rcPage.left) / 2)
        Dim nCY As Double = ((rcPage.top - rcPage.bottom) / 2)
        Dim rcOut As PXC_Rect = New PXC_Rect
        rcOut.left = (nCX - 200)
        rcOut.bottom = (nCY + 250)
        rcOut.right = (nCX + 150)
        rcOut.top = (nCY + 300)

        Dim annot As IPXC_Annotation = firstPage.InsertNewAnnot(nText, rcOut, 0)
        Dim aData As IPXC_AnnotData_Link = CType(annot.Data, IPXC_AnnotData_Link)
        Dim AL As IPXC_ActionsList = Me.docPreview.Doc.CoreDoc.CreateActionsList

        Dim color As PDFXEdit.IColor = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB)
        color.Value = "rgbd(128,128,128)"
        aData.Color = color

        Dim border = New PXC_AnnotBorder
        border.nStyle = PXC_AnnotBorderStyle.ABS_Dashed
        border.nWidth = 4.0!
        border.DashArray = New Single((10) - 1) {}
        border.DashArray(1) = 16.0!
        border.DashArray(0) = 16.0!
        border.nDashCount = 2
        aData.Border = border

        Dim dest As PXC_Destination = New PXC_Destination
        dest.nPageNum = (firstPage.Number + 1)
        dest.nType = PXC_DestType.Dest_XYZ
        dest.nNullFlags = 15
        AL = Me.docPreview.Doc.CoreDoc.CreateActionsList
        AL.AddGoto(dest)
        annot.Actions(PXC_TriggerType.Trigger_Up) = AL
        annot.Data = aData
Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Add a link item to a document to jump to another

Post by Sasha - Tracker Dev Team »

Hello Simon,

You have added the links on the Core level - you will have to use the addAnnots operation to send all of the needed events for the Editor level to refresh itself.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add a link item to a document to jump to another

Post by lidds »

Alex,

You are right, sorry been one of those long days that I should have known this.

I am however still struggling with working out the code to make me jump to the document. I have added a screen image to hopefully better explain.

Thanks

Simon
LinkJumpCode.png
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add a link item to a document to jump to another

Post by lidds »

Hi Alex,

Sorry to hassle you but this is the last thing I need to do to finish this, is there any chance you could assists.

Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Add a link item to a document to jump to another

Post by Sasha - Tracker Dev Team »

Hello Simon,

The behavior is the same as of the Acrobat. You can tweak this one though, because you do use the Editor SDK.
First you will have to intercept the https://sdkhelp.pdf-xchange.com/vi ... eRunAction
Then, when you get to the IPXC_Action interface (like the description advises), you can check whether it's a goto action type. If so, cast it to the IPXC_Action_Goto interface and get the Target property (IPXC_FileSpec). There, you can get the path of the document that will be opened by using the get_WinPath or get_DIPath properties.
After you have the path, you will have to check whether the document is already open by using IPXV_Inst::FindDocBySrcFileName2 or FindDocBySrcFileName if you have the IAFS_Name.
If it is opened already, use the IPXC_Action_Goto destination information to go to the needed page and break the e_document_beforeRunAction event (as it's written in the description). Do not forget to handle the named destinations if the DestName property is specified (you can see how to get to them from the CoreAPIDemo application).
If it's not opened, then let the event continue and the document will be opened as needed.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add a link item to a document to jump to another

Post by lidds »

Alex,

Thank you for your help. It turns out you can do the following code, without having to intercept any events and the PDF API will switch automatically to that document if it is loaded in the viewer.

Code: Select all

            Dim dest As PXC_Destination = New PXC_Destination
            dest.nType = PXC_DestType.Dest_Fit

            Dim AL As IPXC_ActionsList = Me.docPreview.Doc.CoreDoc.CreateActionsList
            AL = Me.docPreview.Doc.CoreDoc.CreateActionsList
            Dim gotoR As IPXC_Action = AL.AddGotoR(canvasOID & ".pdf", dest)
            annot.Actions(PXC_TriggerType.Trigger_Up) = AL
Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Add a link item to a document to jump to another

Post by Sasha - Tracker Dev Team »

Hello Simon,

That's great if that worked for you.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply