本篇文章给大家介绍使用pdf文档操作C#代码,本文代码非常简单,代码附有注释,需要注意的是:需要添加itextsharp.dll引用才可以正常通过编译,感兴趣的朋友可以参考下
本文纯干货,贴上PDF文档操作类C#代码,需要添加iTextSharp.dll引用才可以正常通过编译。
废话不多说了,直接给大家贴代码了。
代码如下:
- using System.IO; using iTextSharp.text;
- using iTextSharp.text.pdf; namespace DotNet.Utilities
- { /// <summary>
- /// PDF文档操作类 /// </summary>
- //------------------------------------调用-------------------------------------------- //PDFOperation pdf = new PDFOperation();
- //pdf.Open(new FileStream(path, FileMode.Create)); //pdf.SetBaseFont(@"C:WindowsFontsSIMHEI.TTF");
- //pdf.AddParagraph("测试文档(生成时间:" + DateTime.Now + ")", 15, 1, 20, 0, 0); //pdf.Close();
- //------------------------------------------------------------------------------------- public class PDFOperation
- { #region 构造函数
- /// <summary> /// 构造函数
- /// </summary> public PDFOperation()
- { rect = PageSize.A4;
- document = new Document(rect); }
- /// <summary> /// 构造函数
- /// </summary> /// <param name="type">页面大小(如"A4")</param>
- public PDFOperation(string type) {
- SetPageSize(type); document = new Document(rect);
- } /// <summary>
- /// 构造函数 /// </summary>










