Skip to main content
Brave_Coast5EAE
Participant
Aug 13, 2022 11:14 AM UTC
Question

Text from Excel to PDF via Script

Dear All,

is it possible to add text automatically to a pdf from a excel worksheet?

 

 

In this case, i would like to add "XCKA-1P" to the PDF.


Thanks in advance!

 

PDF:

 

And Excel:

 

This topic is closed to new replies. Start a new post to keep the conversation going.

7 replies

try67
Community Expert
Community Expert
Aug 13, 2022 4:55 PM UTC

A script can't read data from an Excel file. It might be able to do it if the file was saved as a plain-text file, though.

Translate
Brave_Coast5EAE
Participant
Aug 13, 2022 5:40 PM UTC

yes, the excel file can easily be converted to text.

 

 

Translate
try67
Community Expert
Community Expert
Aug 14, 2022 9:08 AM UTC

In that case you can use the readFileIntoStream method of the util object to read its contents to a Stream object, then the stringFromStream method of the same object to convert it to a String, and then parse it like any other String object in JS to get the info you need from it.

Note that the first method requires a privileged context if you want to specify the file-path of the file to read to it. Otherwise, you'll be prompted to select it manually each time you run the script.

Translate
Brave_Coast5EAE
Participant
Aug 13, 2022 4:31 PM UTC

A script would have to find the name on each PDF page, compare it to the XLS Column A, and then add a text field to the PDF Page with the according data from column C.

 

In the example, the PDF page with the name "Ute Schmidt" would get a text field with "XCKA-1P"

The PDF page with "Gitta Lippold" would get a text field with "GBAD-1K"

 

and so on.

 

The text field can be anywhere on the PDF file in a free area.

 

Lastly the script should save and close the PDF file.

 

Again, thank you!

Translate