35 Replies Latest reply on Jan 15, 2017 11:56 AM by Karl Heinz Kremer

    How can I save PDF as single page TIFF's, or JPEG's

    OzSanta2

      I have been saving single pages of PDF's using the GUI, but it would be much faster to use Java.

       

      I  can't work out how to set the save path, and I also need error trap any failed TIFFS, and save as JPEG's instead. Acrobat won't save TIFFS larger than the international size. Also need to increment each file name to match the page number, please.

       

      So far, I've got...

       

      set tAT to POSIX path of ((path to desktop as text) & "Temporary Acrobat TIFFS")

      tell application "Adobe Acrobat"

        activate

        tell document 1

        set theTempName to name of document 1

        set Params to ""

        set Params to Params & "var dEnd = (this.numPages-1);" & return as text

        set Params to Params & "this.extractPages(0,dEnd);" & return as text

        set Params to Params & "var cFlName = this.documentFileName ;" & return as text

        set Params to Params & "save to :   ((path to desktop as text) + \"Temporary Acrobat TIFFS\"   + \":\"+ cFlName) using: \".tiff\";" & return --< this fails, correct format needed.

        #set Params to Params & "var this.closeDoc(false);"   as text

       

        do script Params

        end tell

      end tell

       

        • 1. Re: How can I save PDF as single page TIFF's, or JPEG's
          Karl Heinz Kremer Adobe Community Professional

          This is not Java, which also would not be supported by Acrobat, it's also not JavaScript, which is a supported language within Acrobat, it's actually AppleScript.

           

          Can you please tell us what the script is not doing correctly. What are you expecting, and what is the script doing?

          • 2. Re: How can I save PDF as single page TIFF's, or JPEG's
            OzSanta2 Level 1

            G'day from there land of Oz, Karl.

             

            What I am trying to do is save each individual page of a PDF, as a separate document, as a TIFF, and also it must be 'trimmed' of excess graphics, to the crop box. I then re-open the cropped TIFF in Acrobat,( which it opens as a PDF), enlarge the top of the document, and add 4 text boxes, 2 with barcodes, then print and save the amended page.

             

            Ate the moment, I'm using the Graphics User Interface in the 'save As' dialog box to save the PDF as TIFFS, and it trims each page to it's crop box. But it's slow, and I need to speed up the process.

             

            The handler above is the accepted method of creating a 'Java Script' within Applescript, and calling the compiled script. I have a long way to go yet, but I need to get the 'save to:' path right. The correct terms are eluding me. I'm a complete Novice at Java.

             

            I want to use the above to check if the 'Save' trims to the crop box, first.

             

            Thanks for you interest.

             

            Santa (aka Brian Christmas)

             

            PS, Here a handler I use to add dialog boxes in Acrobat

             

            # This handler uses Java Script

              #

              on Add_WaterMarkText_(temp)

              try

              local cName, cText, cFont, nFontSize, nS, nE, nTA, nHorizontalAlignment, nVerticalAlignment, nHorizontalWidth, nVerticalHeight, nR, currentPage

             

              set p to 1

              set {cName, cText, cFont, nFontSize, nS, nE, nTA, nHorizontalAlignment, nVerticalAlignment, nHorizontalWidth, nVerticalHeight, nR, currentPage} to temp as list

              set p to 2

              set Params to "" as text

              set p to 3

              set Params to Params & "var f = this.addField(\"" & cName & "\", " & "\"" & "text" & "\", " & currentPage - 1 & ", [" & nHorizontalAlignment & ", " & nVerticalAlignment & ", " & nHorizontalAlignment + nHorizontalWidth & ", " & nVerticalAlignment - nVerticalHeight & "]" & ");" & return as text

              set p to 4

              set Params to Params & "f.value = \"" & cText & "\";" & return as text

              set p to 5

              set Params to Params & "f.userName = \"" & cName & "\";" & return as text

              set p to 6

              set Params to Params & "f.textSize = " & nFontSize & ";" & return as text

              set p to 7

              set Params to Params & "f.textFont =  \"" & cFont & "\";" & return as text

              set p to 8

              set Params to Params & "f.alignment = \"" & "left" & "\";" & return as text

              set p to 9

              set Params to Params & "f.multiline = false;" & return as text

              set p to 10

              set Params to Params & "f.lineWidth = 0;" & return as text

              set p to 11

              set Params to Params & "f.display = display.visible;" & return as text

              set p to 12

              set Params to Params & "f.textColor = color.black;" & return as text

              # set javaScript to Params

              on error errmsg

              set temp to "Add_WaterMarkText error " & errmsg & " Text is " & cText as text

              my writeFile4("MMErrorsList", (temp & return & return as text))

              tell application "System Events" to display dialog temp giving up after 20

              # if RunForOz then tell application "System Events" to display dialog temp giving up after 36000

              end try

              return Params as text

              end Add_WaterMarkText_

            • 3. Re: How can I save PDF as single page TIFF's, or JPEG's
              Karl Heinz Kremer Adobe Community Professional

              Let's take the AppleScript out of the equation. What is the JavaScript you are trying to run?

              • 4. Re: How can I save PDF as single page TIFF's, or JPEG's
                OzSanta2 Level 1

                My main programming language is Applescript, so I need to run any Javascript THROUGH Applescript.

                 

                However, the Java script I need is to save the already opened or focused page of an open Acrobat PDF,  to a desktop folder called 'Temporary Acrobat TIFFS', and save each page as the original document name with the page number included.

                 

                I HAVE to cycle through each page of the PDF using Applescript so I can trim each page to it's crop box, or media box if there is no crop box set. While the trimmed page is open, or focussed, in a loop, I need to save the referred page as a single paged PDF document, as above.

                • 5. Re: How can I save PDF as single page TIFF's, or JPEG's
                  Test Screen Name Most Valuable Participant

                  So... What JavScript are you trying to run? Your code makes a JavaScript string and runs it. Please don't expect us to become AppleScript experts to work out that string. Please copy and paste real strings. Also please copy and paste what it says in the JavaScript console after failing.

                  • 6. Re: How can I save PDF as single page TIFF's, or JPEG's
                    OzSanta2 Level 1

                    Thank you people.

                     

                    I WISH  I could write the Java code. What I use is what I find on the net, that is usually as a add-on to Applescript. If I could write Java script, I wouldn't probably be HERE.

                     

                    I'm trying to save individual pages of PDF's, from Acrobat, on a Mac. I've found information that states this can be done with Java Script, and found a handler on-line that was an Applescript Java handler, so I tried to use it.

                     

                    As I put int my VERY FIRST POST, it fails on the line (which I myself added)...

                     

                      set Params to Params & "save to :   ((path to desktop as text) + \"Temporary Acrobat TIFFS\"   + \":\"+ cFlName) using: \".tiff\";" & return --< this fails, correct format needed.

                     

                    I am asking for the correct way to set this above path in Java, not complete scripts, nor advice for me to supply a complete non-Applescript Java-script. It fails with an error message that is something like 'save fails to understand'.

                     

                    While I thank you for your responses (at least you seem to have read, but not understood, my post), if you don't know the answer, perhaps you could refer me to a site that WOULD be willing to help, without all the free, but useless, advice.

                     

                    Regards

                     

                    Santa

                    • 7. Re: How can I save PDF as single page TIFF's, or JPEG's
                      OzSanta2 Level 1

                      I’ve been avidly researching JavaScript, and think I have a solution that SHOULD work (but darnwell errors).

                       

                      It uses a POSIX path, but gives an error      error "The variable i is not defined." number -2753 from "i”     

                       

                      This error occurrs in the save line, where the ‘& (i + 1) &” is located.

                       

                      Also, it’s as tho the variable dEnd isn’t being set. The line    set Params to Params & "alert(dEnd );" & return as text     does nothing.

                       

                      The command 'this.numPages’ still seems to be valid in 2017, so I’m presuming somehow the script needs to address or ‘lock on’ to the document, but cannot find anything, and I’ve searched for quite a while.

                       

                      Regards

                       

                      Santa

                       

                       

                           tell application "Adobe Acrobat"

                       

                        activate

                        #tell document 1

                        set Params to ""

                        set Params to Params & "var cFlName = this.documentFileName;" & return as text

                        set Params to Params & "var dEnd =  this.numPages-1;" & return as text

                        set Params to Params & "alert(dEnd );" & return as text

                        set Params to Params & "for (i = 0; i <= dEnd-1; i+ );" & return & "{"

                        set Params to Params & "var oNewDoc = this.extractPages(i,i);" & return as text

                        set Params to Params & "oNewDoc.saveAs : ~/Desktop" & "/" & "\"" & "Temporary Acrobat TIFFS" & "\"" & "/" & "\"Page " & "\"" & (i + 1) & " \"" & "\"" & cFlName & "\"" & " using: " & "\"" & ".pdf" & "\"; " & return & "}" as text

                        set Params to Params & "var this.closeDoc(false);" as text

                        do script Params

                        #end tell

                      end tell

                      • 8. Re: How can I save PDF as single page TIFF's, or JPEG's
                        Test Screen Name Most Valuable Participant

                        You could do worse than the Acrobat JavaScript forum. My advice: don't show the AppleScript. it won't be understood. It will be a distraction from what you really need to know. Tell us the specific value of Params when you run Do Script Params. Never mind that it's wrong, it's a starting point. Tell us (copy and paste don't paraphrase!) the console error.

                        • 9. Re: How can I save PDF as single page TIFF's, or JPEG's
                          OzSanta2 Level 1

                          OK, I give in.

                           

                          Here's the best I can do showing the Java Script without any Applescript added. I don't know if the script is exactly right, cause I know stuff all about Java Script formatting, but the error I get is...error "The variable i is not defined." number -2753 from "i” and it occurs in the saveAs line

                           

                          var cFlName = this.documentFileName;

                          var dEnd =  this.numPages-1;

                          alert(dEnd );

                          for (i = 0; i <= dEnd-1; i+ );

                          {

                          var oNewDoc = this.extractPages(i,i);

                          oNewDoc.saveAs : “~/Desktop" & "/" & "\"" & "Temporary Acrobat TIFFS" & "\"" & "/" & "\"Page " & "\"" & (i + 1) & " \"" & "\"" & cFlName & "\"" & " using: " & "\"" & ".pdf" & "\"; "

                          }

                          • 10. Re: How can I save PDF as single page TIFF's, or JPEG's
                            try67 MVP & Adobe Community Professional

                            There are a lot of errors in your code. You need to first of all study the code JS syntax and then the Acrobat-specific methods and properties that you want to use.

                            You can't use AS syntax in your JS code. That's just not going to work.

                            You also need to find out the correct file-path syntax for your files. The best way to do that is to open a PDF from that folder in Acrobat and then execute this command in the JS Console:

                             

                            this.path;
                            

                             

                            It will print out that file's full path, in the syntax that you must use in your code.

                            Let's say that path is "/Desktop/". In that case, the code above should be changed to something like this:

                             

                            var outputPath = "/Desktop/";
                            var originalDoc = this;
                            var cFlName = originalDoc.documentFileName;
                            var dEnd = originalDoc.numPages;
                            for (i=0; i<dEnd; i++) {
                                var oNewDoc = originalDoc.extractPages(i,i);
                                oNewDoc.saveAs({cPath: outputPath + "Page " + (i+1) + " of " + cFlName + ".tiff", cConvID: "com.adobe.acrobat.tiff"});
                                oNewDoc.closeDoc(true);
                            }
                            

                             

                            Edit: Made some minor fixes to the code

                            • 11. Re: How can I save PDF as single page TIFF's, or JPEG's
                              Test Screen Name Most Valuable Participant

                              No, but you can use AppleScript syntax in AppleScript. And then use DO SCRIPT to run the appropriate JavaScript. Rarely done but the Windows equivalent (VB/VBScript running JavaScript fragments) is often seen.

                               

                              I agree that filename syntax is crucial and may be unexpected (being neither the HFS nor the UTF-8 name).

                               

                              I hope the original poster will do as I asked and show the string passed to DO SCRIPT. I'm not going to try to guess what the AppleScript does, I used to use AppleScript and I know that what you get is rarely what you expect.

                              • 12. Re: How can I save PDF as single page TIFF's, or JPEG's
                                OzSanta2 Level 1

                                Thank you TRY67, at last something I can get my teeth into.

                                 

                                The Applescript version produces a file as below. (after all the /// 's indicating quote marks are removed)

                                 

                                On the Java console, it Errors in line 6, Syntax error 5 (coloured blue.)

                                 

                                The second line does NOT produce any output, don’t know why??? There's a 2 page document open.

                                 

                                Regards

                                 

                                Santa

                                 

                                 

                                var dEnd =  this.numPages - 1;

                                 

                                alert(dEnd);

                                var cFlName = this.documentFileName;

                                var outputPath =  "/Desktop/"  ;

                                var outputPathTwo = outputPath & "Temporary Acrobat TIFFS"/;

                                for (i = 0; i <  dEnd ; i++ )

                                {

                                var oNewDoc = this.extractPages(i,i);

                                oNewDoc.saveAs({cPath: outputPathTwo  + "Page "+ (i + 1) +  " of " + cFlName + ".pdf", cConvID: "com.adobe.acrobat.pdf"});

                                }

                                 

                                 

                                 

                                 

                                When I run the actual Applescript version, I get a different error…

                                 

                                Keep in mind "\"" represents a quotation mark in the built up text string.

                                 

                                 

                                error "Adobe Acrobat got an error: \"var dEnd =  this.numPages - 1;

                                 

                                alert(dEnd);

                                var cFlName = this.documentFileName;

                                var outputPath = \\\"/Desktop/\\\"  ;

                                var outputPathTwo = outputPath & \\\"Temporary Acrobat TIFFS\\\"/;

                                for (i = 0; i <  dEnd ; i++ );

                                {

                                var oNewDoc = this.extractPages(i,i);

                                oNewDoc.saveAs({cPath: outputPathTwo  + \\\"Page \\\"+ (i + 1) +  \\\" of \\\" + cFlName + \\\".pdf\\\", cConvID:\\\"com.adobe.acrobat.pdf\\\"});

                                }\" doesn’t understand the “do script” message." number -1708 from "var dEnd =  this.numPages - 1;

                                alert(dEnd);

                                var cFlName = this.documentFileName;

                                var outputPath = \"/Desktop/\"  ;

                                var outputPathTwo = outputPath & \"Temporary Acrobat TIFFS\"/;

                                for (i = 0; i <  dEnd ; i++ );

                                {

                                var oNewDoc = this.extractPages(i,i);

                                oNewDoc.saveAs({cPath: outputPathTwo  + \"Page \"+ (i + 1) +  \" of \" + cFlName + \".pdf\", cConvID:\"com.adobe.acrobat.pdf\"});

                                }”

                                 

                                 

                                tell application "Adobe Acrobat"

                                 

                                  activate

                                  tell document 1

                                  set Params to ""

                                  set Params to Params & "var dEnd =  this.numPages - 1;" & return

                                  set Params to Params & "alert(dEnd);" & return

                                  set Params to Params & "var cFlName = this.documentFileName;" & return

                                  set Params to Params & "var outputPath = " & "\"" & "/Desktop/" & "\"  ;" & return

                                  set Params to Params & "var outputPathTwo = outputPath & " & "\"" & "Temporary Acrobat TIFFS" & "\"" & "/;" & return

                                  set Params to Params & "for (i = 0; i <  dEnd ; i++ )" & return & "{" & return

                                  set Params to Params & "var oNewDoc = this.extractPages(i,i);" & return

                                  set Params to Params & "oNewDoc.saveAs({cPath: outputPathTwo  + " & "\"" & "Page " & "\"" & "+ (i + 1) + " & " \"" & " of " & "\"" & " + cFlName + " & "\"" & ".pdf" & "\"" & ", cConvID:" & "\"" & "com.adobe.acrobat.pdf" & "\"" & "});" & return & "}"  as text

                                  #set Params to Params & "var this.closeDoc(false);" & return as text

                                  end tell

                                  do script Params

                                end tell

                                 

                                • 13. Re: How can I save PDF as single page TIFF's, or JPEG's
                                  OzSanta2 Level 1

                                  Ohhh, I also tried the 'this.path;' suggestion, and all that was returned was 'this.path;'.

                                   

                                  The two page pdf was opened from the desktop  folder 'Temporary Acrobat TIFFS'.

                                  • 14. Re: How can I save PDF as single page TIFF's, or JPEG's
                                    Karl Heinz Kremer Adobe Community Professional

                                    Step away from the AppleScript Editor and get the JavaScript portion to work in Acrobat first. It's a bad idea to tackle two different things at the same time (debugging both JavaScript and the wrapping of JavaScript in your AppleScript). Do one thing at a time and start out by completely forgetting about AppleScript and focus on the JavaScript.

                                     

                                    Here is a tutorial about how to use the JavaScript console in Acrobat: https://acrobatusers.com/tutorials/javascript_console

                                     

                                    To get this to work, you will need to understand how JavaScript works, there is no way around this. You cannot copy&paste your way to a solution by finding snippets online and using them without a good understanding of how they work and more importantly in what way you need to modify them to fit your exact problem. If you want to know how to best approach learning about Javascript for Acrobat, take a look here: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

                                     

                                    Now let's take a look at your JavaScript. I assume the script that Acrobat tries to execute can be extracted from the error message you received. The first thing I do when I try to analyze JavaScript is to paste it into a JavaScript aware editor that allows me to "pretty print" the script. This way, things like unbalanced braces or parenthesis show up right away. When I do this with your script, I get this:

                                     

                                    var dEnd = this.numPages - 1;
                                    alert(dEnd);
                                    var cFlName = this.documentFileName;
                                    var outputPath = \"/Desktop/\"  ;
                                    var outputPathTwo = outputPath & \"Temporary Acrobat TIFFS\"/;
                                    for (i = 0; i < dEnd; i++); {
                                      var oNewDoc = this.extractPages(i, i);
                                      oNewDoc.saveAs({
                                      cPath: outputPathTwo + \"Page \"+ (i + 1) +  \" of \" + cFlName + \".pdf\", cConvID:\"com.adobe.acrobat.pdf\"});
                                      }
                                    

                                    As you can see, there is a problem at the end where something looks unbalanced, and a some closer look (and this is where you need to know about the JavaScript syntax, otherwise you will not be able to spot that - I noticed that you over-escaped your quotes that mark the beginning and end of strings. After fixing that, and adding the extra "/" at the end of like 5 to the string, and changing '&' in that line to '+', I end up with this:

                                     

                                    var dEnd = this.numPages - 1;
                                    alert(dEnd);
                                    var cFlName = this.documentFileName;
                                    var outputPath = "/Users/username/Desktop/";
                                    var outputPathTwo = outputPath + "Temporary Acrobat TIFFS/";
                                    for (i = 0; i < dEnd; i++); {
                                      var oNewDoc = this.extractPages(i, i);
                                      oNewDoc.saveAs({
                                        cPath: outputPathTwo + "Page " + (i + 1) + " of " + cFlName + ".pdf",
                                        cConvID: "com.adobe.acrobat.pdf"
                                      });
                                    }
                                    

                                    Much better looking and also balanced. However, when I run this in the console, I get an error:

                                     

                                    ReferenceError: alert is not defined
                                    2:Console:Exec
                                    

                                    And again this is no surprise, because "alert()" is a valid JavaScript command in a web browser environment, but not in Acrobat. You need to replace that with "app.alert()". After fixing this, we get a bit further, but still end up with an error message:

                                     

                                    UnsupportedValueError: Value is unsupported. ===> Parameter cConvID.
                                    Doc.saveAs:10:Console undefined:Exec
                                    

                                    Here you need to know that there is actually no conversion type of "com.adobe.acrobat.pdf" because PDF is the default if you do not specify any other type (see here for more information, you actually have to display the conversion types on the console to get the full list: Acrobat DC SDK Documentation)

                                     

                                    As you can see, there are lots of steps involved that you cannot really debug within AppleScript, and we are not even done yet.

                                    • 15. Re: How can I save PDF as single page TIFF's, or JPEG's
                                      try67 MVP & Adobe Community Professional

                                      Another issue is that you (OzSanta2, not KHK) changed the code I provided from:

                                      var dEnd = this.numPages;

                                      To:

                                      var dEnd = this.numPages - 1;

                                      This means that the script would skip the last page of the file.

                                       

                                      Do not make changes unless you understand what they mean!

                                      And keep your code simple. Get it to work in the most basic way, and then start adding new functions to it. When it breaks you then know what might have triggered it (your latest changes). And of course, study the relevant literature and reference. Without them it's a wild-goose chase.

                                      • 16. Re: How can I save PDF as single page TIFF's, or JPEG's
                                        OzSanta2 Level 1

                                        G’day David, and Karl, & try67

                                         

                                        Thank you for your interest, and great help.

                                         

                                        David, (who contacted me off-forum), the line I wrote follows the conventions for writing Jave Script code as an Applescript conversion piece of text.

                                         

                                        I've made some alterations, and tested in the Console.

                                         

                                        tell application "Adobe Acrobat"

                                         

                                          activate

                                          open ((path to desktop as text) & "Brian's Disk Report.pdf") as alias

                                          tell document 1

                                          set Params to ""

                                          set Params to Params & "var dEnd =  this.numPages ;" & return

                                          set Params to Params & "var cFlName = this.documentFileName;" & return

                                          set Params to Params & "var outputPath = " & "\"" & "/Desktop/" & "\"  ;" & return

                                          set Params to Params & "var outputPathTwo = outputPath" & " +  " & "\"" & "Temporary Acrobat TIFFS" & "\"" & "/;" & return

                                          set Params to Params & "app.alert(outputPathTwo);" & return

                                          set Params to Params & "for (i = 0; i <  dEnd ; i++ )" & return & "{" & return

                                          set Params to Params & "var oNewDoc = this.extractPages(i,i);" & return

                                          set Params to Params & "oNewDoc.saveAs({cPath: outputPathTwo  + " & "\"" & "Page " & "\"" & "+ (i + 1) + " & "\"" & " of " & "\"" & " + cFlName + " & "\"" & ".pdf" & "\"" & "});" & return & "}" as text

                                          #set Params to Params & "var this.closeDoc(false);" & return as text

                                          end tell

                                          do script Params

                                        end tell

                                         

                                        The liner  ‘Do Script’ tells Acrobat to execute the listed text as Java, and it strips off single quotes. Any quotes that have to be include in the final Java script ‘as quotes’ must be ‘wrapped' in a pair of quotes, and the single required real quote preceded by a “\”, which indicates the character following must be inserted as a literal character. so “\”” inserts a quotation mark. The rest is wrapped in single quotes, and because it’s Applescript, is concotated with a ‘&’. Any literal ‘+’ are included in any part wrapped in single quotes.

                                         

                                        So, when I run it from the Appliscript Editor, I get an error such as below, which to change to an actual Java script, I simple strip every incident of  ‘\’ from the actual bold part, which is included as the Editor can’t display single quotes without the ‘\"…

                                         

                                         

                                        error "Adobe Acrobat got an error: \"var dEnd =  this.numPages ;

                                         

                                        var cFlName = this.documentFileName;

                                        var outputPath = \\\"/Desktop/\\\"  ;

                                        var outputPathTwo = outputPath +  \\\"Temporary Acrobat TIFFS\\\"/;

                                        app.alert(outputPathTwo);

                                        for (i = 0; i <  dEnd ; i++ )

                                        {

                                        var oNewDoc = this.extractPages(i,i);

                                        oNewDoc.saveAs({cPath: outputPathTwo  + \\\"Page \\\"+ (i + 1) + \\\" of \\\" + cFlName + \\\".pdf\\\"});

                                        }\" doesn’t understand the “do script” message." number -1708 from "var dEnd =  this.numPages ;

                                        var cFlName = this.documentFileName;

                                        var outputPath = \"/Desktop/\"  ;

                                        var outputPathTwo = outputPath +  \"Temporary Acrobat TIFFS\"/;

                                        app.alert(outputPathTwo);

                                        for (i = 0; i <  dEnd ; i++ )

                                        {

                                        var oNewDoc = this.extractPages(i,i);

                                        oNewDoc.saveAs({cPath: outputPathTwo  + \"Page \"+ (i + 1) + \" of \" + cFlName + \".pdf\"});

                                        }

                                         

                                        So I end up with…

                                         

                                         

                                        var dEnd =  this.numPages ;

                                         

                                        var cFlName = this.documentFileName;

                                        var outputPath = "/Desktop/"  ;

                                        var outputPathTwo = outputPath +  "Temporary Acrobat TIFFS"/;

                                        app.alert(outputPathTwo);

                                        for (i = 0; i <  dEnd ; i++ )

                                        {

                                        var oNewDoc = this.extractPages(i,i);

                                        oNewDoc.saveAs({cPath: outputPathTwo  + "Page "+ (i + 1) + " of " + cFlName + ".pdf"});

                                        }”

                                         

                                        In the Java Console, I tried the below, two lines at a time, which worked fine until I added var outputPathTwo = outputPath +  "Temporary Acrobat TIFFS"/;

                                         

                                        I can’t find anything to tell me what I’ve done wrong?

                                         

                                         

                                        var dEnd =  this.numPages;

                                         

                                        app.alert(dEnd)

                                        var cFlName = this.documentFileName;

                                        app.alert(cFlName)

                                        var outputPath = "/Desktop/"  ;

                                        app.alert(outputPath)

                                         

                                        var outputPathTwo = outputPath +  "Temporary Acrobat TIFFS"/;

                                        app.alert(outputPathTwo);

                                         

                                         

                                        SyntaxError: syntax error

                                        7:Console:Exec

                                        undefined

                                         

                                        As well, I have a question, should desktop be "~/Desktop/", or does Java not require the '~'?

                                        Regards

                                        Santa

                                        • 17. Re: How can I save PDF as single page TIFF's, or JPEG's
                                          Karl Heinz Kremer Adobe Community Professional

                                          You did not fix the error that I pointed out before:

                                           

                                          var outputPathTwo = outputPath +  "Temporary Acrobat TIFFS"/;

                                           

                                          The '/' at the end need to be part of the string - meaning between the double-quotes.

                                          • 18. Re: How can I save PDF as single page TIFF's, or JPEG's
                                            OzSanta2 Level 1

                                            G'day Karl

                                             

                                            With all due respect, I don't think you're correct.

                                             

                                            I'm including the Folder "Temporary Acrobat TIFFS" as part of the file path to be saved, so the folder name MUST be in double quotes, followed by the file path separator '/'.

                                             

                                            If I followed your suggestion, I'd be trying to address a folder called

                                             

                                            The Applescript line

                                             

                                            set Params to Params & "var outputPathTwo = outputPath  " & " + \"" & "Temporary Acrobat TIFFS" & "\"" & "/;" & return

                                             

                                            returns, when run as a script, the folder name in quotes, followed by a file path separator...

                                             

                                            var outputPathTwo = outputPath   + \"Temporary Acrobat TIFFS/"/;

                                             

                                            I'm trying to learn about Java, but is my method of using outputPath  correct?

                                             

                                            I've tried your alteration just in case I'm wrong, but that line still errors.

                                             

                                            It just struck me, do you mean the extra '/' must be in it's OWN set of double quotes? As in...

                                             

                                            var outputPathTwo = outputPath   + \"Temporary Acrobat TIFFS" + \"/\";

                                             

                                            Regards

                                             

                                            Santa

                                            • 19. Re: How can I save PDF as single page TIFF's, or JPEG's
                                              OzSanta2 Level 1

                                              G'day again.

                                               

                                              Sorry Karl, vagaries of English. Your recommendation read to me as though you wanted the forward slash to be included in the folder name. Now I've added it in its own quotes, it works, UNTIL it goes to save.

                                               

                                              I'm trying to add a variable to display the path name, but it's erring. I'll keep you posted.

                                               

                                              Regards

                                               

                                              Santa

                                               

                                              tell application "Adobe Acrobat"

                                                activate

                                                open ((path to desktop as text) & "Brian's Disk Report.pdf") as alias

                                                tell document 1

                                                set Params to ""

                                                set Params to Params & "var dEnd =  this.numPages;" & return

                                                set Params to Params & "var cFlName = this.documentFileName;" & return

                                                set Params to Params & "var outputPath  = " & "\"" & "/Desktop/" & "\";" & return

                                                set Params to Params & "var outputPathTwo = outputPath  " & " + \"" & "Temporary Acrobat TIFFS" & "\"" & " + " & "\"" & "/" & "\";" & return

                                                set Params to Params & "app.alert(outputPathTwo);" & return

                                                set Params to Params & "app.alert(cFlName);" & return

                                                set Params to Params & "for (i = 0; i <  dEnd ; i++ )" & return & "{" & return

                                                set Params to Params & "app.alert(i + \" First\");" & return

                                                set Params to Params & "var oNewDoc = this.extractPages(i,i);" & return

                                                set Params to Params & "app.alert(i + \" Second\");" & return

                                                set Params to Params & "oNewDoc.saveAs({cPath: outputPathTwo  + " & "\"" & "Page " & "\"" & " + (i + 1) + " & "\"" & " of " & "\"" & " + cFlName + " & "\"" & ".pdf" & "\"});" & return & "}"

                                                set Params to Params & "var this.closeDoc(false);" & return as text

                                                end tell

                                                do script Params

                                              end tell

                                               

                                               

                                               

                                              error "Adobe Acrobat got an error: \"var dEnd =  this.numPages;

                                              var cFlName = this.documentFileName;

                                              var outputPath  = \\\"/Desktop/\\\";

                                              var outputPathTwo = outputPath   + \\\"Temporary Acrobat TIFFS\\\" + \\\"/\\\";

                                              app.alert(outputPathTwo);

                                              app.alert(cFlName);

                                              for (i = 0; i <  dEnd ; i++ )

                                              {

                                              app.alert(i + \\\" First\\\");

                                              var oNewDoc = this.extractPages(i,i);

                                              app.alert(i + \\\" Second\\\");

                                              oNewDoc.saveAs({cPath: outputPathTwo  + \\\"Page \\\" + (i + 1) + \\\" of \\\" + cFlName + \\\".pdf\\\"});

                                              }var this.closeDoc(false);

                                              \" doesn’t understand the “do script” message." number -1708

                                               

                                              The JavaScript...

                                               

                                              var dEnd =  this.numPages ;

                                              var cFlName = this.documentFileName;

                                              var outputPath  = "/Desktop/"  ;

                                              var outputPathTwo = outputPath   + "Temporary Acrobat TIFFS" + "/";

                                              app.alert(outputPathTwo);

                                              app.alert(cFlName);

                                              for (i = 0; i <  dEnd ; i++ )

                                              {

                                              app.alert(i + “First”);

                                              var oNewDoc = this.extractPages(i,i);

                                              app.alert(i +”Second”); // WORKS

                                              oNewDoc.saveAs({cPath: outputPathTwo  + "Page "+ (i + 1) + " of " + cFlName + ".pdf"});

                                              }"

                                              • 20. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                OzSanta2 Level 1

                                                Well, my script seems to work, except a sort of 'file is locked' error now appears with each different PDF file I try.

                                                 

                                                Any remedies, please?

                                                 

                                                Regards

                                                 

                                                Santa

                                                 

                                                var dEnd =  this.numPages;

                                                var cFlName = this.documentFileName;

                                                var outputPath  = "/Desktop/";

                                                var outputPathTwo = outputPath   + "Temporary Acrobat TIFFS" + "/";

                                                app.alert(outputPathTwo);

                                                app.alert(cFlName);

                                                for (i = 0; i <  dEnd ; i++ ){;

                                                app.alert(i + " First");

                                                var oNewDoc = this.extractPages(i,i);

                                                app.alert(i + " Second");

                                                var tempText =    outputPathTwo  + "Page " + (i + 1) + " of " + cFlName  + ".pdf";

                                                app.alert(tempText); // WORKS TO HERE!

                                                oNewDoc.saveAs({cPath: outputPathTwo  + "Page " + (i + 1) + " of " + cFlName  + ".pdf"});

                                                app.alert(tempText);

                                                };

                                                 

                                                RaiseError: The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.

                                                Doc.saveAs:13:Console undefined:Exec

                                                ===> The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.

                                                undefined

                                                 

                                                HOWEVER, when this line runs, the document adds a second document to window tabs, with the name changing from a (name).pdf to something like "Acr197733150881728-25230132.tmp"

                                                The first tab still contains the document (name).pdf

                                                          set Params to Params & "var oNewDoc = this.extractPages(i,i);" & return as text

                                                 

                                                I'm presuming that line creates a new document, with a temporary name, that represents the page the script is working on. BUT, it appears locked.

                                                • 21. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                  Test Screen Name Most Valuable Participant

                                                  It isn't clear whether you ever verified the path name syntax or whether you've just stuck with /Desktop... In reply 10 /Desktop was used as an example "Let's say it was..."

                                                  • 22. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                    Karl Heinz Kremer Adobe Community Professional

                                                    With all due respect, I don't think you're correct.

                                                    Actually, I am correct. You have this line in your code:

                                                     

                                                    var outputPathTwo = outputPath +  "Temporary Acrobat TIFFS"/;
                                                    
                                                    

                                                    What you are doing here is creating a new variable named "outputPathTwo", which consists of the concatenation of the variable outputPath and a string constant "Temporary Acrobat TIFFS" followed by a stray slash, followed by the end of statement mark ";" - the slash is wrong and causes a syntax error message when executed in the JavaScript console:

                                                     

                                                    SyntaxError: syntax error
                                                    1:Console:Exec
                                                    

                                                     

                                                    The reason for this is that the slash needs to be part of the string that you are using to build your outputPathTwo. It needs to look like this:

                                                     

                                                    var outputPathTwo = outputPath +  "Temporary Acrobat TIFFS/";

                                                     

                                                    And yes, this is different from what you would do in AppleScript, but again, we are not dealing with AppleScript here, this is JavaScript, and all we need is a string, not some variable of some path type. What you ended up doing by wrapping the slash in quotes has the same effect as what I proposed back in this comment: Re: How can I save PDF as single page TIFF's, or JPEG's

                                                     

                                                    As you can see in the second block of code that I posted, in line #5, that's exactly what I did. I also changed line #4 where you define the output path to use "/Users/username/Desktop/" instead of just "/Desktop" - that was because there is no "/Desktop" folder on a Mac - at least not unless you create one. In JavaScript, you will need to use the full path to the folder, the ~ syntax will not work (this is a shell based abbreviation, that gets substituted by the shell to the complete filename or folder name. Because we are not using the shell,  no such substitution will take place.

                                                    • 23. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                      OzSanta2 Level 1

                                                      Thank you Karl.

                                                       

                                                      I did say at the end of my post, that I had a thought you might mens to wrap the '/' in its own quotes, and of course you did. Once I changed my code, viola!. It worked.

                                                       

                                                      Until I tried to save it!!!

                                                       

                                                      I  CAN'T  use "/Users/username/Desktop/" instead of just "/Desktop/" because I don't know the name of the user. It's going to be used an another machine, so I require a versatile path name. Surely there's something in Java that allows this?

                                                       

                                                      There IS a Desktop in MacOS, 'path to desktop as text' is a common used command when accessing the desktop and automatically generates the Desktop path, for the user.

                                                       

                                                      However, is this the reason the new file gives a 'can't save' error?  Or, is the file actually locked?

                                                       

                                                      AND, I have checked the new file path, just before trying to save the referred file. I got up early this morning to read through any  Java Script documentation I could, but could not find answers.

                                                       

                                                      Regards

                                                       

                                                      Santa

                                                      • 24. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                        OzSanta2 Level 1

                                                        Didn't realize I could post screen shots. Here's the screenshot of the path, just before trying to save.

                                                         

                                                        Screen Shot 2017-01-12 at 8.26.14 pm.png

                                                        • 25. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                          Karl Heinz Kremer Adobe Community Professional

                                                          There is no "/Desktop" folder - you need to read exactly what I typed. I did not say that there was no Desktop folder. That's different, and when it comes to programming, these small differences are important. When it comes to Unix paths (or what you refer to as Posix paths in AppleScript), a path that start with a '/' always means that it is in the "root" directory of the disk. What I said was that there is no "Desktop" folder in the root directory, which does not mean that there is no Desktop folder in a user's home directory. Every user on Mac OS does have a Desktop folder, but that is referenced differently (e.g. /Users/username/Desktop).

                                                           

                                                          Take a look at the App.getPath() method: Acrobat DC SDK Documentation

                                                           

                                                          This is all there is in terms of asking Acrobat about user specific (or application specific) paths. Unfortunately, there is no function to get the user's Desktop. There is however a function to get the user's Documents directory, which on a Mac is on the same level as the user's Desktop. This means you could get the Documents directory and then just replace "Documents" with "Desktop":

                                                           

                                                          var pathToDesktop = app.getPath("user", "documents").replace("Documents", "Desktop");
                                                          

                                                           

                                                          This is dangerous, because the next version of Mac OS X could move Documents, or a user could have reconfigured Mac OS X to store Documents in a different location. This is one area where you could use your AppleScript wrapper to your advantage and get the path to the desktop as a Posix path. (e.g. set pp to POSIX path of (path to desktop) as text )

                                                           

                                                          As to why you are getting error when trying to save - until you fix your path problem, it's impossible to say if that is caused by a non-existing folder ("/Desktop") or something else.

                                                          • 26. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                            OzSanta2 Level 1

                                                            Thanks Karl, you're being of immense help.

                                                             

                                                            I've done a LOT of reading about getting desktop paths in Java on Mac, and this is typical of postings that DON'T work.

                                                             

                                                            Script to Create Folders Using Photoshop Scripting Mac/Windows

                                                             

                                                            //Folder to create on the desktop

                                                             

                                                            var folder1 = Folder("~/desktop/My New Folder");

                                                             

                                                            //Check if it exist, if not create it.

                                                             

                                                            if(!folder1.exists) folder1.create();

                                                             

                                                             

                                                            These sort of postings is why I've persisted in asking about desktop paths. But, now, I'll try and pass a variable to my Applescript Java script using your suggestion. BUT, does this mean there's no way to test the code in the Console?

                                                             

                                                            Regards

                                                             

                                                            Santa

                                                            • 27. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                              OzSanta2 Level 1

                                                              THANK YOU KARL.

                                                               

                                                              You're a scholar and a gentleman. That worked a treat, and it's FAST.

                                                               

                                                              Thank you to everyone else who pitched in and helped as well.

                                                               

                                                              Regards

                                                               

                                                              Santa

                                                               

                                                              tell application "Finder" to set pp to (POSIX path of (path to desktop) as text)

                                                              tell application "Adobe Acrobat"

                                                                activate

                                                                open ((path to desktop as text) & "Retainer Invoice.pdf") as alias

                                                                do shell script ("sleep 1")

                                                                tell document 1

                                                                set theScript to my setDrawPages(pp)

                                                                do script theScript

                                                                end tell

                                                               

                                                              end tell

                                                               

                                                              on setDrawPages(pp)

                                                                set Params to ""

                                                                set Params to Params & "var dEnd =  this.numPages;" & return as text

                                                                set Params to Params & "var cFlName = this.documentFileName;" & return as text

                                                                set Params to Params & "var outputPath  = " & "\"" & pp & "\";" & return as text

                                                                set Params to Params & "var outputPathTwo = outputPath  " & " + \"" & "Temporary Acrobat TIFFS" & "\"" & " + " & "\"" & "/" & "\";" & return as text

                                                                set Params to Params & "app.alert(outputPathTwo);" & return as text

                                                                set Params to Params & "app.alert(cFlName);" & return as text

                                                                set Params to Params & "for (i = 0; i <  dEnd ; i++ ){;" & return as text

                                                                set Params to Params & "app.alert(i + \" First\");" & return as text

                                                                set Params to Params & "var oNewDoc = this.extractPages(i,i);" & return as text

                                                                set Params to Params & "app.alert(i + \" Second\");" & return as text

                                                                set Params to Params & "var tempText =    outputPathTwo " & " + " & "\"" & "Page " & "\"" & " + (i + 1) + " & "\"" & " of " & "\"" & " + cFlName" & return as text

                                                                set Params to Params & "app.alert(tempText);" & return as text

                                                                set Params to Params & "oNewDoc.saveAs({cPath: outputPathTwo  + " & "\"" & "Page " & "\"" & " + (i + 1) + " & "\"" & " of " & "\"" & " + cFlName" & "});" & return as text

                                                                set Params to Params & "app.alert(tempText);" & return as text

                                                                set Params to Params & "};" & return as text

                                                                return Params as text

                                                              end setDrawPages

                                                              • 28. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                                Karl Heinz Kremer Adobe Community Professional

                                                                You cannot mix JavaScript from one environment with a different environment: JavaScript in Acrobat runs in a "sandbox" - which means it cannot communicate (or only in a very limited fashion) with the outside world, whereas Javascript in PostScript is free to do whatever it wants (within limits). The reason being that you can store JavaScript in a PDF file and then send it on it's way. You don't want a PDF file that you downloaded from the Internet to mess around with your system. So this is a good thing, but makes a lot of stuff much harder or impossible to do.

                                                                1 person found this helpful
                                                                • 29. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                                  OzSanta2 Level 1

                                                                  Thanks again Karl.

                                                                   

                                                                  One more question if you don't mind.

                                                                   

                                                                  At present, the new files have a name such as (FileName).pdf.tiff.

                                                                   

                                                                  I had to revert to saving as tiffs because saving as pdf's did not 'trim' the whole page to any existing crop box, but saving as tiffs, does.

                                                                   

                                                                  I KNOW I read somewhere that it's possible to set a variable to a file name sans the file extension part, but cannot re-find the article.

                                                                   

                                                                  Do you, (or anyone), know how to get the file name without the file extension, please?

                                                                   

                                                                  Regards

                                                                   

                                                                  Santa

                                                                  • 30. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                                    OzSanta2 Level 1

                                                                    Well, I've passed the file name, sans name extension, to the script. It was working fine, saving TIFFS to the correct folder, & correctly named.

                                                                     

                                                                    BUT, one of the very first problems I struck with one file cropped up, saving to TIFFS can error, and the try trap I was using in the Java Script can't trap it, and neither can Applescript. I solved it in Applescript with a Timeout, then dismissed the resultant two error boxes, and saved the file page as a JPEG.

                                                                     

                                                                    I know ZILCH about doing the same in Java Script, but on reading came across the 'set timeout()' command, but I don't think I'm using it correctly.

                                                                     

                                                                    My Applescript is...

                                                                     

                                                                    on setDrawPages(pp, displayName)

                                                                      say 2

                                                                      set Params to ""

                                                                      set Params to Params & "var dEnd =  this.numPages;" & return as text

                                                                      set Params to Params & "var cFlName = " & "\"" & displayName & "\"" & ";" & return as text

                                                                      set Params to Params & "var outputPath  = " & "\"" & pp & "\";" & return as text

                                                                      set Params to Params & "var outputPathTwo = outputPath  " & " + \"" & "Temporary Acrobat TIFFS" & "\"" & " + " & "\"" & "/" & "\";" & return as text

                                                                      set Params to Params & "for (i = 0; i <  dEnd ; i++ ){;" & return as text

                                                                      set Params to Params & "var oNewDoc = this.extractPages(i,i);" & return as text

                                                                      set Params to Params & "var tempText =    outputPathTwo " & " + " & "\"" & "Page " & "\"" & " + (i + 1) + " & "\"" & " of " & "\"" & " + cFlName;" & return as text

                                                                      set Params to Params & "myVar = setTimeout(jpegFunction, 5000);" & return as text

                                                                      set Params to Params & "oNewDoc.saveAs({cPath: outputPathTwo  + " & "\"" & "Page " & "\"" & " + (i + 1) + " & "\"" & " of " & "\"" & " + cFlName + " & "\"" & ".tiff" & "\"" & ", cConvID:" & "\"" & "com.adobe.acrobat.tiff" & "\"" & "});" & return as text

                                                                      set Params to Params & "clearTimeout(myVar);" & return as text

                                                                      set Params to Params & "function  jpegFunction(oNewDoc.saveAs({cPath: outputPathTwo  + " & "\"" & "Page " & "\"" & " + (i + 1) + " & "\"" & " of " & "\"" & " + cFlName + " & "\"" & ".jpeg" & "\"" & ", cConvID:" & "\"" & "com.adobe.acrobat.jpeg" & "\"" & "}));" & return as text

                                                                      set Params to Params & "};" & return as text

                                                                      tell application "System Events" to display dialog Params as text

                                                                      say 3

                                                                      return Params as text

                                                                    end setDrawPages

                                                                     

                                                                     

                                                                     

                                                                    The code this produces is in this left screen shot, and a screen shot of the error follows...

                                                                    Screen Shot 2017-01-13 at 10.10.32 pm.png   Screen Shot 2017-01-13 at 10.10.39 pm.png

                                                                    The Console shows...

                                                                     

                                                                    SyntaxError: missing ) after formal parameters

                                                                    10:

                                                                     

                                                                    Which would indicate to me there's a mistake in my code, but I can't see where? I've mucked about for hours, but don't know what the heck I'm doing. Can anyone help point out the error? And am I using the timeout correctly with the function?

                                                                     

                                                                    Regards

                                                                     

                                                                    Santa

                                                                    • 31. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                                      OzSanta2 Level 1

                                                                      Darn it, I've been chasing shadows.

                                                                       

                                                                      The setTimeout does NOT work in Acrobat.

                                                                       

                                                                      I HAVE to save as TIFFS. It's the only format that will trim Acrobat pages to any crop boxes with coding. JPEG is for emergencies.

                                                                       

                                                                      Does anyone know of a way I can trap that darn error? It's occurring in the actual JavaScript, and I can't use Applescript to deal with it.

                                                                       

                                                                      Using Java cuts the save time dramatically.

                                                                       

                                                                      Regards

                                                                       

                                                                      Santa

                                                                       

                                                                      Here's my Applescript code.

                                                                       

                                                                      property PreserveFileName : ""

                                                                      property theItem : ""

                                                                       

                                                                       

                                                                      tell application "Finder"

                                                                        set pp to (POSIX path of (path to desktop) as text)

                                                                        set thefile to file ((path to desktop as text) & "Problem PDF.pdf") as alias as text

                                                                      end tell

                                                                      set my theItem to thefile

                                                                      try

                                                                        tell application "Finder" to set my PreserveFileName to name of file (my theItem) as text

                                                                      on error errmsg number errnum

                                                                        my sayTheText:("Acrobat error setting file name")

                                                                      end try

                                                                      tell application "Finder"

                                                                        set pp to (POSIX path of (path to desktop) as text)

                                                                        set p to 101.2

                                                                        set tempEXT to name extension of file (my theItem)

                                                                        set p to 101.3

                                                                        set displayName to (characters 1 through -((count of tempEXT) + 2) of my PreserveFileName) as text

                                                                      end tell

                                                                      tell application "Adobe Acrobat"

                                                                        activate

                                                                        open thefile as alias

                                                                        tell document 1

                                                                        say 1

                                                                        set theScript to my setDrawPages(pp, displayName)

                                                                        try

                                                                        say 4

                                                                        do script theScript

                                                                        say 5

                                                                        on error errmsg

                                                                        tell application "System Events" to display dialog errmsg

                                                                        end try

                                                                        end tell

                                                                      end tell

                                                                       

                                                                      on setDrawPages(pp, displayName)

                                                                        say 2

                                                                        set Params to ""

                                                                        set Params to Params & "var dEnd =  this.numPages;" & return as text

                                                                        set Params to Params & "var cFlName = " & "\"" & displayName & "\"" & ";" & return as text

                                                                        set Params to Params & "var outputPath  = " & "\"" & pp & "\";" & return as text

                                                                        set Params to Params & "var outputPathTwo = outputPath  " & " + \"" & "Temporary Acrobat TIFFS" & "\"" & " + " & "\"" & "/" & "\";" & return as text

                                                                        set Params to Params & "for (i = 0; i <  dEnd ; i++ ){;" & return as text

                                                                        set Params to Params & "var oNewDoc = this.extractPages(i,i);" & return as text

                                                                        set Params to Params & "var tempText = outputPathTwo " & " + " & "\"" & "Page " & "\"" & " + (i + 1) + " & "\"" & " of " & "\"" & " + cFlName;" & return as text

                                                                        set Params to Params & "try {" & return as text

                                                                        set Params to Params & "oNewDoc.saveAs({cPath: outputPathTwo  + " & "\"" & "Page " & "\"" & " + (i + 1) + " & "\"" & " of " & "\"" & " + cFlName + " & "\"" & ".tiff" & "\"" & ", cConvID:" & "\"" & "com.adobe.acrobat.tiff" & "\"" & "});" & return as text

                                                                        set Params to Params & "}" & return

                                                                        set Params to Params & "catch(err) {" & return

                                                                        set Params to Params & "app.alert(err);" & return as text

                                                                        set Params to Params & "oNewDoc.saveAs({cPath: outputPathTwo  + " & "\"" & "Page " & "\"" & " + (i + 1) + " & "\"" & " of " & "\"" & " + cFlName + " & "\"" & ".jpeg" & "\"" & ", cConvID:" & "\"" & "com.adobe.acrobat.jpeg" & "\"" & "});" & return

                                                                        set Params to Params & "}" & return

                                                                        set Params to Params & "};" & return as text

                                                                        tell application "System Events" to display dialog Params as text

                                                                        say 3

                                                                        return Params as text

                                                                      end setDrawPages

                                                                       

                                                                      Here's the screen capture of the actual code.

                                                                       

                                                                      Screen Shot 2017-01-14 at 12.21.10 am.png

                                                                       

                                                                      Here's the two consecutive errors, which have to be dismissed manually. Everything MUST be automatic. Cropping and reducing resolution don't work. I need to now save as a JPEG, after the error.

                                                                       

                                                                      Screen Shot 2017-01-14 at 12.14.14 am.pngScreen Shot 2017-01-14 at 12.15.14 am.png

                                                                      • 32. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                                        Karl Heinz Kremer Adobe Community Professional

                                                                        Even though you found a way to get around this, here is how you would get rid of the ".pdf" in the filename. I've already introduced you to the String.replace() method when we talked about how to get the path to the user's Desktop folder. You would use the same approach here, but replace with an empty string. In this case however, the simple replace may not work because you may have something like filename.pdf.pdf and when you run "filename.pdf.aaa.pdf".replace(".pdf", "") (yes, you can do this in JavaScript), you will end up with "filename.aaa.pdf" - it only replaced one - the first instance - of the ".pdf"s in the name. You very likely want to replace the actual extension, which would be the last instance of ".pdf". This is where you would use regular expressions to identify the actual file extension:

                                                                         

                                                                        var cFlName = this.documentFileName;
                                                                        cFlName = cFlName.replace(/.pdf$/i, "");
                                                                        

                                                                        This will find the ".pdf" which is directly followed by the end of the string, regardless of the case (e.g. .pdf and .PDF are both found, as would be .PdF) and replaces it with the empty string .

                                                                         

                                                                        As far as your second problem goes, there is nothing you can do in JavaScript to get around this problem: Acrobat's automation interface is not meant for "lights out" operation, it assumes that somebody is sitting in front of the screen and reads error messages and clicks on the "OK" button when such an error occurs. The condition you are encountering is handled by the user interface, and there is no way to - from within JavaScript - do anything about that. You will not be able to simulate a click on the button, or internally tell Acrobat to continue with the script. You are actually not allowed to use Acrobat on a server, or on a server like environment (see the EULA for more information), so that's Adobe's way of making this server use more complicated.

                                                                         

                                                                        What I would try is to find out what the limitations of the export to TIFF functions are, and therefore what the maximum page size is that you can process this way. You would then have to analyze your PDF document to see if the page you are about to export is larger than that maximum allowed size, and if that's the case, export in a different format (before I would use JPEG, I would try PNG first - JPEG is only good for photographic images).

                                                                         

                                                                        If this is for a server or server-like environment, you will have to look at other tools.

                                                                        1 person found this helpful
                                                                        • 33. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                                          OzSanta2 Level 1

                                                                          G'day Karl.

                                                                           

                                                                          Thank you, you're a mine of information.

                                                                           

                                                                          I'm testing for documents greater than A4 size, which is the maximum I can print. I handle those as PDF's.

                                                                           

                                                                          However, I'm beginning to think, from the dearth of information on the net, that the maximum TIFF size you can save is set by the maximum size of the paper your printer can handle.

                                                                           

                                                                          If there's anyone reading this, that has an A3 printer, would you mind running an Acrobat test with A3.

                                                                           

                                                                          The sort of steps to take are as follows.

                                                                           

                                                                          Please do the following.

                                                                           

                                                                          1. Open GraphicConverter.

                                                                           

                                                                          2. Create a new document with a size of A3 (GC should recognize your printer can print A3).

                                                                           

                                                                          3. Type something large on the window document.

                                                                           

                                                                          4. Hit command-p

                                                                           

                                                                          5. Choose the bottom left pop up PDF, and choose  ‘Save as PDF...’. Save it to the desktop. Close it.

                                                                          Screen Shot 2017-01-14 at 4.20.35 pm.png

                                                                          6. Drag the new file from the Desktop to the Acrobat icon.

                                                                           

                                                                          7. Choose the menu item as shown below.

                                                                           

                                                                          Screen Shot 2017-01-14 at 4.15.12 pm.png

                                                                           

                                                                          8. Click on ‘Save’

                                                                           

                                                                          9. If no error window pops up, it means that A3 TIFFS can be saved.

                                                                           

                                                                          10. Try from 7. again. If you're asked if you want to replace, you've definitely succeeded.

                                                                           

                                                                          Please post results.

                                                                           

                                                                          Regards

                                                                           

                                                                          Santa

                                                                          • 34. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                                            Bernd Alheit Adobe Community Professional & MVP

                                                                            On Windows I can export A2 and A3 documents.

                                                                            1 person found this helpful
                                                                            • 35. Re: How can I save PDF as single page TIFF's, or JPEG's
                                                                              Karl Heinz Kremer Adobe Community Professional

                                                                              I just run a number of tests on Mac OS X 10.11.6 with Adobe Acrobat Pro DC (version 2015.023.20053). I also can export both A2 and A3 formats - both wide and tall - without any problems. There is no page size limit for TIFF files - there is a file size limit, but unless your files are larger than 2GB (or 4GB depending on what's inside the TIFF file), you should not run into problems with that.

                                                                               

                                                                              Here are the options that I used (I did change the color space to all three options: color/grayscale/monochrome to rule out any potential problems that only show up for one of the color spaces):

                                                                               

                                                                              2017-01-15_14-40-40.png

                                                                               

                                                                              What options are you using? What resolution for the output TIFF file? You do set these output options in Acrobat's Preferences in the "Convert From PDF" section.