Skip to main content
Participant
December 10, 2021
Question

PDF Formular Textfeld Zeichen ersetzen

  • December 10, 2021
  • 1 reply
  • 541 views

Hallo zusammen,

ich benötige eine Funktion um in einem Textfeld, welches von AutoDesk Inventor mit Text befüllt wird, das Zeichen # durch ein Absatz zu ersetzen.

 

Beispiel:

Text1#Text2#Text3

soll

Text1

Text2

Text3

werden.

 

Leider habe ich bisher keinerlei Erfahrung im Bereich JavaSkript.

Kann mir bitte jemand behilflich sein, wie das Skript auszusehen hat und an welcher Stelle ich dieses einfügen müsste?

Vielen Dank im Voraus.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
December 10, 2021

So you're importing the data from an external source and then want to convert the "#" characters into line-breaks?

Is the text field set as Multiline? Do you have Adobe Acrobat, or just the free Reader? How are you importing the data, exactly?

Participant
December 13, 2021

Good morning.

The textfields are filled from an external source - AutoDesk Inventor (CAD-Software).

The fields are filled correctly, but in one field a long text, currently separated by the "#" character, should be replaced by a paragraph for the next line. This field is set as Multiline.

We use Adobe Acrobat PRO DC.

The data is filled by a script provided by AutoDesk as a template. The script is called "Anark Core Script" to create a 3D-PDF. The fields must be named as follows {{ topComponent.ArtiLangTextPDF|| "" }} so that the correct texts are inserted in the appropriate place.

 

try67
Community Expert
Community Expert
December 13, 2021

Well, you can do it using this script:

 

for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="text" && f.multiline) {
		f.value = f.valueAsString.replace(/#/g, "\r");
	}
}

 

The question is how to run it. I would embed it in the file as a doc-level script, so that it runs each time the file is opened.