-
1. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Feb 29, 2012 6:43 AM (in response to jessevictoor)- If you want to extract just a single page, don't set the nEnd parameter.
- If you're running this in a batch process, set the output option to "Do
not save changes".
-
2. Re: Extract pages to separate pdf's (something wrong with loop?)
jessevictoor Feb 29, 2012 6:51 AM (in response to try67)There is only x-times of the first page extraction in x-times separate pdf's and the "save as" windows still appears.
-
3. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Feb 29, 2012 6:52 AM (in response to jessevictoor)nStart should be i, not 0.
-
4. Re: Extract pages to separate pdf's (something wrong with loop?)
jessevictoor Feb 29, 2012 10:05 AM (in response to try67)Many thanks!
I also added nEnd: i, because the script starts at i and all other pages after the "i" were also added at the end of the pdf.
When you choose nEnd: i, than will that result in only 1 page in each pdf.
/* Extract Pages to Folder */
var re = /.*\/|\.pdf$/ig;
var filename = this.path.replace(re,"");
{
for ( var i = 0; i < this.numPages; i++ )
this.extractPages
({
nStart: i,
nEnd: i,
cPath : filename + "_page_" + (i+1) + "_EN.pdf"
});
};
-
5. Re: Extract pages to separate pdf's (something wrong with loop?)
heresha93876846 Oct 5, 2016 7:17 AM (in response to jessevictoor)Is it possible to extract directly to jpg in a specific max resolution for width?
I am looking to use javascript to create thumbnails and images for a webshop automatically.
Best regards,
Heresh Ariai
-
6. Re: Extract pages to separate pdf's (something wrong with loop?)
Test Screen Name Oct 5, 2016 7:23 AM (in response to heresha93876846)Sounds as if you need something for a server process. Acrobat definitely not the tool for that.
-
7. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Oct 5, 2016 7:32 AM (in response to heresha93876846)In Addition to what TSN said, you can't set the resolution of the images using a script.
You can do it manually, though, via Edit - Preferences - Convert from PDF - JPEG...
-
8. Re: Extract pages to separate pdf's (something wrong with loop?)
Test Screen Name Oct 5, 2016 7:36 AM (in response to jessevictoor)I suspect the word resolution here is being used to mean "size in pixels" rather than the more usual "pixel density" (ppi)
-
9. Re: Extract pages to separate pdf's (something wrong with loop?)
heresha93876846 Oct 5, 2016 7:37 AM (in response to jessevictoor)I have this code that extracts the pages and names them correctly, is it possible to extract the pages as jpg instead?
/* Extract Pages to Folder */
var re = /.*\/|\.pdf$/ig;
var filename = this.path.replace(re,"");
var lastPage=this.numPages-1;
{
for ( var i = 0; i < this.numPages; i++ )
this.extractPages
({
nStart: i,
nEnd: lastPage,
cPath : Number(filename) + (i+1) + ".pdf"
});
};
-
10. Re: Extract pages to separate pdf's (something wrong with loop?)
heresha93876846 Oct 5, 2016 7:38 AM (in response to jessevictoor)Yes, size in pixels, escuse my english, its not my native language :-)
-
11. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Oct 5, 2016 7:40 AM (in response to Test Screen Name)Well, that is not possible, either...
-
12. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Oct 5, 2016 7:41 AM (in response to heresha93876846)After extracting each page use a variable to hold the return value of the extractPages method and then use the saveAs command to convert it to a JPEG file.
-
13. Re: Extract pages to separate pdf's (something wrong with loop?)
heresha93876846 Oct 5, 2016 7:42 AM (in response to jessevictoor)Okay but if I set it manually then the script output will correspond with that value?
-
14. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Oct 5, 2016 7:58 AM (in response to heresha93876846)I believe so, yes.
-
15. Re: Extract pages to separate pdf's (something wrong with loop?)
heresha93876846 Oct 5, 2016 10:53 PM (in response to jessevictoor)How do I save the files in a subfolder named images?
-
16. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Oct 6, 2016 1:44 AM (in response to heresha93876846)If that folder already exists then you'll need to add it to the cPath parameter, like so:
var outputFilePath = this.path.replace(this.documentFileName, "") + "/images/";
var outputFileName = this.documentFileName.replace(/\.pdf$/i, "");
...
cPath : outputFilePath + outputFileName + "_page_" + (i+1) + ".pdf";
-
17. Re: Extract pages to separate pdf's (something wrong with loop?)
iammund Oct 10, 2016 4:17 AM (in response to jessevictoor)I have a 3-page pdf form and I need the 3rd page extracted using a button action. is it possible to place the code in the button for this to work?
I have this javascript code on the Mouse Up event:
// Get the field values, as strings
var val = getField("txtLeadQuality.1").valueAsString;
if (val != "")
var _path = val + ".pdf"; //filename of the extracted page
this.extractPages({nStart:2, cPath: _path});
the code works in the java console, but when the button is clicked, an error occurs:
RangeError: Invalid argument value.
Doc.extractPages:8:AcroForm:btnSave.1:Annot1:MouseUp:Action1
can someone help me? thanks
-
18. Re: Extract pages to separate pdf's (something wrong with loop?)
Karl Heinz Kremer Oct 10, 2016 9:24 AM (in response to iammund)Take a look at the documentation for Doc.extractPages - you will find this: "If the cPath parameter is specified, this method can only be executed during a batch and console event, or through an external call (for example, OLE). See Privileged versus non-privileged context for details. The event object contains a discussion of JavaScript events."
You cannot call this method from a button action, because that is not a batch or console event.
-
19. Re: Extract pages to separate pdf's (something wrong with loop?)
iammund Oct 10, 2016 9:31 AM (in response to jessevictoor)What is the best way to do this, to extract and save the page 3 to a specific filename?
this is so far what I'm using, wherein after completing the form, the user will click the button and extract the last page, which is page 3.
then the original form will be cleared/reset and closed. only the extracted page will be left open. but the problem is the filename, i'm thinking of some how to automate the filename based on the data entered on a specific field.
//Autopopulate
// Get the field values, as strings
var val = getField("txtLeadQuality.1").valueAsString;
if (val != "")
var _path = val + ".pdf";
this.extractPages(2);
resetFieldsOnPage(0);
resetFieldsOnPage(1);
this.closeDoc(true);
Thanks
-
20. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Oct 10, 2016 10:16 AM (in response to iammund)As mentioned above, you can't specify the file name if you're running it from a button and it's not backed by a script that's installed in a folder-level script.
-
21. Re: Extract pages to separate pdf's (something wrong with loop?)
heresha93876846 Oct 11, 2016 12:07 AM (in response to jessevictoor)I am looking for ways to write folder level scripts but cant find any samples. Altough I found them in the help files: Acrobat DC SDK Documentation
-
22. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Oct 11, 2016 12:28 AM (in response to heresha93876846)See: https://acrobatusers.com/tutorials/using_trusted_functions
On Tue, Oct 11, 2016 at 9:22 AM, heresha93876846 <forums_noreply@adobe.com>
-
23. Re: Extract pages to separate pdf's (something wrong with loop?)
heresha93876846 Oct 11, 2016 1:03 AM (in response to jessevictoor)The information on that webpage is outdated, it links to https://acrobatusers.com/tutorials/folder_level_scripts but the commands and info on that page is not accurate. For example I cant find where to put my folder level scripts.
-
24. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Oct 11, 2016 1:23 AM (in response to heresha93876846)Read the comments, too...
-
25. Re: Extract pages to separate pdf's (something wrong with loop?)
Test Screen Name Oct 11, 2016 1:34 AM (in response to heresha93876846)Three tips:
1. You must define a trusted function because only trusted functions can do these dangerous things. (Imagine if ordinary JavaScript could just write to files on your disk, in some innocent file you downloaded!!)
2. You cannot put a trusted function inside a PDF, but you can put it in a startup script. These are just ordinary JavaScript but with extra powers so they can include a trusted function. Just putting a function in a startup script doesn't make it trusted. The location varies between products and releases, and is different between permanent and subscription licenses.
3. Never include any reference to the variable "this" in a trusted function. If you think you must, ask us how to avoid it. Otherwise there may be unpredictable and hard to understand failures, as designed.
-
26. Re: Extract pages to separate pdf's (something wrong with loop?)
heresha93876846 Oct 11, 2016 1:43 AM (in response to jessevictoor)I looked throught the comments, it linked to other pages... They were also outdated, I use ACROBAT DC. All I want to do is to be able to run scripts that call Acrobat and Photoshop. I downloaded Extended Script Toolkit but when I asked the support for help, they said there is none. When I look for help on the website I often run into empty information pages or in the best cases, outdated info. I cant even find where my folder level scripts are saved by Acrobat DC. I think adobe stopped giving support to these cases a long time ago.
-
27. Re: Extract pages to separate pdf's (something wrong with loop?)
try67 Oct 11, 2016 1:56 AM (in response to heresha93876846)The information is old, but not outdated. Almost everything that's described there should still work with DC. You might need to adjust the location of the Javascripts folder, but if you follow the instructions you'll find it, even for your version.
-
28. Re: Extract pages to separate pdf's (something wrong with loop?)
Karl Heinz Kremer Oct 11, 2016 7:26 AM (in response to heresha93876846)ExtendScript is something you an only use with Photoshop and other CC applications - Adobe Acrobat uses it's own version of JavaScript, and the two are not compatible.
All the information you need is in the Acrobat Javascript documentation, but unfortunately, unless you read (and understand) all of it, some things are hard to find.
See here for some information about where folder level JavaScripts need to be stored: Acrobat JavaScripts - Where do they go? - KHKonsulting LLC
-
29. Re: Extract pages to separate pdf's (something wrong with loop?)
heresha93876846 Oct 12, 2016 2:47 AM (in response to jessevictoor)I found the fresh information Adobe - Acrobat Developer Center | Adobe Developer Connection