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
- Object
- 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 = 0 | Lines start at the left edge. |
public static final int ALIGN_CENTER = 1 | Lines are centered. |
public static final int ALIGN_RIGHT = 2 | Lines end at the right edge. |
public static final int ALIGN_JUSTIFY = 3 | Lines fill the width by widening the spaces, except the last. |
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. |
public static final int DIRECTION_AUTO = -1 | The direction comes from the first strong character. |
public static final int DIRECTION_LTR = 0 | Left to right. |
public static final int DIRECTION_RTL = 1 | Right 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 = 0ALIGN_CENTER
public static final int ALIGN_CENTER = 1ALIGN_RIGHT
public static final int ALIGN_RIGHT = 2ALIGN_JUSTIFY
public static final int ALIGN_JUSTIFY = 3ALIGN_START
public static final int ALIGN_START = 4DIRECTION_AUTO
public static final int DIRECTION_AUTO = -1DIRECTION_LTR
public static final int DIRECTION_LTR = 0DIRECTION_RTL
public static final int DIRECTION_RTL = 1Constructor details
PdfParagraph
public PdfParagraph()append methods.PdfParagraph
public PdfParagraph(String text, PdfFont font, float size)text in one font.Method details
append
public PdfParagraph append(String text, PdfFont font, float size)append
public PdfParagraph append(String text, PdfFont font, float size, int rgb)rgb (0xRRGGBB).appendLink
public PdfParagraph appendLink(String text, String uri, PdfFont font, float size, int rgb)uri when clicked, in color rgb.setAlignment
public PdfParagraph setAlignment(int alignment)ALIGN_ constants.setDirection
public PdfParagraph setDirection(int direction)DIRECTION_ constants.setLineSpacing
public PdfParagraph setLineSpacing(float multiple)setSpaceBefore
public PdfParagraph setSpaceBefore(float points)setSpaceAfter
public PdfParagraph setSpaceAfter(float points)setFirstLineIndent
public PdfParagraph setFirstLineIndent(float points)points.