基本信息
源码名称:高级文本读写组件(PdfFileWriter)
源码大小:31.91M
文件格式:.zip
开发语言:C#
更新时间:2021-01-14
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍


public string WritePDFText()
        {
            string path = Server.MapPath("~/");

            //创建空白文档,文档参数有类型,可以使用枚举进行选择,和返回的文件名称
            string FileName = path @"Document\Test.pdf";
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);
            //加密测试例子
            //Document.SetEncryption(null, null, Permission.All & ~Permission.Print, EncryptionType.Aes128);

            //创建PDF文件信息目录
            PdfInfo Info = PdfInfo.CreatePdfInfo(Document);
            Info.Title("Article Example");
            Info.Author("Uzi Granot Granotech Limited");
            Info.Keywords("PDF, .NET, C#, Library, Document Creator");
            Info.Subject("PDF File Writer C# Class Library (Version 1.14.1)");

            //定义不同的字体类型,如下所示
            string FontName1 = "Arial";
            string FontName2 = "Times New Roman";
            ArialNormal = PdfFont.CreatePdfFont(Document, FontName1, FontStyle.Regular, true);
            ArialBold = PdfFont.CreatePdfFont(Document, FontName1, FontStyle.Bold, true);
            ArialItalic = PdfFont.CreatePdfFont(Document, FontName1, FontStyle.Italic, true);
            ArialBoldItalic = PdfFont.CreatePdfFont(Document, FontName1, FontStyle.Bold | FontStyle.Italic, true);
            TimesNormal = PdfFont.CreatePdfFont(Document, FontName2, FontStyle.Regular, true);
            Comic = PdfFont.CreatePdfFont(Document, "Comic Sans MS", FontStyle.Bold, true);

            //Step 3:添加新页面
            Page = new PdfPage(Document);
            // 添加链接
            Page.AddWebLink(6.0, 6.8, 7.2, 8.0, "http://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library-Version");

            //Step 4:添加内容到页面
            Contents = new PdfContents(Page);

            //创建文字示例
            //Contents = new PdfContents(Document);
            Contents.DrawText(Comic, 40.0, 4.25, 9.25, TextJustify.Center, 0.02, Color.FromArgb(128, 0, 255), Color.FromArgb(255, 0, 128), "PDF FILE WRITER");
            Contents.SaveGraphicsState();
            Contents.SetColorNonStroking(Color.Purple);
            Contents.DrawText(Comic, 30.0, 4.25, 8.75, TextJustify.Center, "Example");
            Contents.RestoreGraphicsState();

            // 绘制条形码
            Contents.SaveGraphicsState();
            BarcodeEAN13 Barcode1 = new BarcodeEAN13("1234567890128");
            Contents.DrawBarcode(1.3, 7.05, 0.012, 0.75, Barcode1, ArialNormal, 8.0);
            PdfQRCode QRCode = new PdfQRCode(Document, "http://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library-Version", ErrorCorrection.M);
            Contents.DrawQRCode(QRCode, 6.0, 6.8, 1.2);

            //保存
            Contents.RestoreGraphicsState();

            // Step 6:创建PDF
            Document.CreateFile();
            //打开PDF文件
            Process Proc = new Process();
            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            return "true";
        }