C#引用第三方库iTextSharp.dll 合并PDF

本文档介绍了如何在C#中利用iTextSharp库进行PDF合并操作。通过PDFOperation类,可以创建PDF文档,设置基本字体,并添加文本内容。提供了一个简单的调用示例,展示如何打开文件流,生成带有当前时间的测试文档,最后关闭文档。
摘要由CSDN通过智能技术生成

///
/// 类说明:Assistant
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:http://www.cckan.net/thread-655-1-1.html
///
using System;
using System.Collections.Generic;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace Common
{
///
/// PDF文档操作类
///
//------------------------------------调用--------------------------------------------
//PDFOperation pdf = new PDFOperation();
//pdf.Open(new FileStream(path, FileMode.Create));
//pdf.SetBaseFont(@“C:\Windows\Fonts\SIMHEI.TTF”);
//pdf.AddParagraph(“测试文档(生成时间:” + DateTime.Now + “)”, 15, 1, 20, 0, 0);
//pdf.Close();
//-------------------------------------------------------------------------------------
public class PDFOperation
{
#region 构造函数
///
/// 构造函数
///
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>
    /// <param name="type">页面大小(如"A4")</param>
    /// <param name="marginLeft">内容距左边框距离</param>
    /// <param name="marginRight">内容距右边框距离</param>
    /// <param name="marginTop">内容距上边框距离</param>
    /// <param name="marginBottom">内容距下边框距离</param>
    public PDFOperation(string type, float marginLeft, float marginRight, float marginTop, float marginBottom)
    {
        SetPageSize(type);
        document = new Document(rect, marginLeft, marginRight, marginTop, marginBottom);
    }
    #endregion

    #region 私有字段
    private Font font;
    private Rectangle rect;   //文档大小
    private Document document;//文档对象
    private BaseFont basefont;//字体
    #endregion

    #region 设置字体
    /// <summary>
    /// 设置字体
    /// </summary>
    public void SetBaseFont(string path)
    {
        basefont = BaseFont.CreateFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    }

    /// <summary>
    /// 设置字体
   
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值