Class PdfParagraph

java.lang.Object
com.codename1.pdf.PdfParagraph

public final class PdfParagraph extends Object

A block of text for PdfLayout, wrapped to the available width. It is made of runs, each with its own font, size, color and optional link:

PdfDocument doc = new PdfDocument();
PdfLayout layout = new PdfLayout(doc, PdfPageSize.A4, 54);
layout.add(new PdfParagraph()
        .append("Total due: ", PdfFont.HELVETICA, 11)
        .append("$1,240.00", PdfFont.HELVETICA_BOLD, 11)
        .setAlignment(PdfParagraph.ALIGN_RIGHT));

Lines break at spaces and after hyphens; a word wider than the line is broken between characters. A \n in the text forces a line break.

Text is given in reading order. Each line is ordered for display by the Unicode bidirectional algorithm, so Hebrew and Arabic read right to left with numbers and Latin words inside them kept left to right, and Arabic letters are joined. The paragraph direction comes from its first strong character unless set with setDirection(int); it decides which side lines start from when no alignment is set and which side the first-line indent is on.

  • Field Details

    • ALIGN_LEFT

      public static final int ALIGN_LEFT
      Lines start at the left edge.
      See Also:
    • ALIGN_CENTER

      public static final int ALIGN_CENTER
      Lines are centered.
      See Also:
    • ALIGN_RIGHT

      public static final int ALIGN_RIGHT
      Lines end at the right edge.
      See Also:
    • ALIGN_JUSTIFY

      public static final int ALIGN_JUSTIFY
      Lines fill the width by widening the spaces, except the last.
      See Also:
    • ALIGN_START

      public static final int ALIGN_START
      Lines start at the side the paragraph direction reads from: the left for left-to-right text, the right for right-to-left. The default.
      See Also:
    • DIRECTION_AUTO

      public static final int DIRECTION_AUTO
      The direction comes from the first strong character. The default.
      See Also:
    • DIRECTION_LTR

      public static final int DIRECTION_LTR
      Left to right.
      See Also:
    • DIRECTION_RTL

      public static final int DIRECTION_RTL
      Right to left.
      See Also:
  • Constructor Details

    • PdfParagraph

      public PdfParagraph()
      An empty paragraph; add text with the append methods.
    • PdfParagraph

      public PdfParagraph(String text, PdfFont font, float size)
      A paragraph of text in one font.
  • Method Details

    • append

      public PdfParagraph append(String text, PdfFont font, float size)
      Adds black text.
    • append

      public PdfParagraph append(String text, PdfFont font, float size, int rgb)
      Adds text in color rgb (0xRRGGBB).
    • appendLink

      public PdfParagraph appendLink(String text, String uri, PdfFont font, float size, int rgb)
      Adds text that opens uri when clicked, in color rgb.
    • setAlignment

      public PdfParagraph setAlignment(int alignment)
      Sets the alignment, one of the ALIGN_ constants.
    • setDirection

      public PdfParagraph setDirection(int direction)
      Sets the paragraph direction, one of the DIRECTION_ constants.
    • setLineSpacing

      public PdfParagraph setLineSpacing(float multiple)
      Sets the distance between baselines as a multiple of the largest font's natural line height; 1.15 by default.
    • setSpaceBefore

      public PdfParagraph setSpaceBefore(float points)
      Sets the space above the paragraph in points; 0 by default.
    • setSpaceAfter

      public PdfParagraph setSpaceAfter(float points)
      Sets the space below the paragraph in points; 6 by default.
    • setFirstLineIndent

      public PdfParagraph setFirstLineIndent(float points)
      Indents the first line by points.