How to update Bookmarks?

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

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

How to update Bookmarks?

Post by mmasood » Wed Jun 07, 2017 7:28 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Thu Jun 08, 2017 10:02 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Thu Jun 08, 2017 1:28 pm

Hi Alex,

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

Regards,
M

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

Re: How to update Bookmarks?

Post by Tracker Supp-Stefan » Thu Jun 08, 2017 3:10 pm

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: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Thu Jun 08, 2017 3:40 pm

Hi Stefan,

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

Regards,
M

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Fri Jun 09, 2017 9:00 am

Hello mmasood,

To get to the Bookmarks in the IPXC_Document use this method:
http://sdkhelp.tracker-software.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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Fri Jun 09, 2017 2:59 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Fri Jun 09, 2017 3:05 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Fri Jun 09, 2017 5:04 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Mon Jun 12, 2017 10:09 am

Hello mmasood,

1) To get the actions type use this:
http://sdkhelp.tracker-software.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.
http://sdkhelp.tracker-software.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:
http://sdkhelp.tracker-software.com/vie ... estination

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

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Tue Jul 11, 2017 6:57 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Wed Jul 12, 2017 7:47 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Wed Jul 12, 2017 3:53 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Thu Jul 13, 2017 9:15 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Fri Jul 14, 2017 1:31 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Fri Jul 14, 2017 1:54 pm

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Thu Jul 27, 2017 3:41 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Fri Jul 28, 2017 8:08 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Fri Jul 28, 2017 12:41 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Fri Jul 28, 2017 2:35 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Fri Jul 28, 2017 4:36 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Mon Jul 31, 2017 7:50 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Mon Jul 31, 2017 6:01 pm

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 55 times
Failure 1.pdf
(43.36 KiB) Downloaded 56 times

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Tue Aug 01, 2017 2:10 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Tue Aug 01, 2017 2:42 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Wed Aug 02, 2017 9:06 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to update Bookmarks?

Post by mmasood » Thu Aug 10, 2017 1:42 pm

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

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

Re: How to update Bookmarks?

Post by Sasha - Tracker Dev Team » Thu Aug 10, 2017 1:48 pm

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply