我有一个PDF文件(附后)。 我的目标是转换PDF到图像使用PDFBOX,因为它是(像使用截图工具在Windows中)。 PDF格式有各种形状和文字。
i have a pdf file(attached). My objective is to convert a pdf to an image using pdfbox AS IT IS,(same as using snipping tool in windows). The pdf has all kinds of shapes and text .
我用下面的code:
PDDocument doc = PDDocument.load("Hello World.pdf");
PDPage firstPage = (PDPage) doc.getDocumentCatalog().getAllPages().get(67);
BufferedImage bufferedImage = firstPage.convertToImage(imageType,screenResolution);
ImageIO.write(bufferedImage, "png",new File("out.png"));
当我使用code,图像文件给出了完全错误的输出(out.png附后)
when i use the code, the image file gives totally wrong outputs(out.png attached)
我怎么做PDFBOX采取类似的直接快照映像?
how do i make pdfbox take something like a direct snapshot image?
另外,我注意到,PNG的图像质量不太好,有什么办法来增加生成的图像的分辨率是多少?
also, i noticed that the image quality of the png is not so good, is there any way to increase the resolution of the generated image?
编辑: 这里是PDF(参见第68号) https://drive.google.com/file/d/0B0ZiP71EQHz2NVZUcElvbFNreEU/edit ?USP =共享
here is the pdf(see page number 68) https://drive.google.com/file/d/0B0ZiP71EQHz2NVZUcElvbFNreEU/edit?usp=sharing
编辑2: 似乎所有的文字isvanishing。 我也尝试过使用PDFImageWriter类
EDIT 2: it seems that all the text isvanishing. i also tried using the PDFImageWriter class
test.writeImage(doc, "png", null, 68, 69, "final.png",TYPE_USHORT_GRAY,200 );
同样的结果。
same result
推荐答案
事实证明,jpedal(LGPL)做了完美的转换(就像一个快照)。
it turns out that jpedal(lgpl) does the converting perfectly(just like a snapshot).
下面是我用的:
PdfDecoder decode_pdf = new PdfDecoder(true);
FontMappings.setFontReplacements();
decode_pdf.openPdfFile("Hello World.pdf");
decode_pdf.setExtractionMode(0,800,3);
try {
for(int i=0;i<40;i++)
{
BufferedImage img=decode_pdf.getPageAsImage(2+i);
ImageIO.write(img, "png",new File(String.valueOf(i)+"out.png"));
}
} catch (IOException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
decode_pdf.closePdfFile();
} catch (PdfException e) {
e.printStackTrace();
}
它工作正常。
it works fine.
相关推荐
最新文章