5 Replies Latest reply on Jul 5, 2016 6:20 AM by setchu

    read file from dynamic stamp

    setchu

      Hi,

       

      I would like tu read informations from a text file in my dynamic stamp.

       

      I try simple :

      event.value = this.importTextData("/c/temp/pdf.txt", 0)

       

      But it's not goog, have an idea  ?

        • 1. Re: read file from dynamic stamp
          Karl Heinz Kremer Adobe Community Professional

          You may want to review the documentation for Doc.importTextData(): Acrobat DC SDK Documentation - Doc.importTextData()

           

          You will find that the method is used to populate text fields from a tab delimited text file (you can find out more about how to use it here: Can I import data from an Excel spreadsheet to a fillable PDF Form? (Create PDF)

           

          What exactly are you trying to accomplish? What data is in the file you want to read? 

          • 2. Re: read file from dynamic stamp
            setchu Level 1

            In this file, it's just a number. I want modify this number manually. So this is a simple text file.

            I would like to read this number in my stamp, and indent it (Number = number+1).

            Every times, I uses my stamp the number take 1 more.

             

            So for exmple, if the number in my text file is "8".

            The fisrt stamp is "8",

            The second is "9",

            The third is "10"...

             

            Thanks for your help ;-)

            • 3. Re: read file from dynamic stamp
              gkaiseril MVP & Adobe Community Professional

              There are any number of examples for creating dynamic stamps that "Bates Number", named after the manufacturer that created the mechanical sequential number stamping machine.

               

              See the AcroLaw blog post Try these Two-line Dynamic Exhibit Stamps for more information.

              • 4. Re: read file from dynamic stamp
                Karl Heinz Kremer Adobe Community Professional

                OK, this looks like you have to solve two different problems (or three actually):

                 

                - determine if you have to read data from the file or just use the last number plus one for your stamp

                - read the number from the file

                - implement a function that can auto-increment after you've read the first number from your file.

                 

                Because you only mentioned the "read number from file" in your original question, that's the only issue I am describing in this post.

                 

                As you found out, you cannot use Doc.importTextData(), but there is a method that can read from a text file: util.readFileIntoStream() (see here for documentation: Acrobat DC SDK Documentation - util.readFileIntoStream()

                 

                The problem with this method is that you cannot use it outside of a trusted environment, so you will have to create a folder level trusted function that you will then call from within your stamp script. See here for information about how to create such a trusted function:

                 

                https://acrobatusers.com/tutorials/using_trusted_functions

                 

                You can use for example the following function (which does not have any error checking so that it does not distract from what you absolutely need):

                 

                var ReadDataFromFile = app.trustedFunction(function(thePath) {
                  app.beginPriv();
                  var rStream = util.readFileIntoStream(thePath);
                  app.endPriv();
                  return util.stringFromStream(rStream);
                });
                

                You can then use the following in your stamp script:

                 

                if (typeof ReadDataFromFile != "undefined") {
                    var data = ReadDataFromFile("/tmp/test.txt");
                    event.value = data;
                }
                
                • 5. Re: read file from dynamic stamp
                  setchu Level 1

                  Finally, I used simple popup question with this code :

                   

                  // Dialog Definition 
                  var oDlg = {
                      strName: "", initialize: function(dialog) {
                          dialog.load({"usnm":this.strName});
                      },
                      commit: function(dialog) {
                          var data = dialog.store(); 
                          this.strName = data[ "usnm"]; 
                      },
                      description: {
                          name: "Test Dialog", elements: [ {
                              type: "view", elements: [
                                  { name: "Enter your name:", type: "static_text", },
                                  { item_id: "usnm", type: "edit_text", char_width: 15 },
                                  { type: "ok_cancel", },
                              ]
                          },]
                      }
                  };
                  
                  // Dialog Activation 
                  oDlg.strName = "Texte"; 
                      if( "ok" == app.execDialog(oDlg)) { 
                      event.value = oDlg.strName; 
                  }
                  

                   

                  Thanks for your help