从pdf获取页面并使用itext将其保存到图像文件中 [英] Get a page from pdf and save it to an image file with itext

查看:765
本文介绍了从pdf获取页面并使用itext将其保存到图像文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个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.

推荐答案

显然(根据 1T3XT BVBA ),你只能保存一张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:

http://www.idrsolutions.com/convert-pdf-to-images /

============================== =====

===================================

编辑:也许PDFBox也能为你做到这一点!:

maybe PDFBox can do it for you too!:

http://pdfbox.apache.org/commandlineutilities/PDFToImage.html

http ://gal-levinsky.blogspot.it/2011/11/convert-pdf-to-image-via-pdfbox.html

这篇关于从pdf获取页面并使用itext将其保存到图像文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