Class Letter

java.lang.Object
com.nsdev.lettergenerator.Letter

public final class Letter extends Object
Starting point for content-first letters and the supported HTML letter template format. Use builder() for Java content, template(String) for markup with typed map bindings, or fromHtml(String) for already-resolved markup. Build a LetterDocument and pass it to LetterPdfGenerator.generate(com.nsdev.lettergenerator.model.LetterDocument).

Java builders default to A4 paper, 20 mm margins and the library's letter typography. Builders are mutable; their built document snapshots are immutable.

  • Field Details

    • PAGE_BREAK

      public static final String PAGE_BREAK
      Form-feed marker accepted by LetterBuilder.body(String...). Use it as a separate body argument or inside a body string to insert a page break. Header, footer and plain signature text reject this marker.
      See Also:
  • Method Details

    • builder

      public static LetterBuilder builder()
      Creates a fresh mutable Java letter builder with default page, region and text settings.
      Returns:
      an independent builder with no body content
    • fromJson

      public static LetterDocument fromJson(String json)
      Parses strict schema-version-one JSON into the shared immutable model. This does not run model validation or PDF layout; pass the result to the generator for either operation.
      Parameters:
      json - nonnull JSON document
      Returns:
      parsed document, or null for the JSON null literal
      Throws:
      InvalidLetterException - for malformed or incompatible input
    • template

      public static HtmlLetterBuilder template(String markup)
      Starts a template builder that substitutes ${name} bindings in parsed text and attribute values. Replacement text cannot introduce markup nodes. The source must use the supported single <letter> root format, checked when built.
      Parameters:
      markup - non-null letter template source
      Returns:
      a fresh builder that accepts placeholder values and named image assets
      Throws:
      IllegalArgumentException - if markup is null
    • fromHtml

      public static HtmlLetterBuilder fromHtml(String resolvedMarkup)
      Starts a builder for already-resolved markup in the supported <letter> format. Placeholder substitution is disabled; supplying values to this builder is rejected. Parsing and markup validation occur when the builder is built.
      Parameters:
      resolvedMarkup - non-null letter markup whose values have already been resolved
      Returns:
      a fresh builder that accepts named image assets
      Throws:
      IllegalArgumentException - if resolvedMarkup is null