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

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
Peter2
User
Posts: 946
Joined: Mon Sep 13, 2010 10:09 am
Location: Switzerland

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

Post 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?
PDF-X-Change Pro German
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

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

Post 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
Peter2
User
Posts: 946
Joined: Mon Sep 13, 2010 10:09 am
Location: Switzerland

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

Post 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
PDF-X-Change Pro German
User avatar
Will - Tracker Supp
Site Admin
Posts: 6815
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK
Contact:

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

Post 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,
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.

Best regards

Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
DIV
User
Posts: 252
Joined: Fri Jun 23, 2017 1:47 am

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

Post 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
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8440
Joined: Wed Jan 03, 2018 6:52 pm

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

Post 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!
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Post Reply