11 Replies Latest reply: Apr 24, 2009 2:35 AM by MrRamrod RSS

    C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY

    Joe The Engineer Community Member

      Here are my requirements:
      1) A PDF viewer that is embedded in a window in my windows app.
      2) I must be able to reference button_click events in the PDF from my windows app. (i.e. if i click a button in the PDF, the event occurs in my windows app.

       


      Pertaining to the above requirements:
      Here is what I've noticed so far. The Adobe Reader ActiveX works great at simply viewing PDF's and the buttons are shown too. However, I haven't found anything in the Reader library that allows me to reference the buttons in the PDF. This leaves the following questions.

       

      Possible Solutions: (need your help/recommendations)

       

      1) Can I use the Acrobat SDK to reference the document that is open inside my Adobe Reader ActiveX control? (If I can, then i can get a hold of my buttons and events). If I can do this, does anyone have any clue about the proper syntax? All of the the samples I've seen actually reference a document that acrobat opens, not the reader....

       

      2) Can I embed the Adobe Acrobat (not the reader) in my windows app in order to view the files? I haven't seen this done yet. Every example I've seen opens the acrobat in it's own window!!!

       

      3) Is there other software out there that offers both functionalities: 1) Embedded viewing window with 2) Full access to PDF library?

       

      Any help in this matter would be greatly appreciated, as I have searched High, Low, and In Between for a solution.

       

      Thanks,

       

      jpc

        • 1. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
          Patrick Leckey Community Member

          For 1 & 2, the answer is "yes" with a "but" ...

           

          You must realize that your end user will need to have Acrobat installed on their local system in order to use any of the added OLE functionality that Acrobat provides over Reader.  The SDK does not provide these libraries - it is merely a collection of documentation, samples and headers required to compile Acrobat automation applications.  The application uses Acrobat to perform its tasks when deployed, and the Acrobat libraries are not redistributable (both by virtue of it being a violation of the EULA and because they are designed to prevent it).  Even if you are using the PD-layer and not presenting the user with a visible interface to Acrobat, an Acrobat process is running in the background in order to provide the functionality.

           

          The same is true of Reader, you're not "embedding" the Reader functionality in your application since the ActiveX control is merely a shim to the Reader application.  It's just less of an issue, since your end users could go and freely download Reader in order to enable the PDF viewing functionality in your application or you could apply for a distribution license with Adobe and distribute Reader with your application.  This is obviously not true of Acrobat since it is not a free product.

           

          So basically, you can achieve the functionality you want with Acrobat but each of your end-users would need their own licensed copy of Acrobat installed on their system for your application to function.

           

          For question 3, you can look at the Adobe PDF Library SDK - if you're in North America, you license it through a partner of ours named Datalogics.  It gives your full PDF access like Acrobat, you are allowed to redistribute the libraries as part of your application and you can use PDPageDrawContentsToWindow in order to render page views to a WinForms DC.

          • 2. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
            lrosenth Adobe Employee

            Neither Acrobat nor Reader will enable you to get called when a button is clicked...

            • 3. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
              walker81 Community Member

              One way for 2) is possible with Acobat std or Pro.

               

              I do not recomment it, but it is possible.

               

              You need to create a plugin containing a MenuItem. (AFExecuteThisScript must be possible  HFT...)

               

              The buttons need to call a JavaScipt function that sets a JS-Variable and calls the MenuItem.

              The MenuItem-Method gets the JSVaribalecontent by using a JS-Readfunction ( mytrustedGetJSButton= function GetIt() )  and now you can informs your app.

               

              If you really want, I can provide an example.

              • 4. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
                Patrick Leckey Community Member

                It is also possible using the JSObject to set the hostContainer property to enable two-way communication.  Again, this option is only available to Acrobat, not Reader as Reader does not have access to the JSObject.

                • 5. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
                  Joe The Engineer Community Member

                  Patrick Leckey and Walker81,

                   

                  So, according to both of you, it is possible.  I have messed around with the buttons a little bit in acrobat enough to know that you can make a button that on click will run a javascript.  The problem is that I do not know any javascript, which is why i was trying to access it only with C#.  However, I am now receptive of the idea of learning at least a little java to get around in adobe (it seems unavoidable).  Any examples or pointers as to how to do this would be greatly appreciated.

                   

                   

                  So for clarification:  Is the following statement correct?  If I have an Adobe Reader Active X control which opens the PDF, it is impossible for me to also reference that opened PDF as an acrobat object, thereby getting access to all of it's objects.

                   

                  From what I understand:

                   

                  -  I can put in the button field of my "template button" to call a certian javascript that is stored in the PDF, and this javascript can send information to my C# windows application.

                   

                  - I can embed acrobat (not reader) into my C# application with the MenuItem that Walker81 mentioned. (btw, i'm not concerned about the extra cost.  I really just need something that works)

                   

                  This brings about a question though:  If I can embed acrobat in my Windows App, then what keeps me from accessing the button fields through that avenue?  (I think the adobe SDK has an example of fields being accessed - things like text boxes being filled in and junk).  So would it be possible to create a buttonclick_event of all of the buttons in the PDF at runtime through adobe's library by looping through all of the fields and declaring a buttonclick event???  I'll look into it, because being able to access a field and being able to make an event from one can be two different animals I guess...

                   

                   

                   

                  Thanks for the responses, and I will look up and mess around with the methods you described and try to make them work from my limited knowledge.  If anyone has any example code they'd like to share to get me started on this, it would be helpful.  I understand there's something called a document level function or something like that in adobe.  I'm assuming you're saying that the button would call this function, and that this function would reference my windows app.  I will look at this some more and try to follow up on here.  I can't imagine that i'm the only person trying to do this..

                  • 6. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
                    Patrick Leckey Community Member

                    So for clarification:  Is the following statement correct?  If I have an Adobe Reader Active X control which opens the PDF, it is impossible for me to also reference that opened PDF as an acrobat object, thereby getting access to all of it's objects.

                    That is correct.  Reader alone does not provide the required interfaces to do what you want.

                     

                    This brings about a question though:  If I can embed acrobat in my Windows App, then what keeps me from accessing the button fields through that avenue?  (I think the adobe SDK has an example of fields being accessed - things like text boxes being filled in and junk).  So would it be possible to create a buttonclick_event of all of the buttons in the PDF at runtime through adobe's library by looping through all of the fields and declaring a buttonclick event???  I'll look into it, because being able to access a field and being able to make an event from one can be two different animals I guess...

                    It's exactly that - you can access the properties and methods of a field, but there is no mechanism in place to directly access events generated by a field through OLE.  To do this, you need to work through the Acrobat JavaScript engine (not Java, JavaScript - they are very different).

                    • 7. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
                      MrRamrod

                      "you can use PDPageDrawContentsToWindow in order to render page views to a WinForms DC."

                       

                      I am working on what sounds like a similar sort of application, although I have gone a LONG way down the path of implementing a custom acrobat plugin (in C) which performs 2-way comms between my application and Acrobat. But its heavy weight, pain the *** to support, and requires the user to have a full acrobat license.  It all works wonderfully, but I am currently research how to reduce end-user costs and am looking at how much of my plugin functionality will port to Reader.

                       

                      If I can use PDFLib (which i wanted to originally) to render direct into my DC, life would just be sooooo much easier.

                       

                      Adobe were against this when i originally proposed this (some 3+ years ago) so has there now been a change of heart?  Is this now a recommended approach?  Are there any limitations?  e.g. i can remember Adobe stating that there were 'risks' in that the pdflib implementation of the renderer wasnt the same as Acrobat, so the document view could differ, and if there were bug in the renderer, it would take longer to fix?  is this still the case?

                       

                      My customers are particularly fickle about the accuracy of document rendering (which is why i moved to pdf originally) so maybe i'm dreaming here, but this still feels like the best (simplest) technical solution i.e. render the pdf directly, instead of faffing about with multi-windowed inter-application comms etc.

                       

                      -r

                      • 8. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
                        Patrick Leckey Community Member

                        Just to confirm - are you talking about the Adobe PDF Library SDK or PDFLib (since you only mention "PDFLib")?  PDFLib is a 3rd party competitor to the Adobe PDF Library SDK and we wouldn't be able to provide any information about that.

                        • 9. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
                          Joe The Engineer Community Member

                          I think he's referring to AcroPDFLib since that's how you access the objects in the Reader ActiveX.

                           

                          BTW:  According to information above, even if I use PDPageDrawContentsToWindow on a regular acrobat window, then I still have the problem of being able to access fields but not being able to register field events.

                          • 10. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
                            Patrick Leckey Community Member

                            Sorry Joe, he really should have started a new thread on this...

                             

                            PDPageDrawContentsToWindow is part of the Adobe PDF Library SDK, not part of the Interapplication Communication portion of the Acrobat SDK so it has nothing to do with the ActiveX Reader Control.

                            • 11. Re: C# WINDOWS APP:  EMBED PDF VIEWER WITH FULL LIBRARY
                              MrRamrod Community Member

                              appologies - i should have started another thread.

                              oh, and yes i did mean the Acrobat PDF Library SDK. Sorry for any confusion.

                              -r