![]() three fields (Does my example work of you? You can download all the files that I used.) If that works, but your actual form does not work, then I would fill in information into the form and export that data as a text file and then compare that with the records you are using. I can however tell you how I would approach a problem like this: First, I would start out with a very simple form and try to get the process working with e.g. Susie, without seeing the script you are using, the form and the data you are trying to import, it’s impossible to say what’s wrong. This almost seems like success if I could just get it to read all data! Does the code in the action still have state from being started from the original form? That is, does idx get set to 0 again? I assume it should increment until all rows from the data file are read or an error occurs and the code always acts on the currently open form. Am I missing something?Īnother question I have is after the saveas, the “currently” open file is now the newly saved one. I didn’t see anything in the debugger, but I’m not too sure how it works. If I comment out the error checking code then the file is actually saved with the correct data (and correct file name from that data), but then terminates with no error (all green checkmarks). When I open my PDF form and run the action, it populates the form with the 1st row of data in the data file, but errors out with User Cancelled File Select (error 3 from importTextdata). So, I made the action and set the paths to look at “/c/temp/”. This is just what I’ve been looking for (for hours)! If you have questions, as usual, post them in the comments. You can read up on device independent paths in the PDF specification. What I’ve used in this script are paths on a Mac, if you are running Windows, the paths may look like this: var fileName = "/c/temp/data.txt" Ī path of e.g. The only thing that’s a bit complex is the file and directory names in this script: Acrobat’s JavaScript uses “device independent paths”. You can get creative and use elements from the form to craete your new filename. And, the line with “saves the file” will save the open file under a new filename. ![]() There are two lines that actually do something: The line that is marked with ‘imports the next record’ is the one line that reads the record with the index “idx” from the file with the fielname “fileName”. This.saveAs(outputDir + this.getField("Text1").value + "_" + this.getField("Text2").value + ".pdf") // saves the file Time to exit this loop.Īpp.alert("Warning: User Cancelled File Select") Īpp.alert("Warning: User Cancelled Row Select") all rows in the data file and therefore are done with indicate the end of our data table: We've exhausted We are not reporting this error because it does Var outputDir = "/Users/username/tmp/" // make sure this ends with a '/'Įrr = this.importTextData(fileName, idx) // imports the next record Var fileName = "/Users/username/tmp/data.txt" // the tab delimited text file containing the data You can use the following script in an Action (or a custom command in Acrobat DC): To import a whole spread sheet of data, we need to call this method for each record, and then save the file under a new name, an then move to the next record. There is a problem with this page from the documentation: The error codes use the wrong sign: All positive values are supposed to be negative and vice versa. Take a look at the documentation for this method: Doc.importTextData Once you have such a file, you can use the Acrobat JavaScript method Doc.importTextData() to import one record at a time (just like we did manually before). The key to importing data from an Excel file is that you need to export the data as a “tab delimited text file” – just like described in the question I linked to above. If that does not work, trying to automate this step will also fail. The following gives you an idea about how to do this using JavaScript.Īnything I said about importing data manually in the link above is still true, so get familiar with the manual process and verify that you can actually import one data record from your text file into your PDF form. There must be a way to automate this…Īnd, there is. This is very useful if you only have to deal with one or a few records that you need to import into PDF forms, but what if we are talking about 10s or 100s of records? It gets a bit boring to click on the same buttons again and again. You can find this information here: Can I import data from an Excel spreadsheet to a fillable PDF Form? A while ago I documented for how to manually import an Excel data record into a PDF form.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |