12 Replies Latest reply: Jan 24, 2011 6:18 AM by lrosenth RSS

    PRINTING WITH VB6 OR JavaScript

    NonLinearly Community Member

      Hi,

      I am trying to print a pdf document through vb6. I am reading SDK for this purpose that I have downloaded from adobe but I DO NOT UNDERSTAND ANYTHING. The content is very brief and scrawled. There are no examples and many things are described with incomprehensible way ... VERY BAD DOCUMENTATION... and this is the reason that I came here...

      I want to to do a simple job...

      I want to print a pdf document. Some pages need to be print in tray 1 and other in tray 2 (this is not known in advance and is dynamically determined from a connection to database). I tried to read from SDK documentation but I did not take any conclusion...

      Do not rush to draw conclusions because I am 10 yeas programmer with visual basic 6 and a couple of years with javascript.

      The only solution that I want is in visual basic 6 or Acrobat Javascript (but I did not understand at all the tray selection...It was very poorly documented).

      Also I thought, because tray selection in javascript was very poorly documented, to make 2 printers first with tray 1 and second with tray 2. With this I could alternately print without tray selection but even in this I could not find a good guide in SDK on how to specify a printer...

       

      Thanks

        • 1. Re: PRINTING WITH VB6 OR JavaScript
          lrosenth Adobe Employee

          Are you working with Adobe Acrobat or Adobe Reader?  What version?

           

          The SDK contains many examples, though perhaps not what you are looking for.

           

          Tray selection is not part of the PDF standard nor supported by Acrobat/Reader, except in an "automatic" mode (select tray based on page size).  Any tray selection will need to be by your software controlling the printer directly.  It may also require you to "split" the PDF and send multiple jobs.  (of course, Reader doesn't support splitting - only Acrobat).

           

          You also need to be aware of the EULA for Acrobat & Reader and how they can NOT be used in a server environment.

          • 2. Re: PRINTING WITH VB6 OR JavaScript
            NonLinearly Community Member

            Thanks for your reply...

            I have acrobat pro 8...

            First let's start with simple things..

            Could someone show me an example how can I print programmatically a range of specific pages from a pdf document?

            Let's say that we have a FileName.pdf on C:/FileName.pdf, the printer has the name PrinterName and we want to print pages 5 to 7...

            The code must be in visual basic 6 or/and in acrobat javascript...most things SDK describes them with very very complicated way...And in some cases there is nothing to say...

            About the tray selection I can handle it with creation of two printers... one with tray 1 as the defaulf tray and the second with tray 2...

            But could you send me a code example how can I do tray selection with pagesize? What do you mean? Have to go to the printer and set one tray with A4 and the second tray with other pagesize? But I want A4 in both. How can then I determine the pagesize in code?

            And something else... I did not find "many examples" about this in the SDK 9.1 that I downloaded (for free) from the adobe's site...You are referring to something else...This SDK is horrible...

            All I need is a simple print and it seems that for acrobat this is big project!!! I beleave that there is a way but there is luck of documentation...

             

            Thanks anyway...

            • 3. Re: PRINTING WITH VB6 OR JavaScript
              lrosenth Adobe Employee

              The most flexible option will be the this.printPages() API for JavaScript.  There are some good examples of how to use that (and the associated printParams object) in the SDK documentation.

               

              You can call that from VB using the JSObject, and there is VB sample code for working with the JSObject in the SDK.

               

              If the page sizes are the same - so that's not the reason for tray swap - then the built-in feature won't help.

               

              There is only one SDK - it has sample code, HTML-based documentation and more for the MANY parts of Acrobat.  You want to focus on the IAC (Interapplication Communication) section, which is what VB is about.

              • 4. Re: PRINTING WITH VB6 OR JavaScript
                ReinhardF Community Member

                Hi,

                 

                attached a vbs for hidden printing via js object.

                It may give you a start up.

                 

                HTH, Reinhard

                 

                PrtHidden.vbs

                --------------------------------------------

                fileIn = "C:\Test.pdf"              '' state the full path of the file to open
                set App = CreateObject("AcroExch.App")     '' start Adobe Acrobat
                App.Show                           '' show Acrobat or comment out for hidden mode

                set AVDoc = CreateObject("AcroExch.AVDoc") '' connect to Ac Viewer
                AVDoc.Open fileIn,""              '' Open a file into viewer
                set PDDoc = AVDoc.GetPDDoc             '' Get the Doc opened in the viewer
                set JSO = PDDoc.GetJSObject            '' Connect to Acrobat JS
                JSO.app.alert("Hi, file is open.Press Ok for printing")  '' Display a MsgBox
                'JSO.print("bUI","nStart","nEnd","bSilent","bShrinkToFit",..)
                nEnd=jso.numPages-1 ''nEnd zeroBase
                JSO.print False,0,nEnd,False,True   '' print with some options
                JSO.closeDoc(True)

                App.CloseAllDocs                  '' close all docs
                App.exit

                • 5. Re: PRINTING WITH VB6 OR JavaScript
                  NonLinearly Community Member

                  ReinhardF, thanks for your reply, it was helpful but I didn't see where the printer is determined? If there is not such option the code is useless because I need to change the printer according to a flag that is dynamically obtained  through an iteration from a connection to a database table.

                  If this code print to the default printer then can I alternately change the default printer using windows API?

                  Thanks...

                  • 6. Re: PRINTING WITH VB6 OR JavaScript
                    lrosenth Adobe Employee

                    You can set the printer via the printParams object.

                     

                    Have you read the documentation on that object yet?

                    • 7. Re: PRINTING WITH VB6 OR JavaScript
                      ReinhardF Community Member

                      Hi,

                       

                      have a look at the printParams you can find in AcroJs help at: http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp/wwhelp/wwhimpl/js/html/wwhelp.ht m?&accessible=true

                       

                      The IAC JSO presents the doc/this js object.

                      Attached the example, which prints to a specific printer using the printParams.

                       

                      HTH, Reinhard

                       

                      PrintToNamedPrinter.vbs

                      '--------------------------------------------

                       

                      fileIn = "C:\Test.pdf"              '' state the full path of the file to open
                      set App = CreateObject("AcroExch.App")     '' start Adobe Acrobat
                      App.Show                           '' show Acrobat or comment out for hidden mode

                      set AVDoc = CreateObject("AcroExch.AVDoc") '' connect to Ac Viewer
                      AVDoc.Open fileIn,""              '' Open a file into viewer
                      set PDDoc = AVDoc.GetPDDoc             '' Get the Doc opened in the viewer
                      set JSO = PDDoc.GetJSObject            '' Connect to Acrobat JS
                      JSO.app.alert("Hi, file is open.Press Ok for printing")  '' Display a MsgBox

                      '//JSO.print("bUI","nStart","nEnd","bSilent","bShrinkToFit","bPrintAsImage","bReverse","bA nnot","bprintParams")
                      endPage = jso.numPages-1 ''nEnd zeroBased
                      set pp = JSO.getPrintParams()  ''contact print parameters
                      pp.printerName = "Kyocera FS-1700+"       ''set a printername
                      JSO.print False,0,endPage,False,True,False,False,True,pp   '' print with some options

                      JSO.closeDoc(True)       '' close the printed doc
                      App.CloseAllDocs           '' - or /and - close all docs
                      App.exit

                      • 8. Re: PRINTING WITH VB6 OR JavaScript
                        mikecj517 Community Member

                        Everyone,

                         

                        Please forgive for hijacking the original post. The code is great but I'm having one issue with it.

                         

                        At the line > jso.Print False, 0, nEnd, False, True '' print with some options

                         

                        I get Run Time Error 438 Object doesn't support this property or method. Is there a specific reference I need to allow the jso.print (or pddoc.print) to occur.

                         

                        Any thoughts on a possible solution.

                         

                        Thanks,

                         

                        MikeCJ

                        • 9. Re: PRINTING WITH VB6 OR JavaScript
                          lrosenth Adobe Employee

                          What version of Acrobat do you have installed?  (and you need Acrobat and not Reader)

                          • 10. Re: PRINTING WITH VB6 OR JavaScript
                            NonLinearly Community Member

                            The case is closed... The acrobat pro does not have the ability to print with dynamic tray selection! Even if I make a second instance of the printer to print alternately then there is a problem... some times pages that print to second instance printer preciding pages that print to first instance and the output does not has the right order...

                            • 11. Re: PRINTING WITH VB6 OR JavaScript
                              mikecj517 Community Member

                              Lrosenth,

                               

                              I apologize for not replying through the forum but I could not find the reply button.

                               

                              In response to your question, Adobe Acrobat 7.0 Professional.

                               

                              Michael Cochran

                              EH&S Manager

                              L-3 Communications Display Systems

                              1355 Bluegrass Lakes Parkway

                              Alpharetta, GA 30004

                              Phone:  770-752-5468

                              Fax:    770-752-5481

                              • 12. Re: PRINTING WITH VB6 OR JavaScript
                                lrosenth Adobe Employee

                                Unfortunately, we no longer support Acrobat 7.