These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Order form with lots of products, calculated fields

skyview-ross
Registered: Feb 14 2011
Posts: 3

I'm creating a pdf order form for a wine store; the original pdf was created for us, and I converted it into a form.
There is one line for each product that looks like this:
 
____ 40080 CABERNET SAUVIGNON $9.95
 
When I ran the auto form-field recognition, it created a field to the left of the product number (where the underscore is) for each product. The field name is simply the product number, in this example '40080'.
 
I have been able to create and distribute the form with each field as a numeric (quantity), and the quantity for each product is saved in a dataset file. Is there a way I can read in the price for each field and have it calculate the totals? The prices are aligned in a column, I need to convert it to a data column. Some sort of bulk processing is needed - there are 577 products!
 
Thanks,
Ross Diamond

My Product Information:
Acrobat Pro 8.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Do you already know how to use Acrobat JavaScript to perform form calculations? So all you need is a way to read data from an external file, or a way to convert the text on the form to price data?

I believe that in Acrobat 10 there is a way to selectively convert table like data into data file. But there isn't any thing in Acrobat 8 for this. You could write a script to search the page text and extract price data, but it would be a lot of work and may not be reliable, depends on the consistency of the layout and what else is on the page.

If you have the price data in a file already, and you can reliably associated it with the related form field names, then your best bet is to import this data file into the PDF as an attachment and then parse it for the needed info.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

skyview-ross
Registered: Feb 14 2011
Posts: 3
thomp, thanks for the info

Now it turns out there is also an Excel spreadsheet with all the data - product number, name and price.
I'm not sure how to use Acrobat Javascript. What's the best way to import the data into the pdf file? Should I just create a new form from the spreadsheet? Or convert the spreadsheet to an XML file?

Thanks again,
Ross
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I don't know that creating the from from excel will make the form any more scriptable, at least as far a acquiring the price values is concerned.

With out a knowledge of Acrobat JavaScript, or programming in general, this is a very difficult task. There are a few ways to approach a solution. The easiest solution for you to implement with your current skill set is to hard code the prices into the calculations. Obviously this is very tedious and not an optimal solution.

The most general solution is to convert the Excel file into a text or CSV file and then add it as a file attachment to the form. Acrobat JavaScript has a function for reading the contents of an attachment. The contents would then need to be parsed to get the price data. This solution is the best because it gives you the ability to update prices by just replacing the attachment. Once written it's very portable, but it requires good programming skills.

There are also automated ways to add code into the PDF so that if you need to create a new document, adding in the interactive functionality is simple. But again, this requires some coding skills.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

skyview-ross
Registered: Feb 14 2011
Posts: 3
I have some programming and Javascript background; after looking at some of your tutorials, I'm now working in the Acrobat Javascript console.

I have created and distributed the basic form (on our website), and converted the Excel file to a tab-delimited text file; now the issue is collecting and parsing the data.
Do files attached to a pdf become embedded after you distribute the form? The form will be accessed via our website or sent via email, I don't want users to have to deal with another attached file.

The other issue is that while our form has 500+ products, 99% of the orders that come in include less than 20 products. So basically the calculation part only needs about 20 'Item lines' that would read in the data from a filled-in form dataset (product number, quantity), then look up the corresponding price, calculate the item total, and then add them all up for a grand total.
Maybe the calculation part should be a separate form that we run after receiving the data, or can it be included in the main form?

Thanks again,
Ross
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
PDF attachments are embedded into the PDF. They become an integral part of it. In fact, a PDF can be used exactly like a zip file, as a container for other files. This is how a PDF Portfolio works.

The contents of an attachment are acquired with the "doc.getDataObjectContents()" function. Look it up in the Acrobat JavaScript references, there's an example of how to use it. You'll need to write code to parse the data you need out of the contents. This is best accomplished by creating a array or generic object to hold all relevant data in the contents. This should be done when the PDF is loaded in Acrobat, so the object/array can be used at runtime.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script