Understanding Advanced PDF Printing Errors with Rich Text Fields in NetSuite

When printing transactions in NetSuite using Advanced PDF/HTML Templates, user may encounter errors if the template includes a Rich Text custom field. The printing failed with the following error:

Error Message:

The template cannot be printed due to the following errors: 
Error on line 203, column 504 in template. 
Detail: The value of attribute "style" associated with an element type "p" must not contain the '<' character.

Why This Happens

The root cause lies in the way Rich Text fields store content versus how Advanced PDF/HTML templates handle it:

Rich Text Fields:

  • Allow users to add formatted text, including HTML tags like <b>, <i>, <p>, <br>, and inline styles.
  • These fields generate standard HTML content.

Advanced PDF/HTML Templates:

  • Follow XHTML standards, which are stricter than regular HTML.
  • XHTML does not allow certain characters (like < or >) in attribute values unless properly escaped.
  • When a Rich Text field’s HTML is inserted into an XHTML-compliant template, invalid characters in attributes (e.g., style=”<some inline style>”) trigger errors.
  • As a result, the PDF generation fails, and the formatted content cannot be printed as intended. Often, the Rich Text appears as plain text, or the template throws an error.

Implications

  • Formatted content is lost: The PDF does not retain bold, italics, lists, or other rich formatting.
  • Printing fails for strict templates: Templates adhering to XHTML standards cannot render raw HTML from Rich Text fields.
  • Error messages point to invalid < or > characters: These are common when inline styles or HTML tags from Rich Text are included directly.

Workarounds

  • Use Plain Text Fields for PDF Templates: If formatted text is not essential, consider using a plain text custom field instead of Rich Text. This avoids invalid HTML characters and ensures the template prints without errors.
  • Clean Rich Text Content Before Rendering: Strip HTML tags from Rich Text fields using a script or formula before inserting them into the PDF template.
  • Escape HTML Special Characters: Replace < with &lt; and > with &gt; in the field value before rendering in the PDF. This allows XHTML-compliant printing but removes the original formatting.
  • Redesign the Template: Instead of directly inserting the Rich Text field, map only safe text portions or use inline styles compatible with XHTML.

Key Takeaway

Rich Text fields in NetSuite are not fully compatible with Advanced PDF/HTML templates due to XHTML compliance requirements. Any Rich Text field that contains HTML tags or inline styles can cause the template to fail during printing. To ensure error-free PDF generation, either use plain text, sanitize the Rich Text content, or carefully escape HTML characters before rendering. This is a NetSuite Enhancement.

Leave a comment

Your email address will not be published. Required fields are marked *