【发布时间】:2015-08-12 10:22:52
【问题描述】:
我有一个现有的PDF,我想从中检索图像
注意:
在文档中,这是 RESULT 变量
public static final String RESULT = "results/part4/chapter15/Img%s.%s";
我不明白为什么需要这张图片?我只想从我的PDF 文件中提取图片
所以现在当我使用MyImageRenderListener listener = new MyImageRenderListener(RESULT);
我收到错误消息:
results\part4\chapter15\Img16.jpg(系统 找不到指定的路径)
这是我的代码。
package part4.chapter15;
import java.io.IOException;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
/**
* Extracts images from a PDF file.
*/
public class ExtractImages {
/** The new document to which we've added a border rectangle. */
public static final String RESOURCE = "resources/pdfs/samplefile.pdf";
public static final String RESULT = "results/part4/chapter15/Img%s.%s";
/**
* Parses a PDF and extracts all the images.
* @param src the source PDF
* @param dest the resulting PDF
*/
public void extractImages(String filename)
throws IOException, DocumentException {
PdfReader reader = new PdfReader(filename);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
MyImageRenderListener listener = new MyImageRenderListener(RESULT);
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
parser.processContent(i, listener);
}
reader.close();
}
/**
* Main method.
* @param args no arguments needed
* @throws DocumentException
* @throws IOException
*/
public static void main(String[] args) throws IOException, DocumentException {
new ExtractImages().extractImages(RESOURCE);
}
}
【问题讨论】:
-
嗨..现在不再是错误了,请查看问题,我已编辑
标签: java pdf itext pdf-parsing