How to update Bookmarks?

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, 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
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

How to update Bookmarks?

Post by mmasood »

Hi,

I am using Core Api. I am resizing pdf files which I am able to do successfully. The logic that I have been using is to create a new page of the desired size and move over and scale the content of the old page and then delete the old page.

The problem that I am facing is that the output document has the correct page sizes but the bookmarks are all broken. I am copying over the Annotations so the bookmarks are being displayed in the output file but the links are all broken. My question is how do I make sure that the bookmarks remain intact during this process?

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

You will have to run through all of Actions Lists that may contain GoTo Actions (document, pages, links, bookmarks) and modify them by yourself, also do not forget about named destinations, and modify the destination of the GoTo Action if it goes to the modified page. Note that GoTo Action can be linked to a named destination.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

Can you provide some code that will help me get started?

Regards,
M
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to update Bookmarks?

Post by Tracker Supp-Stefan »

Hello mmasood,

Alex finished for today, but I will pass that request to him - and I am sure he will give you some pointers where to look at to get this implemented.

Cheers,
Stefan
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Stefan,

Thanks, i will look forward to Alex's response.

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

To get to the Bookmarks in the IPXC_Document use this method:
https://sdkhelp.pdf-xchange.com/vie ... etNameTree
with the "Bookmarks" name.
Then you can get the bookmarks root that holds all of the bookmarks in document. Each bookmark has Action List that can hold multiple actions of multiple types. Basically you need to go from the end of the array and find last GoTo action. Then you will need to see whether it's a Named Destination typed action or is it a direct destination type one. If it's a named destination type then you skip it, because you should also go through all of the named destinations and change their coordinates proportionally. If it's a direct destination type then check the Dest type and by using PDF Specification change it's dValues[] if type XYZ or Rect and they are not inherited.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

I tried the following code:

Code: Select all

	Dim book As IPXC_NameTree
        Set book = pDocOrig.GetNameTree("Bookmarks")
and I always get the book.count to be 0 even when there are bookmarks present in the document. Can you show me some sample code on how to use it?

I tried the following code as well:

Code: Select all

	Dim oBookmarks As IPXC_Bookmark
        Set oBookmarks = pDocOrig.BookmarkRoot
and with this I am getting the ChildrenCount to be greater than 0 if there are bookmarks. I am not sure on how to parse through this to check each individual item in the list.

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

This is a correct code:

Code: Select all

 Dim oBookmarks As IPXC_Bookmark
        Set oBookmarks = pDocOrig.BookmarkRoot
Parse trough this as if you were parsing an ordinary tree (note that this is not a list). Basically each item can have it's own children. Each of them can have the Actions List.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

i am not able to make any progress on this. Can you explain a few things:
Each bookmark has Action List that can hold multiple actions of multiple types. Basically you need to go from the end of the array and find last GoTo action.
Q1. How do I find the the type of an action i.e. GoTo action?
Then you will need to see whether it's a Named Destination typed action or is it a direct destination type one.
Q2. How do I determine if an action is Named Destination or Direct Destination?
If it's a named destination type then you skip it, because you should also go through all of the named destinations and change their coordinates proportionally.
Q3. Can you explain this further?
If it's a direct destination type then check the Dest type and by using PDF Specification change it's dValues[] if type XYZ or Rect and they are not inherited.
Q4. How do i check for Dest Type?

Can you provide any sample code that I can go through to make this work?

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

1) To get the actions type use this:
https://sdkhelp.pdf-xchange.com/vie ... ction_Type
For example, to get the Type ID of the GoTo action use this:

Code: Select all

int GoTo = pxsInst.StrToAtom("GoTo");
2) After knowing that the action is a GoTo action by type just cast the interface to the IPXC_Action_Goto.
https://sdkhelp.pdf-xchange.com/vie ... ction_Goto
This interface has answers to this question.

3) You can read the PDF Specification to find out more about destinations (or GoTo actions in that matter). What I meant in my post was this:
https://sdkhelp.pdf-xchange.com/vie ... estination

4)We won't write the complete code for you - we only provide guidance - feel free to ask.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

I tried with the suggestions that you gave and I am able to see the properties of the dest but cannot update them. Following is the code that I have right now:

