问题描述
有一个pdf文件,我想将第二页作为图像导入并保存到jpeg文件中。
是否有可能以及怎么做?
There is a pdf file, and I want to import the 2nd page as an image and save it to a jpeg file. Is it possible and how to do it?
这是我导入页面的代码:
This is the code how I import a page:
Document document = new Document();
File file = File.createTempFile("", "");
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
final int backPage = 2;
PdfReader reader = new PdfReader(pdf.getAbsolutePath());
PdfImportedPage importedPage = writer.getImportedPage(reader, backPage);
com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(importedPage);
现在我得到一个图像
实例,但是我不知道如何将它写入jpeg文件。
Now I get an image
instance, but I don't know how to write it to a jpeg file.
推荐答案
显然(根据),你只能保存一张iText图像PDF页面,而不是光栅图像。
您可以将它存储在任何地方,如果您稍后将其用于另一个PDF页面...否则,您将不得不使用像JPedal这样的工具:
Appearently (according to 1T3XT BVBA), you can only save an iText Image from a PDF page, not a raster image.You can store it everywhere, if you will use later to put it in another PDF page... otherwise, you'll have to use a tool like JPedal:
============================== =====
===================================
编辑:也许PDFBox也能为你做到这一点!:
maybe PDFBox can do it for you too!:
这篇关于从pdf获取页面并使用itext将其保存到图像文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!