Page 1 of 1

Javascript to create filename for "save as" from different strings

Posted: Fri Mar 01, 2019 1:04 pm
by Peter2
Very often, filenames has to be created in a defined way, like "projektnumber-plantype-projectphase", e.g. "47110815-AB-Prephase.pdf".

Is there a way to start a dialogue with "save as" that shows an expanded inputbox, so that the user can create the complex filename inside this dialogue?

Re: Javascript to create filename for "save as" from different strings

Posted: Fri Mar 01, 2019 2:58 pm
by Tracker Supp-Stefan
Hello Peter,

You've posted in the Editor section, but are speaking of creating PDFs - so can you please confirm what is the input - is it a PDF file you already have opened in the Editor that you want to SaveAs... under a different name, or a file you want to 'print' to PDF from another source?

If it's inside the Editor - then you might indeed be able to write some such custom JS and add it to a toolbar button which will pop up a menu with some drop downs, and then use this input for the SaveAs... operation, which the script will also have to perform.

Regards,
Stefan

Re: Javascript to create filename for "save as" from different strings

Posted: Fri Mar 01, 2019 3:18 pm
by Peter2
Tracker Supp-Stefan wrote: Fri Mar 01, 2019 2:58 pm ... is it a PDF file you already have opened in the Editor that you want to SaveAs... under a different name ...
Yepp, exactly this.

Peter

Re: Javascript to create filename for "save as" from different strings

Posted: Fri Mar 01, 2019 4:00 pm
by Will - Tracker Supp
Hi Peter,

Thanks for the post - I'm afraid that this isn't something that we'd write for you. Generally speaking, unless the script is extremely simple or has a large benefit to a large number of users, we don't write user's scripts for them. I'd advise you take a look at the Adobe JS API Reference, as we support most of the features of functions in it:
https://www.adobe.com/content/dam/acom/ ... erence.pdf

Thanks,

Re: Javascript to create filename for "save as" from different strings

Posted: Tue Mar 12, 2019 4:20 am
by DIV
Hi, Will.
Thanks for the link to the "JavaScript for Acrobat API Reference" in the Adobe Acrobat SDK.
It is such a long document, mainly for reference and with an emphasis on syntax, although there are also examples given.

I am guessing that a script such as that enquired about would include a saveAs method, amongst other things.

What is puzzling me is where this JavaScript script would be stored.

I am passingly familiar with JavaScript scripts embedded into individual PDF files. For example, to implement an action if the user/reader clicks somewhere, or to gather/calculate some data and automatically update dependent text.

However, in the functionality enquired about, wouldn't the script be desirably stored 'within' PDF-XChange Editor itself somehow?
Is that correct?
And if so, where can that functionality be found?

ANALOGY: In Microsoft Word it is possible to store macros in individual documents, and respectively they'd only be available when that document were opened. But they could alternatively be stored in the 'normal' template, so that they'd then be always accessible no matter what document were opened.

—DIV

Re: Javascript to create filename for "save as" from different strings

Posted: Tue Mar 12, 2019 8:12 pm
by TrackerSupp-Daniel
Hello Div,

You can create a custom button to run this javascript, by following the steps in this article: https://www.pdf-xchange.com/knowle ... the-Editor

If you do not wish to a button to the UI, you could also store the JS in a text format on your desktop and then paste it into the JS console (Ctrl+J) whenever you need to use it.

You are correct that the saveAs method would be needed, beyond that if you need a dialog with any options to appear, you would have to code the entire dialog from the ground up in your JS, so creating a dialog free button is advised.

I hope this helps!