• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Jan 07, 2017 Jan 07, 2017

Copy link to clipboard

Copied

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

TOPICS
Edit and convert PDFs

Views

4.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 12, 2017 Jan 12, 2017

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

...

Votes

Translate

Translate
Community Expert ,
Jan 08, 2017 Jan 08, 2017

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 08, 2017 Jan 08, 2017

Copy link to clipboard

Copied

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_

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2017 Jan 09, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 09, 2017 Jan 09, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 09, 2017 Jan 09, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 10, 2017 Jan 10, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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" & "\"; "

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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"});

}"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines