代码:
/**
* 将pdf中的maxPage页,转换成一张图片
*
* @param pdfFile
* pdf的路径
* @param outpath
* 输出的图片的路径[包括名称]
* @param maxPage
* pdf的页数
* 【比如Pdf有3页,如果maxPage=2,则将pdf中的前2页转成图片,如果超过pdf实际页数,则按实际页数转换】
*/
private static void pdf2multiImage(String pdfFile, String outpath, int maxPage) {
try {
InputStream is = new FileInputStream(pdfFile);
PDDocument pdf = PDDocument.load(is, true);
List<PDPage> pages = pdf.getDocumentCatalog().getAllPages();
List<BufferedImage> piclist = new ArrayList<BufferedImage>();
int actSize = pages.size(); // pdf中实际的页数
if (actSize < maxPage) maxPage = actSize;
for (int i = 0; i < maxPage; i++) {
piclist.add(pages.get(i).convertToImage());
}
yPic(piclist, outpath);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 将