C# 对PDF文件的使用

百度网盘三方dll

ps:. net framework 4.0 client profile 下不行

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Diagnostics;

            PdfDocument doc = new PdfDocument();
            doc.PageSettings.Margins.All = 0;//设置边距为0
            PdfPageBase page = doc.Pages.Add();
            doc.Pages.RemoveAt(0);//删除第一页,因为有水印

            page = doc.Pages.Add();
            PdfTrueTypeFont trueTypeFont16 = new PdfTrueTypeFont(new System.Drawing.Font("宋体", 28, FontStyle.Regular), true);

            //字体颜色
            PdfSolidBrush brushGray = new PdfSolidBrush(Color.Gray);
            PdfSolidBrush brushBlack = new PdfSolidBrush(Color.Black);

            //直线颜色
            PdfPen pdfPenBlack = new PdfPen(Color.Black);
            PdfPen pdfPenGray = new PdfPen(Color.Gray);

            PdfImage pimg = PdfImage.FromImage(Properties.Resources.image1);

            page.Canvas.DrawImage(pimg, 100, 200, 20, 100, 50);
            page.Canvas.DrawString("Hello world!", trueTypeFont16, brushBlack, 200, 100);
            page.Canvas.DrawLine(pdfPenGray, 50, 200, 500, 200);

            string name = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".pdf";
            doc.SaveToFile(name);
            doc.Close();
            Process.Start(name);
发布了31 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/breakbridge/article/details/87089830