op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc  SOLVED

PDF-XChange Editor SDK for Developers

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

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
zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Wed Nov 04, 2020 11:41 am

Hi Support,

I'm trying to catch the moment when "op.document.optimize" does its work.

I'm handling e.operBeforeExecute and e.operExecuted events.

Seems that op.document.optimize is not caught (not passed), rather "op.openDoc" is reported when IOperation.Do is executed.

By design, or?

Further, when op.openDoc is caught after calling IOperation.Do(op.document.optimize) - the "Input" parameter is some interface but none of IAFS_Name, IAFS_File, IString or IStream. What is it?


-žarko

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

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by Sasha - Tracker Dev Team » Wed Nov 04, 2020 1:23 pm

Hello zarkogajic,

As that operation is from plugin - the default begin/end wrapper is missing - thus you can't catch the events. Also, the interface that is being passed to the op.openDoc is IString.

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

zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Wed Nov 04, 2020 3:16 pm

Hi Alex,
Also, the interface that is being passed to the op.openDoc is IString.
It is so when using "Save As Optimized...", the "Input" in e.operBeforeExecute/op.openDoc *is* IString (a file name under Temp folder).

However, when programmatically executing (IPXV_Inst.CreateOp) IOperation(op.document.optimize).Do, the "Input" in e.operBeforeExecute/op.openDoc is *not* IString (nor any of IAFS_Name, IAFS_File, IStream).

-žarko

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

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by Sasha - Tracker Dev Team » Fri Nov 06, 2020 10:15 am

Hello zarkogajic,

We've added the e.operBeforeExecute/e.operExecuted events for the optimize operation - you will be able to do what you require. The fix will be available in the V9 version that should be out in a month or so.

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

zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Fri Nov 06, 2020 10:21 am

Thanks Alex,

That's great!

Would e.operExecuted be fired before or after the file has been saved to the file system? (the later is more preferable :))

-žarko

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

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by Sasha - Tracker Dev Team » Mon Nov 09, 2020 10:48 am

Hello zarkogajic,

This would be before the document is saved. Basically, you will catch the e.operExecuted event and then you have two choices:
1) Work with that document structure directly via our API and do the needed stuff to make it a linearized pdf file.
2) Get the document's IAFS_Name, close the document (so that the file won't be blocked), do your stuff with the 3rd party tools, open that document with the saved IAFS_Name and put it's object into the operation Output in place of the old one.
Note, that when registering the EventHandler, you should not use the EventHandler_SyncCall, becuse this will block the main thread of the Control while you are working with the file.

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

zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Mon Nov 09, 2020 11:06 am

HI Alex,

Thanks. I'll have to work with your proposed option (2).

I'll close the topic and wait for the new release including those to events ...

-žarko

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

op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by Sasha - Tracker Dev Team » Mon Nov 09, 2020 11:12 am

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

zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Tue Jan 26, 2021 2:53 pm

Hi Support,

Now in V9, I can catch "e.operExecuted" for "op.document.optimize", so I'm reopening this topic...
This would be before the document is saved. Basically, you will catch the e.operExecuted event and then you have two choices:
2) Get the document's IAFS_Name, close the document (so that the file won't be blocked), do your stuff with the 3rd party tools, open that document with the saved IAFS_Name and put it's object into the operation Output in place of the old one.
What I see is that "e.operExecuted" for "op.document.optimize" happens before the SaveAs dialog prompts for the file name to save.

Also, the Output parameter at this moment does have something but that something is not IAFS_Name - what is it ? (the Help system states Output is not used)

When does your optimization actually happen? As I would need to call my 3rdparty linearization code after you do optimization (as otherwise I think your optimization would remove linearization)...
Note, that when registering the EventHandler, you should not use the EventHandler_SyncCall, becuse this will block the main thread of the Control while you are working with the file
I'm not sure why would I need an EventHandler for the above?

-žarko

zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Thu Apr 01, 2021 5:40 pm

Hi Support,

I've figured out the order of events here .... and I think I know now how to do what I'm after ...


zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Fri Apr 02, 2021 1:17 pm

Hi Support,

Here's my last attempt to try to linearize a file as a part of optimization operation...

The "e.document.afterSave" gets raised for Save and Save As but also for Save Copy As. But, not for Save As Optimized.

May I ask you to include/raise the "e.document.afterSave" event also for the "Save As Optimized" command - once the document is saved to file system.

Being able to react on "e.document.afterSave" for optimized documents would then give me a moment to do my stuff to the file....

p.s.
I know optimization works on Core Documents - and there may be no IPXVDocument when running the operation - but in case there is (when optimizing an IPXV_Document loaded in MainFrame) - e.document.afterSave could be raised from it and then I could get my hands on the optimized file from IPXV_DocSaveEvent.Dest property.

-žarko

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

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by Sasha - Tracker Dev Team » Wed Apr 07, 2021 9:40 am

Hello zarkogajic,

Theoretically this can be added - but will need to consult with Vasyl first.

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

zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Wed Apr 07, 2021 10:16 am

Hi Alex,

Thanks, that would be great!


User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2033
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by Vasyl-Tracker Dev Team » Sat Apr 17, 2021 1:59 am

Hi zarkogajic.

In the new upcoming build you will be able to catch the new "e.document.preSaveOptimizedData" event and get the IPXV_DocPreSaveOptimizedDataEvent interface from the IEvent argument in OnEvent callback. The short description of that interface:

Code: Select all

uuid(45BF8A5F-296C-44D4-9DB4-E04F04EF501B)
IPXV_DocPreSaveOptimizedDataEvent
{
	[get] IPXC_Document TempOptimizedDoc;
	[get] ICab OptimizationOpts;
	[get, set] IAFS_Name DestFileName;
	[get] HANDLE_T WndParent;
	[get] IProgressMon Progress;
};
TempOptimizedDoc - is the temp. core-document that can be used for additional modifications you need and before saving to the destination file. Also you may use the TempOptimizedDoc.SrcInfo.File to read/write it (but do not use methods of TempOptimizedDoc-object after writing to the File).
OptimizationOpts - contains all optimization-options used by user
DestFileName - the file name specified by user, you may change it.


HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Sat Apr 17, 2021 6:42 am

Hi Vasyl,

Thanks - looks good.

Btw, still, please fire ".document.afterSave" for optimized saved documents...


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

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by Sasha - Tracker Dev Team » Tue Apr 20, 2021 1:05 pm

Hello zarkogajic,

Spoke with Vasyl, and he said that's it's too much work to do and to risky to inject a document.afterSave event for the current optimization operation logic.
We fear that something can be broken along the way and as this is an old and battle hardened operation, let's leave it as is. Basically these events that Vasyl gave you will do all of the stuff that you require.

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

zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by zarkogajic » Tue Apr 20, 2021 1:11 pm

Hi Alex,

ok, thanks, I hear ya.

Yes, hopefully IPXV_DocPreSaveOptimizedDataEvent should be enough ... I'm downloading 353 now and will do test in the coming days...


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

op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc

Post by Sasha - Tracker Dev Team » Tue Apr 20, 2021 1:19 pm

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

zarkogajic
User
Posts: 958
Joined: Thu Sep 05, 2019 12:35 pm

Re: op.document.optimize -> e.operBeforeExecute/e.operExecuted == op.openDoc  SOLVED

Post by zarkogajic » Thu Apr 22, 2021 10:25 am

EDIT: I've moved this post to a separate topic :

viewtopic.php?f=66&t=36495

-žarko

Post Reply