Java uses PDFBox to manipulate PDF files

Source: Internet
Author: User

import java.io.fileinputstream;import org.apache.pdfbox.cos.cosdocument;import  org.apache.pdfbox.pdfparser.pdfparser;import org.apache.pdfbox.pdmodel.pddocument;import  Org.apache.pdfbox.util.pdftextstripper;public class read { public string readfdf (string file)  {  String docText =  ";  try {    fileinputstream fis = new fileinputstream (file);   cosdocument  Cosdoc = null;   pdfparser parser = new pdfparser (FIS);    parser.parse ();    cosdoc = parser.getdocument ();    Pdftextstripper stripper = new pdftextstripper ();   doctext =  Stripper.gettext (New pddocument (Cosdoc));    system.out.println (docText);   }  catch  (exception e)  {   sYstem.out.println ("bb="  + e.getmessage ());  }  return doctext; }  Public static void main (string args[])  {  read read = new  read ();   STRING S = READ.READFDF ("G:\\apdf\\test.pdf");   System.out.println (s);  }}

Only one jar package is required to Pdfbox-app-1.8.7.jar

Jar Package http://pdfbox.apache.org/

Reference Blog: http://wangbaoaiboy.blog.163.com/blog/static/521119102010111613126524/

There's even a bag in the Pdfbox-app-1.8.7.jar, and there's no need to reintroduce it.

This article is from the "format USB disk NTFS format" blog, so be sure to keep this source http://3482583.blog.51cto.com/3472583/1582565

Java uses PDFBox to manipulate PDF files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.