ExecuteJS to import and export in XFDF

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
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

ExecuteJS to import and export in XFDF

Post by Erickc »

Hi,

In a PowerBuilder 12.5 application, we are trying to import and export programmatically in a .xfdf file all the annotations present in a PDF.

We succeeded by using PDFXChange Viewer Active X SDK and these commands :

Code: Select all

Ole_PDF.Object.RunJavaScript( 'this.importAnXFDF( "'C:\temp\annot.xfdf'" );' )
Ole_PDF.Object.RunJavaScript( 'this.exportAsXFDF( true, false, null, "' +  "'C:\temp\annot.xfdf'"  + '", true);' )     


Now, we are struggling to make the equivalent in PDF_Xchange Editor ActiveX.

We had a look at the ”FullDemo” included with the SDK. On its Javascript tab, we tried to enter this command :

Code: Select all

 importAnXFDF("C:\temp\annot.xfdf")  (single or double quoted)
And the result is always the opening of a file dialog window

Could you please give us some hints?

Thank you very much!

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

Re: ExecuteJS to import and export in XFDF

Post by Tracker Supp-Stefan »

Hello Eric,

Are you using this method:
IPXV_Inst::ExecuteJS Method ?

Can you give a larger snippet with your implementation in the Editor SDK?

Regards,
Stefan
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hello Stefan,

Yes, we use IPXV_Inst::ExecuteJS Method. Here the code snippet :

Code: Select all

OLEObject myIcab
OLEObject myDoc

any        la_null, la_nullout
setnull(la_null)

//open document … OK - It works!
myIcab = ole_pdfXchange_editor_control.Object.Inst.CreateOpenDocParams()
ole_pdfXchange_editor_control.Object.OpenDocFromPath( 'C:\Temp\abc.pdf' , myIcab)

//load setting … OK - It works!
ole_pdfXchange_editor_control.Object.VisibleCmdPanes = 1
ole_pdfxchange_editor_control.object.Inst.LoadUserSettings(ole_pdfxchange_editor_control.object.Inst.CreateString('C:\Temp\@@setting_annotation_pdf.dat'))
ole_pdfxchange_editor_control.object.LockedCmdBars = false

//Import annotations  … FAIL!
myDoc = ole_pdfxchange_editor_control.Object.Doc
ole_pdfxchange_editor_control.Object.Inst.ExecuteJS(myDoc,
                              ole_pdfxchange_editor_control.object.Inst.CreateString('importAnXFDF("C:\Temp\annots.xfdf")'),
                              5,
                              15,
                              la_null)

Thank you!

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

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Does this same JS work for you in the End-User Editor from inside the JS console there?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hello Alex

This command opens a file selection dialog window in both the JS console of the End user Edition and the demo application supplied with the JDK :

Code: Select all

importAnXFDF("C:\Temp\annots.xfdf")
We expected that it should load the annotations without the dialog window.

Cheers,

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

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Well that's because you have not specified a path correctly - if you read an Acrobat JS Documentation you would have seen that you should have specified a device independent path.

Code: Select all

importAnXFDF("/C/Temp/annots.xfdf")
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Thank you Alex,
Effectively, with the correct path, it now works in both JS consoles.
But we still struggle to make it works in our PowerBuilder app.
Do you see something that could be wrong in the following code?
Or maybe you have a example in another programming language thant C# that would be closer to PowerBuilder.
We are so close to success - annotations import/export is the only thing left we have to implement in our proof of concept and confirm the switch from PDF-Viewer SDK to PDF-Xchange Editor SDK!

Code: Select all

OLEObject myIcab
OLEObject myDoc

any        la_null, la_nullout
setnull(la_null)

//open document … OK - It works!
myIcab = ole_pdfXchange_editor_control.Object.Inst.CreateOpenDocParams()
ole_pdfXchange_editor_control.Object.OpenDocFromPath( 'C:\Temp\abc.pdf' , myIcab)

//load setting … OK - It works!
ole_pdfXchange_editor_control.Object.VisibleCmdPanes = 1
ole_pdfxchange_editor_control.object.Inst.LoadUserSettings(ole_pdfxchange_editor_control.object.Inst.CreateString('C:\Temp\@@setting_annotation_pdf.dat'))
ole_pdfxchange_editor_control.object.LockedCmdBars = false

//Import annotations  … FAIL!
myDoc = ole_pdfxchange_editor_control.Object.Doc
ole_pdfxchange_editor_control.Object.Inst.ExecuteJS(myDoc,
                              ole_pdfxchange_editor_control.object.Inst.CreateString('importAnXFDF("/C/Temp/annots.xfdf")'),
                              5,
                              15,
                              la_null)
Thank you,

Cheers,

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

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Would VB6 work for you? If so, my teammate will write code sample for you tomorrow.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hello Alex,

That would be awesome :D

Thank you!

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

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Just a thought - why would you need to execute a JS when you can just open the xfdf file with the OpenDocFromPath method and it will be automatically converted to the PDF. Give it a try.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hello Alex,

We will try it but I think that even if it works, we would still have to find a way to export those annotations in a separate xfdf file. With the Viewer SDK, the only way was through Javascript.

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

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Now, the operation is available for that - try this one:
https://sdkhelp.pdf-xchange.com/vie ... sAndFields

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hello again Alex,

