Get and write data to csv or txt file with javascript
Copy link to clipboard
Copied
Hello,
because of an invoice template form i need to read a small csv file with colums "invoice no, customer, date" to get the latest invoice number to add it with 1 for the new invoice.
The csv is in the same folder like the pdf im working from. Which functions could helm me doing that?
Thank you verya much in advance!
Copy link to clipboard
Copied
The readFileIntoStream method of the util object.
Copy link to clipboard
Copied
Thank you very much for that fast answer.
Can you tell me a good explanation site for this function?
And is it possible after reading to insert a new colum with the new invoice number, customername and current date?
Copy link to clipboard
Copied
See the documentation: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#rhtocid=_6_1_8_78_0_5&t...
Writing a file is much more complicated. One possible way of doing it is to create a data object and then export it, but it would require user interaction.
Copy link to clipboard
Copied
Hm, so there is no workaround to:
- get latest column of csv-file
- get latest invoice no
- insert latest invoice no+1 to field
- with click on a button save the new invoice number to new column
?
Maybe it is possible to create a single txt-file with a number in it and read and replace the number after clicking?
I just want to get the invoice number without having dublicates.
Copy link to clipboard
Copied
Not sure what you mean by "workaround"... It's possible, but it requires writing the code and setting up the file correctly, which is not a simple task. I've created similar tools for my clients in the past so if you're interested in hiring someone to do it for you feel free to contact me privately via [try6767 at gmail.com] to discuss it further.
Copy link to clipboard
Copied
You'll find tools(paid for) and information on performing exactly this type of task here:
https://www.pdfscripting.com/public/Form-Data-Handling.cfm#MoveData
What do you mean exactly by "insert a new colum with the new invoice number,"
Do you mean to modify the PDF to add a new column on the invoice? or modifiy the CSV file?
Neither of these is feasible through JavaScript alone.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks for your answer.
The task is to avoid dublicate invoice numbers.
So i thought about using another file to store previous used Invoice numbers and just add a 1 to it.
But for the next Invoice i need to store the currently created invoice number also in the file.
So either working with a csv file, wich can tell the pdf which was the last invoice and adding the new one as new row at the end, or creating a simple txt file which gets completely overwritten everytime with the latest invoice-number in it.
Copy link to clipboard
Copied
How about creating a PDF file to hold the numbers. PDFs are very easy to open get a value, change the value, and then save the PDF using a script.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
A CSV file is not a proper solution, because you cannot guarantee it is saved, nor manage conflicts between multiple users. You need a database. PDF files cannot access databases however. I suggest what you really need is an accounting package, they are made for invoicing. PDF will bring you nothing but pain.

