Is there a way to extractPages() as a different format? i.e. .docx.

New Here ,
Jul 17, 2018 Jul 17, 2018

Copy link to clipboard

Copied

I took a packet that's broken up in 7 different files and combined them all as one .pdf.

Problem is, I'm in the Navy and doing that is technically "altering an official document" (even though all I did was essentially copy/paste), which is a big no-no. The way it exists now, it takes longer to open/save/print each file than it does to do the work. So, I combined them and automated where I could, now it takes about 15 seconds vice 15 minutes+. But, I need to get the 4 .docx and 1 .xlsx back to their native format after they've been filled out in the master file, then knock the other 2 ranges out as .pdf.

I'm not sure how, but this worked perfectly once using:

this.extractPages(start,end,'/C/myPath/myFilename.docx', 'com.adobe.acrobat.docx');

In a button action. Which (as I understand it) shouldn't be possible. The file saved where I wanted, with the name I wanted, in the right format, and looked flawless. Then I made the huge mistake of leaving my work PC on overnight and came back to a frozen machine and lost the progress. The converted test file is still there though, so I know I'm not crazy.

In a perfect world, it would prompt the user to pick a save path and have the filename filled and ready to go, or use an alert to prompt for text input for the filename. I'd like to make it as easy as possible for my coworkers and future sailors assigned to this station. Wrapping it up in a button or even a folder level .js that can be executed from one would be perfect. Even if I need to have the filenames and paths static, it would be better than the current system. I also doubt most folks at my office will know how to open the converted files in Acrobat Pro, let alone convert them to the right format, so I need a way to do it for them or there's no point in creating the document at all. I got the okay to add .js files to other machines from the cybersecurity folks, so that's one battle I don't have to worry about if that's the only way to make this happen.

Honestly, any way at all to get those 5 ranges back into their intended format would make everything a lot easier on myself and my coworkers. Any suggestions, help, or general finger pointing in the right direction to learn for myself would be greatly appreciated. I've been all over these forums, stack overflow, any documentation I can get my hands on, Reddit, google in general, and Thom Parker's stuff (which is the only reason I know even the little bit I do! Thanks man!). I'm an Electrician's Mate with exactly one class in OOP, I have no idea what I'm doing (but would gladly trade JS advice for light bulb fixing advice!) and no direction from our IT folks. Seriously, anything at all to put me on the right path would be incredibly helpful and appreciated.

-OneConfusedSparky

TOPICS
Acrobat SDK and JavaScript

Views

169

Likes

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

Adobe Community Professional , Jul 18, 2018 Jul 18, 2018
Nice to hear it!Either you've stumbled upon an undocumented feature of this method (which would be very nice!) or what happened was that you exported the file as a PDF and then the Action picked it up and converted it to DOCX, or something like that. Hard to say for sure... I'll try to run some tests and see if it works for me.Yes, the basic code would be:var newDoc = this.extractPages(start, end);newDoc.saveAs('/C/myPath/myFilename.docx', 'com.adobe.acrobat.docx');newDoc.closeDoc(true);If you d...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

Did the file save as docx file or as a PDF file? As far as I know, it's not possible to convert the file while extracting it.
The solution is to extract the pages, even as a temporary file, then use the saveAs method to convert the new Doc object returned by the extractPages command to the other format.

Likes

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 ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

Hey I know you! You and Thom are like 60% of the reason I even know how to open the command prompt!

It did save as .docx, which apparently shouldn’t be possible. It was my Frankensteining of extractPages() and saveAs() by just adding the conversion in. It hasn’t worked since so it must have just been dumb luck.

I’m going to give your guidance a try when I get to work today. Just to make sure I understand, I need to:

declare a newDoc object = extractPages() then saveAs() that object in the format I need. I’m assuming I’ll need to close and delete the object as well to make it less clunky too.

I’ll make sure to swing back and update when it works.

Thank you for the help here and the insane amount you’ve taught me through forum diving.

Likes

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
Adobe Community Professional ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

Nice to hear it!

Either you've stumbled upon an undocumented feature of this method (which would be very nice!) or what happened was that you exported the file as a PDF and then the Action picked it up and converted it to DOCX, or something like that. Hard to say for sure... I'll try to run some tests and see if it works for me.

Yes, the basic code would be:

var newDoc = this.extractPages(start, end);

newDoc.saveAs('/C/myPath/myFilename.docx', 'com.adobe.acrobat.docx');

newDoc.closeDoc(true);

If you do it like that it won't even save the extracted pages as a PDF and you'll only get the final docx file.

Of course, this has to be executed from a privileged context, like an Action or a trusted function in a folder-level script.

Likes

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
Adobe Community Professional ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

I get the following error message when I try to specify a non-PDF file path in extractPages:

RangeError: Invalid argument value.

So I think you might have done it some other way, as it doesn't seem to work...

Likes

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 ,
Jul 19, 2018 Jul 19, 2018

Copy link to clipboard

Copied

LATEST

Works like a charm! Thank you again for the help here and second hand help you've given me answering other questions!

Likes

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