Good news - OpenDocFromPath works to get the annotation!

The only thing left is the ability to save back those annotations. :D

Cheers,
Eric
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hi Alex,

I just saw your reply!

Many thanks!!

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

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Well the JS command that exports them uses this operation. Try using the JS first and if it does not work try using this operation directly.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hello Alex,

We failed to execute both op.document.exportCommentsAndFields and IPXV_Inst::ExecuteJS Method

Our problem seems to be related to PDF Editor Layer access. We can't instantiate or access it.

Finally, your offer for a simple example in VB6 would be welcome.

Thank you!

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

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Can you give us your code sample on op.document.importCommentsAndFields?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hello Alex

Here is the code (PS, our need is for exportCommentsAndField, I made a mistake in my previous question - I'm the messenger not the actual programmer!)

Code: Select all

oleobject myDoc
oleObject pxcInst
oleObject afsInst
oleObject myPath

//Save menu setting... it works
ole_pdfxchange_editor_control.object.Inst.SaveUserSettings(ole_pdfxchange_editor_control.object.Inst.CreateString('C:\Temp\@@setting_annotation_pdf.dat'))

// Create instances to CORE API Layers
pxcInst = ole_pdfxchange_editor_control.object.Inst.GetExtension("PXC")
afsInst  = ole_pdfxchange_editor_control.object.Inst.GetExtension("AFS")
// BTW we don't know how to do it for the PDF Editor Layer ("PXV") and if it's required

//Try to create an IAFS_Name param to pass in exportCommentsAndField command... It doesn't work :-(
myPath = afsInst.DefaultFileSys.StringToName(ole_pdfxchange_editor_control.object.Inst.CreateString('C:\Temp\abc2.xfdf'))

myDoc = ole_pdfxchange_editor_control.Object.Doc

//We didn't made it so far since myPath was not created.  But if we do, do we have to call the "PXV" layer?
pxcInst.exportCommentsAndFields(myDoc, myPath)
Thank you very much

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

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Sorry I meant a sample on op.document.exportCommentsAndFields.
Also, about this:
// BTW we don't know how to do it for the PDF Editor Layer ("PXV") and if it's required
You already have the IPXV_Inst:

Code: Select all

ole_pdfxchange_editor_control.object.Inst
As for the IAFS_FileSys::StringToName method - try supplying the default parameters as we've done earlier - probably the VB6 works only that way.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hello Alex,
No luck. Our PowerBuilder dev is stuck in a dead-end.
I think a VB6 example will be much needed.
Thank you.
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Well, then you will have to wait until tomorrow, because our VB expert is away today.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Thank you.
Have a great day!
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

The problem was that you've passed an IString whilst the StringToName method needs a normal string as an input parameter. Please read parameter types more carefully.

Code: Select all

    Dim Path As IAFS_Name
    Dim p_fsInst As PDFXEditCtl.IAFS_Inst
    Set p_fsInst = PXV_Control1.Inst.GetExtension("AFS")
    Set Path = p_fsInst.DefaultFileSys.StringToName(App.Path + "\sample.pdf")
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Hi,
Would it be possible for you to supply us a more complete VB6 example of a call to ExecuteJS with importAnXFDF as javascript command?
Something that would show the declaration, initialization and usage of the 5 parameters would really help us to finally complete our proof of concept and confirm that we can switch from the Viewer SDK. After the last week, we're still stuck.
Thank you very much,
Best regards,
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

Try this code:

Code: Select all

Dim res As IString
   Set res = PXV_Control1.Inst.CreateString()
   Dim script As String
   
   Set script = "importAnXFDF('/C/Temp/annots.xfdf');"
   
   Call PXV_Control1.Inst.ExecuteJS(PXV_Control1.Doc, script, PAEC_External, PAESC_Exec, Nothing, res)
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Thank you so much Alex,
We will hopefully make it work in PowerBuilder.
On a side note, we were made aware that PowerBuilder only supports external functions that were exported using the WINAPI (_stdcall) format.
Is this requirement applicable to PDF -XChange Editor SDK? May be this could explain our struggles.
Here is an extract of PB Documentation
Use _stdcall convention
C and C++ compilers typically support several calling conventions, including _cdecl (the default calling convention for C programs), _stdcall (the standard convention for Windows API calls), _fastcall, and thiscall. PowerBuilder, like many other Windows development tools, requires external functions to be exported using the WINAPI (_stdcall) format. Attempting to use a different calling convention can cause an application crash.
When you create your own C or C++ DLLs containing functions to be used in PowerBuilder, make sure that they use the standard convention for Windows API calls.
Thank you,
Eric
Last edited by Erickc on Tue Jul 11, 2017 1:48 pm, edited 1 time in total.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

Hello Eric,

We are using the stdcall in the Editor SDK.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Erickc
User
Posts: 46
Joined: Tue Apr 12, 2016 2:36 pm

Re: ExecuteJS to import and export in XFDF

Post by Erickc »

Thank you!
(and of course I meant stdcall and not "strcall". Sorry for this bad typo.)
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: ExecuteJS to import and export in XFDF

Post by Sasha - Tracker Dev Team »

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