[]
        
(Showing Draft Content)

Drawing Text in PDF

Each of the drawing areas provide drawText method to draw text. It takes the following arguments:

  • The text to draw
  • The X-coordinate of the point to draw the text at (optional)
  • The Y-coordinate of the point to draw the text at (optional)
  • The text drawing options (optional)

Example

doc.drawText("Lorem.");
// or
doc.drawText("Ipsum.", 0, 30);
// or
doc.drawText("Dolor.", null)

Current text coordinates

There is a concept of the current text coordinates, represented by the drawing area's x and y properties. These coordinates are used by the drawText method if positioning arguments are not defined. Each call to the drawText method updates the current text coordinates internally (even if the coordinates were passed into the method explicitly), so, any subsequent text is placed below the previous one.

Use the drawing area's moveDown and moveUp methods to move the Y-coordinate lower or upper with a given number of lines (default = 1).

Wrapping and Clipping

The text is drawn within a rectangular area defined as follows:

  • The x and y arguments determine the upper-left corner of the area. If omitted, then the current text coordinates are used instead.
  • The width and height properties determine the size of the area. If width is omitted, then the area will be limited horizontally by right margin of the page. If height is omitted, then the area will be limited vertically by the bottom edge of a body section. Use Infinity to indicate that the area has an infinite size in that direction.

The text is wrapped and clipped automatically within the area. If height is not defined, then the text will be extended to a new page automatically if it exceeds the bottom edge of the body section.

Alignment

Use the align property to determine how text should be aligned horizontally within the area. The following alignment methods are supported: left (default), center, right, justify.

For example, the following code draws a text within a 300x100 rectangle using current text coordinates and aligns it to the right.

doc.drawText("Lorem", null, null, {
    height: 100,
    width: 300,
    align: wijmo.pdf.PdfTextHorizontalAlign.Right
});