By testing the control spire.pdf, we can create a PDF file and draw text, pictures, tables, graphics, and so on to the document, where, for the part of drawing text, Spire.pdf provides three font types to draw the text, namely:
- Standard fonts
- TrueType fonts
- Chinese, Japanese and Korean (CJK) fonts
From the above class, we can find that we can support Chinese, Japanese, Korean, English and other font classes, which gives us more possibilities to operate the PDF file. In this article, "Changing the font of a PDF file with private font" describes how to apply fonts, and in the next article, we'll show you how to use the font classes provided by Spire.pdf to draw text of different style types.
using the tool : Spire.pdf for. NET 4.0
PS: After installing the class library, note that after you reference Spire.PDF.dll in the program, the DLL file can be obtained in the Bin folder under the installation path after code editing.
"Example 1" draws text with italic style
C#
Using spire.pdf;using spire.pdf.graphics;using system.drawing;namespace drawtextofdifferentstyles_pdf{class Program {static void Main (string[] args) {pdfdocument doc = new pdfdocument ();//Create a PDF document Pdfpagebase page = doc. Pages.Add (); Add page pdfgraphicsstate state = page. Canvas.save (); Instantiate font, create format brush pdffont font = new Pdffont (Pdffontfamily.helvetica, 18f); Pdfsolidbrush brush1 = new Pdfsolidbrush (color.deepskyblue); Pdfsolidbrush brush2 = new Pdfsolidbrush (color.cadetblue); Pdfsolidbrush Brush3 = new Pdfsolidbrush (color.lightpink); Page. Canvas.translatetransform (10, 100);//Specifies the coordinates of the text on the canvas page. Canvas.scaletransform (1f, 0.6f);//Specifies the horizontal and vertical stretch of the text//draws the text type of the Italic style page. Canvas.skewtransform (-10, 0); Page. Canvas.drawstring ("There is NO ROYAL ROAD to Learning.", font, BRUSH1, 0, 0); Page. Canvas.skewtransform (10, 10); Page. Canvas.drawstring ("Books, like friends, should is few and well chosen.", Font, BRUSH2, 10, 50); Draws the text of the Zoom Type page. Canvas.scaletransform (1f, -1f); Page. Canvas.drawstring ("Books, like friends, should is few and well chosen.", Font, BRUSH3, 10,-2 * 50); Save the canvas page again. Canvas.restore (state); Save and open document Doc. SaveToFile ("Drawtext.pdf"); System.Diagnostics.Process.Start ("Drawtext.pdf"); } }}
Test results:
"Example 2" Drawing Center rotation graphic
C#
Using spire.pdf;using spire.pdf.graphics;using System.drawing;namespace _3{class Program {static void Main ( String[] args) {pdfdocument doc = new pdfdocument ();//Create a PDF document Pdfpagebase page = doc. Pages.Add (); Add page pdfgraphicsstate state = page. Canvas.save (); Instantiate font, create format brush pdffont font = new Pdffont (Pdffontfamily.helvetica, 10f); Pdfsolidbrush brush = new Pdfsolidbrush (color.blueviolet); Format the string layout and specify the position of the text in the canvas pdfstringformat centeralignment = new Pdfstringformat (Pdftextalignment.left, pdfvertic Alalignment.middle); float x = 400; Float y = 600; Draw the text and apply the Format page. Canvas.translatetransform (x, y); Specify text draw quantity for (int i = 0; i < i++) {//Set text to rotate clockwise (text offset interval 30 degrees) Page. Canvas.rotatetransform (30); Draw text and apply format pAge. Canvas.drawstring ("Every tide have its ebb.", font, Brush, ten, 0, centeralignment); }//Save the canvas page again. Canvas.restore (state); Save and open document Doc. SaveToFile ("Drawtext.pdf"); System.Diagnostics.Process.Start ("Drawtext.pdf"); } }}
Test results:
(Here are a few different styles of demo, can be compared to see the effect)
The above is about drawing different styles of the text of the entire content, if you want to reprint, please indicate the source.
(End of this article)
How C # draws text of different style types in PDF