• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    使用pdfbox实现pdf文本提取和合并功能示例

    有时我们需要对PDF文件进行一些处理,提取文本、合并等。以前我们使用A-PDF Text Extractor免费工具,为什么不自己写一个呢?
    现在我们可以使用PDFBox-0.7.3这个开源类库. 下载解包后引用:

    复制代码 代码如下:

    PDFBox-0.7.3.dll
    IKVM.GNU.Classpath.dll

    新建一个项目,代码很简单:

    复制代码 代码如下:

    public static string ParseToTxtStringUsingPDFBox(string filename){
    PDDocument doc = PDDocument.load(filename);
    PDFTextStripper stripper = new PDFTextStripper();
    return stripper.getText(doc);
    }

    获得这个textString,再把它们写成磁盘文件就可以了, 像这样的方法:

    复制代码 代码如下:

    public static void WriteToTextFile(string str,string txtpath)
    {
    if (string.IsNullOrEmpty(txtpath))
    throw new ArgumentNullException("Output file path should not be Null");
    using (var txtWriter = new StreamWriter(txtpath))
    {
    txtWriter.Write(str);
    txtWriter.Close();
    }
    }

    其它的功能您可以自行发挥了. 这个类库目前支持:

    PDF to text extraction
    Merge PDF Documents
    PDF Document Encryption/Decryption
    Lucene Search Engine Integration
    Fill in form data FDF and XFDF
    Create a PDF from a text file
    Create images from PDF pages
    Print a PDF

    上一篇:mstest实现类似单元测试nunit中assert.throws功能
    下一篇:使用linq读取分隔符文本文件
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    使用pdfbox实现pdf文本提取和合并功能示例 使用,pdfbox,实现,pdf,文本,