Skip to main content
Known Participant
May 30, 2021
Question

Get and write data to csv or txt file with javascript

  • May 30, 2021
  • 2 replies
  • 4303 views

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!

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
May 30, 2021

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.

 

  

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
FireholdAuthor
Known Participant
May 30, 2021

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.

Thom Parker
Community Expert
Community Expert
May 30, 2021

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. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
May 30, 2021

The readFileIntoStream method of the util object.

FireholdAuthor
Known Participant
May 30, 2021

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?

try67
Community Expert
Community Expert
May 30, 2021

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=Acro12_MasterBook%2FJS_API_AcroJS%2Futil_methods.htm%23TOC_readFileIntoStream

 

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.