Search results

PdfStringFormat API in JavaScript Pdf Export API control

PdfStringFormat class represents the text layout information on PDF.

// create a new PDF document
let document : PdfDocument = new PdfDocument();
// add a pages to the document
let page1 : PdfPage = document.pages.add();
// set font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// set brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
//
// set the format for string
let stringFormat : PdfStringFormat = new PdfStringFormat();
// set the text alignment
stringFormat.alignment = PdfTextAlignment.Center;
// set the vertical alignment
stringFormat.lineAlignment = PdfVerticalAlignment.Middle;
//
// draw the text
page1.graphics.drawString('Hello World', font, blackBrush, new PointF(10, 10), stringFormat);
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();

Properties

alignment PdfTextAlignment

Gets or sets the horizontal text alignment

// create a new PDF document
let document : PdfDocument = new PdfDocument();
// add a pages to the document
let page1 : PdfPage = document.pages.add();
// set font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// set brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
//
// set the format for string
let stringFormat : PdfStringFormat = new PdfStringFormat();
// set the text alignment
stringFormat.alignment = PdfTextAlignment.Center;
//
// draw the text
page1.graphics.drawString('Hello World', font, blackBrush, new PointF(10, 10), stringFormat);
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();

characterSpacing number

Gets or sets value that indicates a size among the characters in the text.

// create a new PDF document
let document : PdfDocument = new PdfDocument();
// add a pages to the document
let page1 : PdfPage = document.pages.add();
// set font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// set brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
//
// set the format for string
let stringFormat : PdfStringFormat = new PdfStringFormat();
// set character spacing
stringFormat.characterSpacing = 10;
//
// draw the text
page1.graphics.drawString('Hello World', font, blackBrush, new PointF(10, 10), stringFormat);
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();

lineAlignment PdfVerticalAlignment

Gets or sets the vertical text alignment.

// create a new PDF document
let document : PdfDocument = new PdfDocument();
// add a pages to the document
let page1 : PdfPage = document.pages.add();
// set font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// set brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
//
// set the format for string
let stringFormat : PdfStringFormat = new PdfStringFormat();
// set the vertical alignment
stringFormat.lineAlignment = PdfVerticalAlignment.Middle;
//
// draw the text
page1.graphics.drawString('Hello World', font, blackBrush, new PointF(10, 10), stringFormat);
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();

lineSpacing number

Gets or sets value that indicates the vertical distance between the baselines of adjacent lines of text.

// create a new PDF document
let document : PdfDocument = new PdfDocument();
// add a pages to the document
let page1 : PdfPage = document.pages.add();
// set font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// set brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
// set string
let text : string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitati';
// set rectangle bounds
let rectangle : RectangleF = new RectangleF({x : 0, y : 0}, {width : 300, height : 100})
//
// set the format for string
let stringFormat : PdfStringFormat = new PdfStringFormat();
// set line spacing
stringFormat.lineSpacing = 10;
//
// draw the text
page1.graphics.drawString(text, font, blackBrush, rectangle, stringFormat);
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();

wordSpacing number

Gets or sets value that indicates a size among the words in the text.

// create a new PDF document
let document : PdfDocument = new PdfDocument();
// add a pages to the document
let page1 : PdfPage = document.pages.add();
// set font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// set brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
//
// set the format for string
let stringFormat : PdfStringFormat = new PdfStringFormat();
// set word spacing
stringFormat.wordSpacing = 10;
//
// draw the text
page1.graphics.drawString('Hello World', font, blackBrush, new PointF(10, 10), stringFormat);
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();