Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Get and write data to csv or txt file with javascript

Participant ,
May 30, 2021 May 30, 2021

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!

TOPICS
How to , JavaScript , PDF forms
3.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2021 May 30, 2021

The readFileIntoStream method of the util object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 30, 2021 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2021 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...

 

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 30, 2021 May 30, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2021 May 30, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2021 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 30, 2021 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2021 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 30, 2021 May 30, 2021
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines