将 PDF 转换为图像(格式正确)

2023-03-20移动开发问题
1

本文介绍了将 PDF 转换为图像(格式正确)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 pdf 文件(附件).我的目标是使用 pdfbox 原样将 pdf 转换为图像(与在 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 .

我正在使用以下代码:

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"));

当我使用代码时,图像文件给出完全错误的输出(附加了 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/编辑?usp=共享

here is the pdf(see page number 68) https://drive.google.com/file/d/0B0ZiP71EQHz2NVZUcElvbFNreEU/edit?usp=sharing

编辑 2:似乎所有的文字都消失了.我也尝试使用 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 );

同样的结果

推荐答案

事实证明 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();
}

它工作正常.

这篇关于将 PDF 转换为图像(格式正确)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Cocos2d - 对 CCSprite 应用 GLImageProcessing 效果
Cocos2d - apply GLImageProcessing effect to CCSprite(Cocos2d - 对 CCSprite 应用 GLImageProcessing 效果)...
2024-08-12 移动开发问题
10

如何在 COCOS2d Android 中使用 CClistview?
How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)...
2024-08-12 移动开发问题
5

未找到 SpriteBuilder 图像文件
SpriteBuilder image file not found(未找到 SpriteBuilder 图像文件)...
2024-08-12 移动开发问题
8

如何在 spritebuilder-Cocos2d 3.2 中添加单独的 iPad 和 iPhone 图像
How to add seperate iPad and iPhone images in spritebuilder- Cocos2d 3.2(如何在 spritebuilder-Cocos2d 3.2 中添加单独的 iPad 和 iPhone 图像)...
2024-08-12 移动开发问题
4

带有大图像的Objective C iPad动画-使用什么方法?
Objective C iPad Animation with large images - What method to use?(带有大图像的Objective C iPad动画-使用什么方法?)...
2024-08-12 移动开发问题
10

iOS 和 Cocos2d - 更改 CCSprite 的图像和新尺寸 = FAIL
iOS and Cocos2d - Changing CCSprite#39;s image AND new dimensions = FAIL(iOS 和 Cocos2d - 更改 CCSprite 的图像和新尺寸 = FAIL)...
2024-08-12 移动开发问题
8