Code: Select all

		' 1 - check if it a GoTo action'
                If book.Actions.Item(i).Type = 2703 Then
                    ' 2 - cast it to IPXC_Action_Goto'
                    Dim action As IPXC_Action_Goto
                    Set action = book.Actions.Item(i)
                    
                    ' 3 - check if the action is Named Destination Type or not'
                    If action.IsNamedDest = False Then
                        ' direct destination'
                        Debug.Print "IsNamedDest = False"
                        Debug.Print "Page: " & action.Dest.nPageNum
                        Debug.Print "Null Flags: " & action.Dest.nNullFlags
                        Debug.Print "Type: " & action.Dest.nType
                        Debug.Print "dValues(0): " & action.Dest.dValues(0)
                        Debug.Print "dValues(1): " & action.Dest.dValues(1)
                        Debug.Print "dValues(2): " & action.Dest.dValues(2)
                        Debug.Print "dValues(3): " & action.Dest.dValues(3)
                        Debug.Print ""
                        
                        action.Dest.nPageNum = 20
                        
                        book.Actions.Remove i
                        book.Actions.Insert i, action
                    Else
                        ' named destination'
                        Debug.Print "IsNamedDest = True"
                        Debug.Print "Page: " & action.Dest.nPageNum
                        Debug.Print "Null Flags: " & action.Dest.nNullFlags
                        Debug.Print "Type: " & action.Dest.nType
                        Debug.Print "dValues(0): " & action.Dest.dValues(0)
                        Debug.Print "dValues(1): " & action.Dest.dValues(1)
                        Debug.Print "dValues(2): " & action.Dest.dValues(2)
                        Debug.Print "dValues(3): " & action.Dest.dValues(3)
                        Debug.Print ""
                    End If
                    
                    Set action = Nothing
                End If
I have tried these two things:

1. change the Page number and save the document
2. i have also tried to remove and then add the action again

to make it work but the final document always has the bookmark pointing to the same page as the original document and my changes are not used.

What should I do to make it work?

I am using the latest version of Core Api 6.0.322.5 and VB6.

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

1) Never, I mean never! use the direct number representations for IDs like you did here they will be changed from build to build:
book.Actions.Item(i).Type = 2703
The correct way is initializing them on the program start from their string representations (like you can see in the FullDemo application).
As for the destination setting, try creating a variable for the PXC_Destination:

Code: Select all

PXC_Destination dest = act.get_Dest();
//..Modify it here
act.set_Dest(ref dest);
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

I tried your suggestion but it still does not work. Following is the latest code:

Code: Select all

                ' 1 - check if it a GoTo action'
                If book.Actions.Item(i).Type = GoToValue Then
                    ' 2 - cast it to IPXC_Action_Goto'
                    Dim action As IPXC_Action_Goto
                    Set action = book.Actions.Item(i)
                    
                    ' 3 - check if the action is Named Destination Type or not'
                    If action.IsNamedDest = False Then
                        ' direct destination'
                        ' change dValues if Type = XYZ or RECT and is not inherited'
                        Debug.Print "IsNamedDest = False"
                        Debug.Print "Page: " & action.Dest.nPageNum
                        Debug.Print "Null Flags: " & action.Dest.nNullFlags
                        Debug.Print "Type: " & action.Dest.nType
                        Debug.Print "dValues(0): " & action.Dest.dValues(0)
                        Debug.Print "dValues(1): " & action.Dest.dValues(1)
                        Debug.Print "dValues(2): " & action.Dest.dValues(2)
                        Debug.Print "dValues(3): " & action.Dest.dValues(3)
                        Debug.Print ""
                        
                        Dim oDest As PXC_Destination
                        oDest = action.Dest
                        oDest.nPageNum = oDest.nPageNum + 1
                        action.Dest = oDest
                    Else
                        ' named destination'
                        Debug.Print "IsNamedDest = True"
                        Debug.Print "Page: " & action.Dest.nPageNum
                        Debug.Print "Null Flags: " & action.Dest.nNullFlags
                        Debug.Print "Type: " & action.Dest.nType
                        Debug.Print "dValues(0): " & action.Dest.dValues(0)
                        Debug.Print "dValues(1): " & action.Dest.dValues(1)
                        Debug.Print "dValues(2): " & action.Dest.dValues(2)
                        Debug.Print "dValues(3): " & action.Dest.dValues(3)
                        Debug.Print ""
                    End If
                    
                    Set action = Nothing
                End If
Can you provide a code snippet for VB6 that will work?

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

Do the same thing with the IPXC_ActionsList like with the PXC_Destination - the .Net is making a copy of the data and you are modifying a copy, not an original. If you were doing this in the C++ for example - everything would work correctly through pointers.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

Your last suggestion worked wonders. I am able to update the bookmarks now. Thanks a lot for your help through out this process.

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

The bookmarks part is working fine with the changes that were made. I am however running into another thing, the table of contents links are not being updated. I checked and they are not Bookmarks but Annotations (Link Annotations).

