In my current project, there is a requirement to compare contents between two different pdf files in slient mode , we develop this interface base on Acrobat professional 8 .
Since we can get the Acrobat.dll after setup Acrobat Professional, that’s the chance let us can use the objects in Acrobat.
There are several objects we will used,
AcroExch.App --- you can treat it like the exe file, from the application level let user can control the appearance of Acrobat, populate Acrobat.
AcroExch.PDDoc --- the underlying PDF representation of a document
AcroExch.AVDoc --- a view of PDF document in a window
From these objects, we can do most of things such as open PDF file, close, etc.
CAcroApp app = (CAcroApp )(Activator .CreateInstance(Type .GetTypeFromProgID("AcroExch.App" ))); CAcroPDDoc pdDoc1 = (CAcroPDDoc )(Activator .CreateInstance(Type .GetTypeFromProgID("AcroExch.PDDoc" ))); app.Hide(); |
When in the implementation, we met an obstacle, when execute the comparison, Acrobat will popup a dialog which let you choose options, it block the whole process.
In order to fix this issue, we have to open other backend thread to monitor when this dialog come to the front of the window, then close it.
We use WIN32 dll to deal with that.
Here is the snippet:
while (title.ToString() != "Compare Documents" ) { Thread .Sleep(1000); IntPtr val = GetForegroundWindow(); GetWindowText(val, title, 100000); } SendKeys .SendWait("{ENTER}" ); |
the next step is encapsulates this function into WCF and deploy it, then any users can use it from anywhere.