下面是一个简单的Java程序,使用Apache PDFBox读取PDF文件内容并打印出来: importorg.apache.pdfbox.pdmodel.PDDocument;importorg.apache.pdfbox.text.PDFTextStripper;importjava.io.File;importjava.io.IOException;publicclassReadPDF{publicstaticvoidmain(String[]args){try{// 加载PDF文档PDDocumentdocument=PDDocument....
FileBean bean = new FileBean(); String filePath = file.getAbsolutePath(); bean.setPath(file.getAbsolutePath()); bean.setModified(file.lastModified()); String content = ""; if(filePath.endsWith(".doc") || filePath.endsWith(".docx")){ content = readDoc(file); }else if(filePath.e...
readPdf(inputPath, outputPath); }publicstaticvoidreadPdf(String inputPath, String outputPath){try(PDDocumentdocument=PDDocument.load(newFile(inputPath))) {if(!document.isEncrypted()) {PDFTextStripperByAreastripper=newPDFTextStripperByArea(); stripper.setSortByPosition(true);PDFTextStrippertStripper=...
/*** 读取 PDF文本内容**@Param: MultipartFile*@return: pdf文本内容*/publicstaticStringreadPdf(MultipartFile file){StringBuildercontent=newStringBuilder();try{InputStreamis=file.getInputStream();PDFParserparser=newPDFParser(newRandomAccessBuffer(is));parser.parse();// 读取文本内容PDDocumentdocument=parse...
问使用java读取pdf文件ENHow to Read PDF File in Java(使用Apache PDF Box库)
Java读取pdf文件方法
public class Pdfreader { public void readFdf(String file) throws Exception { // 是否排序 boolean sort = false;// pdf文件名 String pdfFile = file;// 输入文本文件名称 String textFile = null;// 编码方式 String encoding = "GB2312";// 开始提取页数 int startPage = 1;// 结束...
public void readFdf(String file) throws Exception { // 是否排序 boolean sort = false;// pdf...
public class PdfReader { public void readFdf(String file) throws Exception { // 是否排序 boolean sort = false;// pdf文件名 String pdfFile = file;// 输入文本文件名称 String textFile = null;// 编码方式 String encoding = "UTF-8";// 开始提取页数 int startPage = 1;// 结束...
Reading a PDF Document To read an existing PDF document, you need to create a PdfDocument object and then call its "load" method with the file pathname or a memory stream containing the PDF file. // Create a PdfDocument instance PdfDocument doc = new PdfDocument(); try { // Load an...