What is the procedure that I need to follow in order to update the table of contents and any other link annotations?

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

The procedure should be the same as for the bookmarks. You should take the pages' annotations list and look for the link type annotations. Then take their Actions List from them and change it accordingly.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

I am trying to do the same thing that you suggested. Following is the code that I have (that does not work):

Code: Select all

    Dim actionList As IPXC_ActionsList
    Set actionList = oAnnot.Actions(Trigger_Up)
    
    If Not actionList Is Nothing Then
        If actionList.Count > 0 Then
            Dim i As Long
            For i = actionList.Count - 1 To 0
                ' 1 - check if it a GoTo action'
                If actionList.Item(i).Type = GoToValue Then
                    ' 2 - cast it to IPXC_Action_Goto'
                    Dim action As IPXC_Action_Goto
                    Set action = actionList.Item(i)
                    
                        ' 3 - check if the action is Named Destination Type or not'
                        If action.IsNamedDest = False Then
                            ' direct destination'
                            ' change dValues if Type = XYZ or RECT and is not inherited'
                            Debug.Print "IsNamedDest = False"
                            Debug.Print "Page: " & action.Dest.nPageNum
                            Debug.Print "Null Flags: " & action.Dest.nNullFlags
                            Debug.Print "Type: " & action.Dest.nType
                            Debug.Print "dValues(0): " & action.Dest.dValues(0)
                            Debug.Print "dValues(1): " & action.Dest.dValues(1)
                            Debug.Print "dValues(2): " & action.Dest.dValues(2)
                            Debug.Print "dValues(3): " & action.Dest.dValues(3)
                            Debug.Print ""
                            
                            Dim oDest As PXC_Destination
                            oDest = action.Dest
                            oDest.nPageNum = oDest.nPageNum + 1
                            
                            action.Dest = oDest
                        Else
                            ' named destination'
                        End If
                    
                    Set action = Nothing
                End If
            Next
        End If
    End If
    
    oAnnot.Actions(Trigger_Up) = actionList
    Set actionList = Nothing
    Exit Function
I have tried with Trigger types other than Trigger_Up but it still does nothing. What do you think might be missing here?

I checked one of the output pdf in Acrobat Pro and it shows that it is a link but has no properties attached to it what so ever.

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

From the first sight, the code looks correct. Have you tried debugging it? Is suggest creating a link with a GoTo action in the End-User Editor, and try modifying it.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

Yes i have debugged it and the values seem to be updated. I have another question:

I am resizing pages as part of my application, following are the steps:
1. Calculate the dimensions of the new page
2. Insert a new page in the document
3. Copy the content from Original page to the New Page
4. Delete the Original page

Q1. Is there a better way to do this?
Q2. Is there a way to resize the current page so that I do not have to create a new page?

If it is something that can be done, that will fix the annotation issue for me as well :).

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

Well, in the Editor SDK there is a Resize Pages operation. Though as you are using the Core API you don't have any access to the Operations of the Editor SDK. To resize a page you will have to change it's PBox_MediaBox - that's all. Though the content scaling should be done by yourself if you need that.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

I am changing the Media Box of the page with this line of code:

Code: Select all

currentPage.Box(PBox_MediaBox) = newPageRect
where 'newPageRect' is the updated rectangle.

This has effect on some of the documents while the page size of the others remains unaffected.

Q1. Is this the right way to update the page size of a page?
Q2. If not that how should it be done?

I am attaching a couple of documents that have this problem for you to look at. Looking forward to your reply.

Regards,
M
Attachments
Failure 2.pdf
(16.25 KiB) Downloaded 168 times
Failure 1.pdf
(43.36 KiB) Downloaded 154 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

Well, the problem is that that file has a valid Crop box specified, thus it is cropped by it - you will also have to set the CropBox. In other files there were no Crop Box - thus it was fixuped by the Media Box.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

I just ran a few files through my application and checked that all files have a crop box similar to the media box. How do I determine if the crop box for a file is valid or not? Is there any call in the Core Api that can help me deal with it?

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

I doubt that - you will have to look into the PDF structure directly not the End-User Editor (it will fixup everything for the End-User automatically). Basically, you will have to take the PDFObject of the IPXC_Page and then check whether the CropBox element is present.
Here's the link to the PDF specification to the Page Objects definition:
http://www.adobe.com/content/dam/Adobe/ ... G8.1640002

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood »

Hi Alex,

I have been able to fix it by updating the crop box as well as the media box. I haven't run across any issues so far.

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply