PdfTrueTypeFont.fromBase64String constructor

PdfTrueTypeFont.fromBase64String(
  1. String fontData,
  2. double size, {
  3. PdfFontStyle? style,
  4. List<PdfFontStyle>? multiStyle,
})

Initializes a new instance of the PdfTrueTypeFont class.

fontdata represents the font stream as base64 string format. size represents the font size to draw the text. style and multistyle are used to set font styles.

//Create a new PDF document.
PdfDocument document = PdfDocument();
//Font stream in base64 string format
String base64 = 'AAEAAAATAQAABAAwRFNJRzlPG+EAASMQAAAdgKMbEAAAAAy/k2Tw==';
//Create a new PDF true type font instance with font data as base64 string.
PdfFont font = PdfTrueTypeFont(base64, 12);
//Draw string to PDF page.
document.pages.add().graphics.drawString(
    'Hello World!',
    font,
    brush: PdfBrushes.black,
    bounds: Rect.fromLTWH(0, 0, 100, 50));
//Saves the document.
List<int> bytes = doc.save();
//Dispose the document.
doc.dispose();

Implementation

PdfTrueTypeFont.fromBase64String(String fontData, double size,
    {PdfFontStyle? style, List<PdfFontStyle>? multiStyle}) {
  _helper = PdfTrueTypeFontHelper(this);
  if (fontData.isEmpty) {
    throw ArgumentError.value(fontData, 'fontData', 'Invalid font data');
  }
  _initializeFont(base64.decode(fontData), size, style, multiStyle);
}