3.在使用命名空间上加上
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
4.在Main函数中先创建一个名为doc烦人PDF的新文件,再给doc添加一个页面page。
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
5.导入我们刚才下载的字体文件DeeDeeFlowers.ttf,这里是作为一个名为trueTypeFont
的PdfTrueTypeFond 的参数之一并设置字体大小为 20f。
String fontFileName = "DeeDeeFlowers.ttf";
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f);
6.下面就是给刚才建立的page页添加一些文字了,然后设置一下他们的属性,这里所用的方法是page.Canvas.DrawString()。注意在这里就使用到我们刚才导入的字体了,并设置颜色为美丽的淡紫色,new PdfSolidBrush(Color.Orchid),起始坐标xy均为10。奉上最喜爱的文章Youth的一段。
page.Canvas.DrawString("Years may wrinkle the skin,n"
+ " but to give up enthusiasm wrinkles the soul.n"
+ " Worry, fear, self-distrust bows the heartn"
+" and turns the spirit back to dust.", trueTypeFont, new PdfSolidBrush(Color.Black), 10, 10);
7.然后保存为Pdf文件再预览就可以了。
下面就是展示出来的使用DeeDeeFlowers.ttf的效果图了。










