Escape ampersands in NetSuite Advanced PDF templates

Fix a literal ampersand XML error in a copied Advanced PDF/HTML template and verify that its unsaved sample preview prints one ampersand.

The quick answer

For literal text between XML tags, encode a bare ampersand as & in the template source. The XML source Harbor & Pine should print as Harbor & Pine with one visible ampersand. Change only the broken literal character, leave valid entities intact, and preview again. Template Preview uses sample data and does not prove saved transaction printing.

The screenshots use sample data and fictional person and operating-company names.

Before you start

Use a copied custom template in a test account, with its original source preserved. Advanced PDF/HTML Templates must be enabled on the SuiteCloud subtab of Enable Features, and your role must be able to edit the template. The example uses Practice Invoice PDF/HTML Template and literal payment-address text Harbor & Pine. The walkthrough ends at an unsaved preview; it does not change a transaction form’s template assignment.

01. Open the copied template

Go to Customization → Forms → Advanced PDF/HTML Templates. Find Practice Invoice PDF/HTML Template and click Edit. Confirm its name and preserved source before continuing.

Verify the copied practice template name before changing its source.

02. Inspect the literal text in Source Code

Turn on Source Code. Locate the payment-address line containing Harbor & Pine between XML tags. Confirm it is literal text rather than part of a FreeMarker expression or an existing valid entity. In this example, the bare ampersand is on line 14.

Line 14 contains literal payment-address text between XML tags. Its bare ampersand starts an invalid entity reference.

03. Read the Preview error

Click Preview. Read the XML error about the entity name following the ampersand; open Detail if needed. Close the error and return to the source. This error comes from the literal XML character, not from a missing font glyph.

Read the entity error, then return to the source. It identifies an XML parsing problem.

04. Encode only the broken character

Replace that single bare ampersand with &amp;. The corrected source reads <td>Harbor &amp; Pine</td>. Leave valid entities such as &lt; and &#160; intact. A global replacement can turn an existing &amp; into &amp;amp; and make the printed text wrong.

Only the broken literal ampersand is encoded. Existing valid entities should remain intact.

05. Verify the unsaved preview

Click Preview again. Check that Payment address displays Harbor & Pine with one visible ampersand and no XML error. Close the preview. This edit remains unsaved. Before live use, separately save the approved template, check the transaction form’s Advanced printing assignment, and print a saved invoice with representative data. Check email output separately if it uses another template. Dynamic FreeMarker values need separate handling: a value emitted into XML may need ?xml, but escape it exactly once.

The corrected sample preview prints one ampersand. The template edit is still unsaved.

Common questions

Why does an ampersand break an Advanced PDF preview?

A bare ampersand in literal XML text starts an entity reference. Encode that character as &amp; so the parser can read it and the PDF prints one ampersand.

Should I replace every ampersand in the source?

No. Leave valid entities such as &lt; and &#160; intact. Replacing their leading ampersand can double-escape them and change the output.

Does the same fix apply to dynamic FreeMarker values?

Dynamic values need separate treatment. Raw text emitted into XML may need ?xml, but escape it exactly once and do not assume the static-text edit proves the dynamic field is handled correctly.

Does escaping fix a missing character in the font?

It fixes XML parsing. A font that lacks the required glyph needs a separate font check.

Does Template Preview prove that a saved invoice will print correctly?

No. Preview uses sample data and can test unsaved source. Separately save the approved template, confirm the transaction form’s printing assignment, and print a saved invoice with representative data before live use.