These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Add menuitem to save a PDF

webpointz
Registered: May 21 2009
Posts: 36

I would like to know if it's possible to add a custom menuitem to Acrobat Pro that will take the current open PDF file and save the file to a specific filepath.

The PDF is created on the fly in a browser and the user is directed to OPEN the file which opens in Acrobat Pro.

What I am trying to do is two things:

1. have a menuitem that when clicked, will save the file to a specific location
2. remove the (1) in the filename when saving

Basically, when Acrobat pro opens the file and the user clicks on "saveas", acrobat tacks on a (?) at the end of the filename.

Any thoughts on what code i could put in the CONFIG.JS file to better control the save process so that users don't have to manually fix things?

Thanks

My Product Information:
Acrobat Pro 9.2, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Here's a folder level function that can be called from a menu item for saving the file. Place this in the Config.js file.
var mySaveFn = app.trustedFunction(function(oDoc){app.beginPriv();var cFileName = ...code to create file name...var cFilePath = ...code to create file path...oDoc.saveAs(cFilePath + cFileName);app.endPriv();}); // Add Menu Itemapp.addMenuItem({cName:"MySave",cParent:"File",cExec:"mySaveFn(event.target)"});

However, you could also call this function from a Toolbar Button, which can appear in the browser window.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

webpointz
Registered: May 21 2009
Posts: 36
Thanks Thom,

I just thought of something...if I create this button or menu item, is there any way to include in the function to "enhance for reader".

The problem comes when the user "enhances" the PDF (which I need them to do). When you choose "enhance", it immediately prompts a dialog to "save now" but when the user does this, the saveas dialog appears with a specific folder path AND the filename is the original name BUT with extended characters on the end of the name.

Example:

Original filename: myPDF.pdf
Saveas: myPDF(1).pdf

I'm trying to avoid the user from having to do too much so as to prevent errors in where and how the file gets saved.

Michael
webpointz
Registered: May 21 2009
Posts: 36
Hi Thom,

Updating my earlier post...I have it working now, just wondering how in the code I can use the file's original name, stripping off the uneeded characters.

Is there syntax for setting the original filename?
webpointz
Registered: May 21 2009
Posts: 36
There is one last thing that needs resolving.

When the user OPENS a PDF, they are opening the file from a link in a browser directly with Acrobat Pro.

When they do this, the file is being renamed with a "(??)" where "??" is a number.

Example:

Original Filename: Mytest.pdf
Opening the File, filename becomes "Mytest[1].pdf"

Does anyone know in the script how I can remove the [1] from the filename to retain the original filename?

Thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I haven't tried this, but it may work. Setup the PDF to display the title instead of the file name.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

webpointz
Registered: May 21 2009
Posts: 36
We are using iText to build the PDF so I have added the following to the code that produces the PDF:

document.addTitle(FileName);

In a folder level javascript file is the following:

var mySaveFn = app.trustedFunction(function(doc)
{
app.beginPriv();
var FileName = doc.info.title;
app.alert(doc.info.title);
var FilePath = "network_folder_path";
doc.saveAs(FilePath + FileName);
app.endPriv();
});

I tested it and it works perfectly...many thanks again Thom!!!