Suche // Search:

30.11.2009

Formulare in bestimmte Verzeichnisse speichern und nach Inhalt aus Formularfeld benennen
//
Save forms to specific directories and named after form field data

Dies Thema hat mich selbst eine lange Zeit beschäftigt.
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


22.11.2009

"Änderung speichern"-Dialog mit Dirty-Flag unterbinden
//
Suppress 'Save Changes' Dialog with Dirty Flag

Manche Dinge sind echt nervig.
Da hat man ein XFA-Formular auf einem zentralen Speicherort liegen, das nicht überschrieben werden soll oder ein eines, dass nur zum Nachschlagen, aber nicht zum Ausfüllen dient.
Durch die vielen interaktiven Möglichkeiten kommt es aber immer wieder zu dem Problem, dass beim Schließen des Formulars der Dialog "Änderungen speichern" auftaucht und das Formular in seiner ursprünglichen Form überschrieben wird.

Um dem Problem Herr zu werden, bedarf es einiger Programmiertricks.

Im Kern dreht sich aber alles um ein kleines Script, dass das sogenannte Dirty Flag kontrolliert.
Das Dirty Flag gibt an, ob etwas in dem Formular geändert wurde, sei es noch so unbedeutend gewesen.
Ist das der Fall, fragt Acrobat/Reader nach, ob die Änderungen gespeichert werden sollen.

There are some annoying things going on.
Imagine, you have a XFA-form located on a central hard drive, that shouldn't be overwritten or a form you only use for look something up but not for filling.
Through all the interactivity in the forms you can get the 'save changes" dialog when you close the form and it happens that the basic form then is overwritten.

To handle this, you need some tricky programmings.

The base is a small script, that controls the dirty flag.
This flag tells the application if something has been changed in the form.
If so, Acrobat/Reader asks you to save changes you made.

JavaScript:

var MyDoc = event.target;
MyDoc.dirty = false;

Das Beispielformular zeigt, wie Sie dieses Script durch Events im Formular ansteuern können.

The example form shows, how you can trigger the script through events in the form.

Beispiel // Example:
https://workspaces.acrobat.com/app.html#d=WIEJS1UOrtCxRiAj5OeLPg