Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public final class PdfParagraph

  1. Object
  2. PdfParagraph

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.

Fields

public static final int ALIGN_LEFT = 0Lines start at the left edge.
public static final int ALIGN_CENTER = 1Lines are centered.
public static final int ALIGN_RIGHT = 2Lines end at the right edge.
public static final int ALIGN_JUSTIFY = 3Lines fill the width by widening the spaces, except the last.
public static final int ALIGN_START = 4Lines start at the side the paragraph direction reads from: the left for left-to-right text, the right for right-to-left.
public static final int DIRECTION_AUTO = -1The direction comes from the first strong character.
public static final int DIRECTION_LTR = 0Left to right.
public static final int DIRECTION_RTL = 1Right to left.

Constructors

public PdfParagraph()An empty paragraph; add text with the append methods.
public PdfParagraph(String text, PdfFont font, float size)A paragraph of text in one font.

Methods

public PdfParagraph append(String text, PdfFont font, float size)Adds black text.
public PdfParagraph append(String text, PdfFont font, float size, int rgb)Adds text in color rgb (0xRRGGBB).
public PdfParagraph appendLink(String text, String uri, PdfFont font, float size, int rgb)Adds text that opens uri when clicked, in color rgb.
public PdfParagraph setAlignment(int alignment)Sets the alignment, one of the ALIGN_ constants.
public PdfParagraph setDirection(int direction)Sets the paragraph direction, one of the DIRECTION_ constants.
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.
public PdfParagraph setSpaceBefore(float points)Sets the space above the paragraph in points; 0 by default.
public PdfParagraph setSpaceAfter(float points)Sets the space below the paragraph in points; 6 by default.
public PdfParagraph setFirstLineIndent(float points)Indents the first line by points.

Inherited methods

Field details

ALIGN_LEFT

public static final int ALIGN_LEFT = 0
Lines start at the left edge.

ALIGN_CENTER

public static final int ALIGN_CENTER = 1
Lines are centered.

ALIGN_RIGHT

public static final int ALIGN_RIGHT = 2
Lines end at the right edge.

ALIGN_JUSTIFY

public static final int ALIGN_JUSTIFY = 3
Lines fill the width by widening the spaces, except the last.

ALIGN_START

public static final int ALIGN_START = 4
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.

DIRECTION_AUTO

public static final int DIRECTION_AUTO = -1
The direction comes from the first strong character. The default.

DIRECTION_LTR

public static final int DIRECTION_LTR = 0
Left to right.

DIRECTION_RTL

public static final int DIRECTION_RTL = 1
Right to left.

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.