Wie speichert man ein Formular in ein bestimmtes Vereichnis und wie benennt man es dann auch gleich noch nach einem Feldinhalt aus dem Formular selbst?
Programme wie MS Word können Letzteres ja, nicht so der Adobe Acrobat oder Reader.
Also muss JavaScript wieder her.
Damit klappt's, aber auch nur unter Verwendung von Folder Level Skripten, da die Sicherheitseinstellungen von Acrobat und Reader es ansonsten verbieten.
Eine einfache Variante des Ganzen könnte etwa so aussehen.
Ein Folder Level Script sowie ein Button und Formularfeld im Formular interagieren miteinander.
This issue took a long time for me to clear up.
How can I control the save directory of a form and how do I also rename the form after some data of the form itself?
Applications such as MS Word are able to do the latter, but Adobe Acrobat or Reader don't.
So you need JavaScript to realize this task.
But, because of Acrobat's and Reader's security restrictions this is only possible with folder level scripts.
A simple version can look like this.
The folder level script and also a button and field in the form interact with each other.
Beispiel-Formular – Speicherung in durch Skript angegebene Verzeichnisse
//
Sample form – Saving into directories specified through scripting
Beispiel-Ordner – Speicherung in einer der 4 Unterodner mittels JavaScript möglich
//
Sample folders – Saving directly into one of the 4 subfolder via JavaScript
Folder Level Script – JavaScript
var LCB_SaveAs = app.trustedFunction(function(doc)
{
app.beginPriv();
var LCB_SaveAsTarget = SaveAsTarget;
doc.saveAs({cPath: LCB_SaveAsTarget});
app.endPriv();
});
JavaScript zur Erstellung des Zielpfads
//
JavaScript to create save path
// Variables we use in the filename taken from fields somewhere in the form
var Var1 = xfa.resolveNode("form1.#subform.cDepartment").rawValue;
var Var2 = xfa.resolveNode("form1.#subform.cName").rawValue;
// Create a time stamp for the new file
var TimeStamp = util.printd("ddmmyyyy", new Date());
// This functions checks the current file name. If it is not the correct file name we don't save the file under a new file name
if (event.target.documentFileName === "LCB_SaveAs_V2.pdf")
{
// Name of a sub directory
// To save in the same directory enter ""
// To save in a named subfolder enter "Foldername/" (don't forget the trailing slash!)
var Directory = Var1 + "/";
// Concatenate the variables to a file name
var NewFileName = "LCB_SaveAs_V2" + "_";
NewFileName += Var2 + "_";
NewFileName += TimeStamp;
NewFileName += ".pdf";
// Replace all characters that are not allowed to be used in a save path – this it to avoid an raise error
NewFileName = NewFileName.replace(/[\s\!\?\<\>\'\"\*\/\\\=\?\^\`\{\}\|\~]+/g, "_");
// Concatenate save path with new file name for this form and show it into this field
this.rawValue = event.target.path.replace(event.target.documentFileName, "") + Directory + NewFileName;
}
else
{
this.rawValue = event.target.path;
}
JavaScript für Speichern-Button
//
JavaScript for Save Button
if (event.target.documentFileName === "LCB_SaveAs_V2.pdf")
{
//A variable for the Folder Level Script
SaveAsTarget = xfa.resolveNode("form1.#pageSet.Page1.FileParameters.TargetSubDirectory").rawValue;
try
{
event.target.LCB_SaveAs(event.target);
// Show message to inform the user, where the new file was saved.
xfa.host.messageBox("File has beed saved under:\r\r" + SaveAsTarget, "File Saved", 3, 0);
xfa.form.execInitialize();
}
catch(e)
{
xfa.host.messageBox(e.toString().replace("RaiseError: ","") + "\r\rEnsure the destination folder exists and there isn't already a file with the same file name in that folder!", "Failed to save file", 0, 0); }
}
else
{
// Open the 'Save As' dialog to let the user choose the target and filename.
app.execMenuItem("SaveAs");
}
Das Beispielformular geht noch weiter rein in die Materie und wird sie sicher interessieren.
Sie können z.B. in verschiedene Unterverzeichnisse speicher, je nach dem, welchen Wert Sie aus einer Dropdown-Liste ausgewählt haben.
The example form is much more detailed and will surely find your interest.
For example, you can save the form into one of several sub directories, depending on the selections you made in a drop down list.
Aktualisierung - Eine neuere Version ist hier verfügbar
//
Update - A newer version is available here
http://thelivecycle.blogspot.de/2015/06/save-with-new-name-in-specified.html