Use product_box to process PDF documents

Source: Internet
Author: User
Tags parsing pdf files

Use product_box to process PDF documents

1. Use product_box to process PDF documents

The full name of PDF is Portable Document Format, which is an electronic file Format developed by Adobe. This file format is independent of the operating system platform and can be used in Windows, Unix, Mac OS, and other operating systems.

The PDF File Format encapsulates text, fonts, formats, colors, and image images independent of devices and resolutions in one file. If you want to extract the text information, you need to parse it according to its file format. Fortunately, there are already many tools that can help us with these tasks.

2. Download product_box

The most common PDF Text Extraction Tool is javasbox. Visit http://sourceforge.net/projects/#box/to enter the download interface. You can download the latest version from this webpage. This article uses the PDFBox-0.7.3 version. Product_box is an open-source Java PDF library that allows you to access the information of PDF files. In the following example, we will demonstrate how to extract text information from a PDF file using the APIS provided by product_box.

3. Configure in Eclipse

The following is the process of creating a project in Eclipse and creating a tool class for parsing PDF files.

(1) create a common Java project in Eclipse workspace: ch7.

(2) decompress the downloaded box-0.7.3.zip file.

(3) Go to the external directory and you can see that all external packages used in the product_box are included. Copy the following Jar package to the lib directory of the Project ch7 (if the lib directory has not been created, create one first ).

Bcmail-jdk14-132.jar

Bcprov-jdk14-132.jar

Checkstyle-all-4.2.jar

FontBox-0.1.0-dev.jar

Lucene-core-2.0.0.jar

Then copy the PDFBox-0.7.3.jar to the lib directory of the project from the lib directory of the Consumer box.

(4) Right-click the project and choose "Build Path-> Config Build Path-> Add Jars" from the shortcut menu, add the packages under the lib directory of the project to the Build Path of the project.

4. Use product_box to parse PDF content

In the just-created eclipseproject, create a ch7.pdf box package and create a eclipboxtest class. This class contains a getText method used to obtain text information from a PDF. The Code is as follows.
Import java. io. BufferedWriter;
Import java. io. FileInputStream;
Import java. io. FileWriter;

Import org.w.boxw.parser. extends parser;
Import orgdomainbox. util. extends textstripper;


Public class extends parser {

/**
* @ Param args
*/
// TODO automatically generates method stubs

Public static void main (String [] args) throws Exception {
FileInputStream FCM = new FileInputStream ("F: \ task \ lerman-atem2001.pdf ");
BufferedWriter writer = new BufferedWriter (new FileWriter ("F: \ task \ change.txt "));
Partition parser p = new partition Parser (FCM );
P. parse ();
Extends textstripper ts = new extends textstripper ();
String s = ts. getText (p. getPDDocument ());
Writer. write (s );
System. out. println (s );
FCM. close ();
Writer. close ();

}
}

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.