6 Replies Latest reply on Mar 1, 2010 11:27 PM by Neville0

    [JS CS3 Win] Export to PDF then auto-print PDF from Acrobat

    Neville0

      Hello!

       

      I am working on the script that is exporting pages to PDF, and would like to automatically send exported PDF to print from Acrobat.

      I get the scripting part for exporting to PDF, and it's working very well, but I have trouble on the part of the script that tells Acrobat to open the PDF and send it to printer. Script is run from InDesign, so I thought this is right forum to ask.

      The following part of the script is working OK on one computer, but on other two computers with similar configuration (CS3. Windows, Acrobat 8) it doesn't work at all and I can't figure out where is the problem:

       

      var printFile = "/c/temp/test.pdf";
      var remoteScript = "printFile = decodeURI('"+printFile+"');\n";
      remoteScript += "var doc = app.openDoc({cPath: printFile});\n";
      remoteScript += "var pp = doc.getPrintParams();\n";
      remoteScript += "pp.pageHandling = pp.constants.handling.shrink;\n";
      remoteScript += "pp.NumCopies = 2;\n";
      remoteScript += "pp.interactive = pp.constants.interactionLevel.silent;\n";
      remoteScript += "pp.printerName = '\\\\hrhqzgw23prn01\\\hr300019ps';\n";
      remoteScript += "doc.print(pp);\n";
      remoteScript += "doc.closeDoc(true);";
      acrobat.executeScript(remoteScript);
      

       

      I would appreciate any help. thank you.

        • 1. Re: [JS CS3 Win] Export to PDF then auto-print PDF from Acrobat
          Kasyan Servetsky Level 5

          You can do this via BridgeTalk -- that is export pdf file from InDesign, and then send acrobat script in BridgeTalk message.

          At least, when I was playing with acrobat scripting, I was able to run an acrobat script from ID, which opened a pdf file, printed it to the default printer and closed it without saving.

           

          Kasyan

          • 2. Re: [JS CS3 Win] Export to PDF then auto-print PDF from Acrobat
            Muppet Mark Level 5

            Kasyan, any chance I could see a sample of how you were able to do this. I have not been able to get Acrobat to respond to a BridgeTalk message. Normally any bt message will launch the app if its not already running and I can't even get that far!!! Im using CS2 if that makes any difference? In ESTK data browser 'acrobat' is not listed in 'apps' Array does that mean Im not able to communicate with this? Thanks…

            • 3. Re: [JS CS3 Win] Export to PDF then auto-print PDF from Acrobat
              Kasyan Servetsky Level 5

              Hi Mark,

               

              I'll post the sample code a little bit later — it's somewhere on another computer and I have to find it. It worked for me on InDesign CS3 and Acrobat 8 for Windows — not sure if it would work in CS2. Acrobat is not listed in CS3's ESTK as well, but it works anyway (that was a big surprise for me). There was a client that asked me to write a script that would export pdf files from ID, then open them in Acrobat, print and  close them without saving. I started studying Acrobat scripting — btw, it's a very interesting subject. However the client abandoned his plans soon and I had to stop exploring this.

               

              Application specifiers section of Interapplication Communication with Scripts chapter   in JS Tools Guide contains an impressive list of applications, acrobat is among them. This gave me the idea that theoretically it should work — and it did work in practice.

               

              Regards,

              Kasyan

              • 4. Re: [JS CS3 Win] Export to PDF then auto-print PDF from Acrobat
                Kasyan Servetsky Level 5

                Hi Mark,

                 

                Here is a sample script. It exports the active InDesign document to pdf file, using its base name, to the root of C drive. Then opens the exported file in Acrobat, prints it to the default printer and silently closes it.
                Tested on InDesign 5.0.3, Acrobat 8.0.0, Windows XP SP3.

                 

                #target indesign

                var myIndesignDoc = app.activeDocument;

                var myBaseName = GetFileNameOnly(myIndesignDoc.name);

                var myFile = new File( "/C/" + myBaseName + ".pdf" );

                myIndesignDoc.exportFile( ExportFormat.pdfType, myFile, false );

                 

                var myScript = 'var myAcrobatDoc = app.openDoc( "/C/' + myBaseName + '.pdf" );\n';

                myScript += 'myAcrobatDoc.print( {bUI: false, bSilent: true} );\n';

                myScript += 'myAcrobatDoc.closeDoc( true );';

                var bt = new BridgeTalk;

                bt.target = "acrobat";

                bt.body = myScript;

                bt.send();

                 

                function GetFileNameOnly(myFileName) {

                    var myString = "";

                    var myResult = myFileName.lastIndexOf(".");

                    if (myResult == -1) {

                        myString = myFileName;

                    }

                    else {

                        myString = myFileName.substr(0, myResult);

                    }

                    return myString;

                }

                 

                Short explanation of the acrobat script:


                1. Open the pdf file, just exported from InDesign
                var myAcrobatDoc = app.openDoc( "/C/' + myBaseName + '.pdf" );

                 

                2. To print the document silently I use the doc object’s print method and set the following parameters:
                bUI -- Determines whether to present a user interface to the user
                bSilent -- Suppresses the Cancel dialog box while the document is printed
                myAcrobatDoc.print( {bUI: false, bSilent: true} );

                 

                3. Close the document without notifying the user:
                myAcrobatDoc.closeDoc( true );

                 

                Regards,

                Kasyan

                • 5. Re: [JS CS3 Win] Export to PDF then auto-print PDF from Acrobat
                  Muppet Mark Level 5

                  Kasyan, firstly thanks for posting you sample script. I won't get about looking at this until later (after workday). At a quick glance I don't see anything different in the approach with the exception of my mac os file file paths. I will need take a look at the guides for later suite versioning to see if changes were made. My aim was to add extra menus to Bridge for things I process by script on a regular basis. This I have been able to do for both PS & AI. ID (Im still very much at the beginning of learning to script as I switched to this app much later on) and Acrobat were next on the list. I saw 'acrobat' listed in the namespaces so I was hopeful I could utilize this. I will let you know how I get on if at all… Might just end up on my list of reasons to upgrade… I would doubt its an os related issue.

                  • 6. Re: [JS CS3 Win] Export to PDF then auto-print PDF from Acrobat
                    Neville0 Level 1

                    Yes it's working fine... Thanks.

                    The reason it isn't working for me all the times is because if the pdf filename has any non-ascii characters, acrobat won't open it...

                    I solved this with decodeURI() function in bt message.

                     

                    myScript = "myFile = decodeURI('"+myPDFfile+"');" + "\r"
                    + "var doc = app.openDoc({cPath: myFile});"; ...