This content has been marked as final. Show 6 replies
I should also probably clarify why I'm printing to PDF rather than using SaveAs:
SaveAs produces a 840KB file whereas printing through the PDF8 printer makes a 59KB file.
I want to avoid sending the entire, fully-operational marking tool to my students to play with! ;)
I think you could simplify this considerably and still get a smaller file size by doing the following:
1. Determine the file name as you currently are
2. Flatten the document using the doc.flattenPages() method
3. Use doc.saveAs() to save with the file name determined in step #1
Thanks for the reply George. :)
The other reason that I'd like to print to PDF rather than using Save As is that if I 'Save As', I then have a completed (and flattened/password-protected/neutered) marking sheet still open rather than the original (fully-operational) one - ready to mark the next assignment. If I decided not to bother removing or restricting the functionality of the completed files, I not only produce bloated, administratively-sensitive files, I also run the risk of saving over the top of the last file completed.
As it is, the file name set up that I have isn't actually working. I'm not sure what I'm doing wrong, but the only way I can seem to get it to actually produce a file is when I basically hard-code the file name like this:
>pp.fileName = "Lawrence_Chris.ps";
Although I've not tested it, I'm pretty sure that the method I'm using will works for doc.saveAs() though, right?
Ok, I've pursued the SaveAs method (as George suggested) with moderate success with the following code (secure function names have been changed ;) ):
config.js file script:
>myTrustedSaveAs = app.trustedFunction( function ( doc, studName )
myTrustedOpenDoc = app.trustedFunction( function ( path )
Button's onMouseUp script:
>// get student name and turn it into a file name
var studFile = this.getField("Name").value.split(",").join("_").split(" ").join("") + ".pdf";
// get the current document's directory path
var origFile = this.path;
var pathBits = this.path.split("/");
// whack 'em together
var studFilePath = pathBits.join("/");
// toss the form fields and stuff
// save the new file
// open the original again (not working)
// close the one I just saved
This is what happens:
Button is clicked,
All the form fields and buttons are removed,
It produces a file with the new file name (e.g. Lawrence_Chris.pdf) next to the original,
The file closes
I'm pretty sure that once the SaveAs runs and the new file is created, I actually still have the original file open instead of the that was just saved. This would explain why the openDoc command doesn't seem to do anything because the file it's opening is already open. The closeDoc then runs and of course I then have no open documents!
So, now I either need a way to revert the open original file so I get all of my form fields back and don't have to reopen it, or a way to close and then immediately open the file without saving changes. :/
I was right, it is the original document that remains open rather than the SaveAs document, and I've worked out how to revert the original document too using this code:
This means I can toss all the openDoc code as well - hooray!
New problem though! Revert isn't behaving properly! :(
If I put that revert command at the end of the script attached to the onMouseUp of my button, nothing happens. If I run the revert command through the console, it brings up the normal alert 'Are you sure you want to revert? Cancel/Revert', I click on 'Revert', and it works fine. If I put the revert command in the config.js file as part of my trusted SaveAs function, the normal alert comes up, I click on 'Revert', then another alert comes up with 'Can not close the existing file. Ok', I click Ok, and the document closes! :/
What am I doing wrong?
(Thanks for letting me think aloud, btw! :) )
You seem brilliant. I have a similar requirement.
I need to create a file name using data from 2 of the form fields; full name and number. I am new to this, can you please provide steps on how you do this?
or email me at sbendigo[at]yahoo.com