Creating a PDF with combined texts from different inputs

Hello all,

I want to create a script that:

  1. is asking for the language (English or French)

  2. then is asking for the list of products that have been shipped

  3. then is asking for the list of products that have been returned

  4. then is asking for the list of products that have been cancelled

  5. and then is creating a PDF in the downloads folder with the following layout:

    Language: English   
    

    Product Status
    Item 1 Shipped
    Item 2 Shipped
    Item 3 Shipped
    Item 4 Shipped
    Item 5 Shipped
    Item 6 Returned
    Item 7 Returned
    Item 8 Returned
    Item 9 Cancelled

or if the selected language is French to have the following layout:

Langue: Français 

Produit		Condition
Article 1 		Expédié 	
Article 2 		Expédié
Article 3 		Expédié
Article 4 		Expédié
Article 5 		Expédié
Article 6 		Retourné
Article 7 		Retourné
Article 8 		Retourné
Article 9 		Annulé 

Could you please advise me how to do it, especially the last two steps?

When you say asking for the list of products …

Is the list a file the script reads? What’s the source?

My strategy to do this would be:

  • Use dialog toolkit to get all the user selections
  • Format the lists to meet the specifications
  • Save the lists to a text document
  • Use Shane’s script (linked to below) to make a pdf from the saved text document
1 Like

Thank you for your reply.

The list comes from a spreadsheet, where the products are there in columns.

So far I have created the three dialogs with the inputs. I copy the cells from the spreadsheet and paste them on the dialogs.

Quick question: Is there any option to make the input text field larger? Or to have a wider text box, showing all the Pasted values?

And I am stuck now with formatting the lists. How can save this on a file but excluding any empty list?

If, for example, I have only 3 shipped orders, the layout should be this:

**Language**: English   

Product 	 Status
Item 214 	 Shipped
Item 329 	 Shipped
Item 572 	 Shipped

And if I have only one cancelled French order, the final layout should be:

**Langue**: Français 


Produit		Condition
Article 753 	Annulé

In fact, it is desirable that each user publish their problematic script, but here everything is described in words.

Well, I’ll start guessing that you already know how to create a text file. Therefore, I will offer a method that uses standard OS X tools, namely the convert-to utility from the LibreOffice.app bundle, to convert a TXT or RTF file to PDF.

Note that it also preserves the RTF markup (great), but I assume there is a better way (with standard OS X like here) that I don’t know of.
.

set txtFile to choose file of type {"rtf", "rtfd", "txt"}
set txtFilePath to quoted form of (POSIX path of txtFile)

set outDirPath to do shell script "dirname " & txtFilePath
do shell script "/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf --outdir " & quoted form of outDirPath & space & txtFilePath