How do I allow user to interact with PDF while plugin works in the background (Acrobat C++ SDK)?

May 05, 2020

Copy link to clipboard

Copied

Hi,

I am working on an Acrobat Plugin using the C++ SDK for Windows.

I've implemented a toolbar as part of the plugin. Part of the plugin actions is compute and time intensive. The compute intensive task is now part of a background thread, however, I cannot interact with the document while the toolbar is active. I believe this is because the right and left click action of Adobe are associate with the DoClickProcType callback

 

My question is the following:

Is there a way to release the right and left click to the default tool so that the user can interact with the document using the usual tools (select, pan,. etc...) while my plugin does background work?

 

Things that I have tried but didn't work:

  • Registered the plugin window application using WinAppRegisterModeless
  • Disable my plugin, and its toolbar and set the default tool using AVAppSetActiveTool(AVAppGetDefaultTool(), true). This seems to return the select tool (the arrow icon is highlighted in the toolbar area, but I can't right click)
  • Tried associated a callback function that returns false to the IsPersistentProcType of AVToolRec

You can start another thread from your plug-in. It must not

* cause the main thread to wait (plug-in must return control to Acrobat)

* use any Acrobat API methods AT ALL including non-visual ones

* cause the process to hang 

If Acrobat is hanging, you probably have not followed one or both of these rules.

TOPICS
Acrobat SDK and JavaScript

Views

373

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How do I allow user to interact with PDF while plugin works in the background (Acrobat C++ SDK)?

May 05, 2020

Copy link to clipboard

Copied

Hi,

I am working on an Acrobat Plugin using the C++ SDK for Windows.

I've implemented a toolbar as part of the plugin. Part of the plugin actions is compute and time intensive. The compute intensive task is now part of a background thread, however, I cannot interact with the document while the toolbar is active. I believe this is because the right and left click action of Adobe are associate with the DoClickProcType callback

 

My question is the following:

Is there a way to release the right and left click to the default tool so that the user can interact with the document using the usual tools (select, pan,. etc...) while my plugin does background work?

 

Things that I have tried but didn't work:

  • Registered the plugin window application using WinAppRegisterModeless
  • Disable my plugin, and its toolbar and set the default tool using AVAppSetActiveTool(AVAppGetDefaultTool(), true). This seems to return the select tool (the arrow icon is highlighted in the toolbar area, but I can't right click)
  • Tried associated a callback function that returns false to the IsPersistentProcType of AVToolRec

You can start another thread from your plug-in. It must not

* cause the main thread to wait (plug-in must return control to Acrobat)

* use any Acrobat API methods AT ALL including non-visual ones

* cause the process to hang 

If Acrobat is hanging, you probably have not followed one or both of these rules.

TOPICS
Acrobat SDK and JavaScript

Views

374

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 05, 2020 0
May 05, 2020

Copy link to clipboard

Copied

My understanding is that the SDK is single threaded.  If you want to give Acrobat a few cycles to interact with the user then you'll need to create you're own pseudo threads, like using idle events to run small pieces of the process.  

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1
May 05, 2020

Copy link to clipboard

Copied

Thanks for this.

A quick follow up: Is the best way to do this to use AVAppRegisterIdleProc() and related funtions?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 0
May 05, 2020

Copy link to clipboard

Copied

You can start another thread from your plug-in. It must not

* cause the main thread to wait (plug-in must return control to Acrobat)

* use any Acrobat API methods AT ALL including non-visual ones

* cause the process to hang 

If Acrobat is hanging, you probably have not followed one or both of these rules.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 2
May 05, 2020

Copy link to clipboard

Copied

Thanks for the clarifications. A quick follow on your second point:
"It must not use any Acrobat API methods AT ALL including non visual ones"
In my application, I make calls to non-visual ones. So because I am doing this, I cannot return the right and left click to the user, because my thread is using Acrobat (even though it's the non visual API calls).

 

Is this a good way to rephrase your second point there?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 0
May 05, 2020

Copy link to clipboard

Copied

.."In my application, I make calls to non-visual ones." When you say "application" do you mean "plug-in, outside the main thread" - because it is not your application, Acrobat is the application. However, if you are using Acrobat API methods inside Acrobat and outside the main thread YOU MUST STOP.  This applies to ALL PLUGIN METHODS WITHOUT EXCEPTION. No matter how much you want to use them in your other thread DO NOT DO SO. Outside Acrobat, in your application you cannot use the plug-in methods at all, so that is not even possible.

 

"So because I am doing this, I cannot return the right and left click to the user" Sorry I have no idea what you mean by "return [a] click to the user". A click in Acrobat can be processed by a plug-in, and if the plug-in waits Acrobat will hang. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1
May 05, 2020

Copy link to clipboard

Copied

Thanks for the clarification. I should have said plugin instead of application.

This helps me understand things much, much better. 
As for "returning a click to the user", I really don't know the best way to explain it, but I think one way to say it differently is to ask "is there a way to let Acrobat process the click instead of the plugin while there's a backgound task?" However, this question is moot, because using the Acrobat API outside the main thread is bad, which is what I was doing.

 

Thanks for the help. I think this means I need to rewrite part of the plugin, but better doing now than later 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 0
May 05, 2020

Copy link to clipboard

Copied

By the way... this may lead to the question... "How do I wait for the thread to complete". The answer is simple, you must not because you are making Acrobat wait. What you can do is create an Idle proc which runs at intervals; the idle proc checks for completion of the task and takes a suitable action.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1
May 05, 2020

Copy link to clipboard

Copied

Good Stuff Andy!! Thanks 🙂

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1
May 05, 2020

Copy link to clipboard

Copied

 "is there a way to let Acrobat process the click instead of the plugin while there's a backgound task?" To see why the answer must be no... the plug-in is not separate from Acrobat. When Acrobat calls your plug-in, through a callback, your plug-in IS ACROBAT at that moment. Acrobat does do a few things of its own in a background thread, but all the UI input is handled in the main thread - and you are that main thread.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1