[]
        
(Showing Draft Content)

Rich Text in PDF

In PdfDocument, the text can be filled with any color. It can also be stroked or filled and stroked simultaneously.

The drawText's options argument has the fill and stroke properties. Leave these properties empty to indicate that the text should be filled, by default. Set stroke to true to indicate that the text should be stroked. Set fill and stroke, both to true to indicate that text should be both stroked and filled.

Each call to drawText starts a new paragraph. To indicate that subsequent text should be placed right after the previous one, set the options argument's continued property to true:

import * as wijmo from '@mescius/wijmo';
import * as wjPdf from '@mescius/wijmo.pdf';

doc.drawText("Lorem ", null, null, { continued: true });
doc.drawText('ipsum ', null, null, {
        continued: true,
        stroke: true
    }
);
Result

Lorem Ipsum Rich Text

Setting Up the Fill Color

The fill color can be specified in two ways:

By passing a brush directly to drawText as the options.brush property:

doc.drawText("Lorem", null, null, {
    brush: new wjPdf.PdfSolidBrush("#ff0000")
});

By changing the default document brush using the doc.setBrush method first. This brush will be used if you call drawText method without passing a brush to it:

doc.setBrush(new wjPdf.PdfSolidBrush("#ff0000"));
doc.drawText("Lorem");
Result

Lorem Red Text

Setting up the stroke color

Like the fill color, the stroke color can be specified in the same way by passing a pen to the options.pen property or doc.setPen method.

doc.setPen(new wijmo.Color('#e69500'));
doc.drawText("Lorem", null, null, {
    stroke: true,
    fill: new wijmo.Color('#3173c0')
});

// or
doc.drawText("Lorem", null, null, {
    stroke: true,
    fill: new wijmo.Color('#3173c0'),
    pen: new wijmo.Color('#e69500')
});
Result

Lorem Set Pen Example

For more information about brushes and pens, see the Drawing Graphics topic.

PdfDocument doesn't differentiate between text color and vector graphics color, so changing the default document brush or pen affects the vector graphics API too.