pdfsharp.net的代码示例
示例
代码源在此处查看输出
using System; using System.Diagnostics; using System.IO; using PdfSharp; using PdfSharp.Drawing; using PdfSharp.Pdf; using PdfSharp.Pdf.IO; namespace HelloWorld { /// <summary> ///此示例是强制性的HelloWorld程序。 /// </summary> class Program { static void Main(string[] args) { //创建一个新的PDF文档 PdfDocument document = new PdfDocument(); document.Info.Title = "Created with PDFsharp"; //创建一个空白页 PdfPage page = document.AddPage(); //获取用于绘制的XGraphics对象 XGraphics gfx = XGraphics.FromPdfPage(page); //创建字体 XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic); //画文字 gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center); //保存文档... const string filename = "HelloWorld.pdf"; document.Save(filename); //...并启动查看器。 Process.Start(filename); } } }