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, Vasyl-Tracker Dev Team, Sean - Tracker, Paul - Tracker Supp, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

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

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

Post by Peter2 » Fri Mar 01, 2019 1:04 pm

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: 13428
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 » Fri Mar 01, 2019 2:58 pm

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: 824
Joined: Mon Sep 13, 2010 10:09 am
Location: Switzerland

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

Post by Peter2 » Fri Mar 01, 2019 3:18 pm

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: 6789
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 » Fri Mar 01, 2019 4:00 pm

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: 62
Joined: Fri Jun 23, 2017 1:47 am

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

Post by DIV » Tue Mar 12, 2019 4:20 am

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: 2420
Joined: Wed Jan 03, 2018 6:52 pm

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

Post by TrackerSupp-Daniel » Tue Mar 12, 2019 8:12 pm

Hello Div,

You can create a custom button to run this javascript, by following the steps in this article: https://www.tracker-software.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!
Daniel McIntyre
Support Technician
Tracker Software Products (Canada) LTD

Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

Post Reply