Skip to main content
Participating Frequently
May 5, 2020
Answered

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

  • May 5, 2020
  • 4 replies
  • 1563 views

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
This topic has been closed for replies.
Correct answer Test Screen Name

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.

4 replies

Legend
May 5, 2020

 "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.

Legend
May 5, 2020

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.

Thom Parker
Community Expert
Community Expert
May 5, 2020

Good Stuff Andy!! Thanks 🙂

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Test Screen NameCorrect answer
Legend
May 5, 2020

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.

rkmtwoAuthor
Participating Frequently
May 5, 2020

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?

Legend
May 5, 2020

.."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. 

Thom Parker
Community Expert
Community Expert
May 5, 2020

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.  

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
rkmtwoAuthor
Participating Frequently
May 5, 2020

Thanks for this.

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