1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pdfbox-2.0.8 でPDFからJavaでテキスト抽出

Posted at
import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

public class PdfToTextMain1 {

	public static void main(String[] args) {

		// https://pdfbox.apache.org/download.cgi
		// pdfbox-2.0.8
		// fontbox-2.0.8.jar

		String filepath = "file/pdf_ja.pdf";

		try {

			PDDocument pdDoc = PDDocument.load(new File(filepath)); // throws
																	// IOException
			PDFTextStripper pdfStripper = new PDFTextStripper();// throws
																// IOException

			pdfStripper.setStartPage(1);
			pdfStripper.setEndPage(5);

			String parsedText = pdfStripper.getText(pdDoc); // throws
															// IOException

			System.out.println(parsedText);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

-->
これはテストです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?