[英]Pdf(with type 3 fonts) to Image conversion in java
I am using icepdf to convert the pdf to image. 我正在使用icepdf将pdf转换为图像。 Here is the code.
这是代码。
import org.icepdf.core.exceptions.PDFException;
import org.icepdf.core.exceptions.PDFSecurityException;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.pobjects.Page;
import org.icepdf.core.util.GraphicsRenderingHints;
import javax.imageio.ImageIO;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
public class PageCapture {
private static ArrayList<File> fileNames = new ArrayList<File>();
public static void main(String[] args) {
// Get a file from the command line to open
String filePath = "example.pdf";
// open the file
Document document = new Document();
RenderedImage rendImages = null;
File file = null;
BufferedImage bi = null;
int height = 0, width = 0, i = 0, x = 0, y = 0;
try {
document.setFile(filePath);
} catch (PDFException ex) {
System.out.println("Error parsing PDF document " + ex);
} catch (PDFSecurityException ex) {
System.out.println("Error encryption not supported " + ex);
} catch (FileNotFoundException ex) {
System.out.println("Error file not found " + ex);
} catch (IOException ex) {
System.out.println("Error IOException " + ex);
}
// save page captures to file.
float scale = 5.0f;
float rotation = 0f;
// Paint each pages content to an image and
// write the image to file
for (i = 0; i < document.getNumberOfPages(); i++) {
BufferedImage image = (BufferedImage) document.getPageImage(i,
GraphicsRenderingHints.PRINT, Page.BOUNDARY_CROPBOX,
rotation, scale);
height = image.getHeight();
width = image.getWidth();
rendImages = image;
file = new File("C:/INC/imageCapture1_" + i + ".tif");
try {
fileNames.add(file);
ImageIO.write(rendImages, "tif", file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
image.flush();
}
try {
BufferedImage result = new BufferedImage(width, height * i, // work
// these
// out
BufferedImage.TYPE_INT_RGB);
Graphics g = result.getGraphics();
for (int j = 0; j < fileNames.size(); j++) {
bi = ImageIO.read(fileNames.get(j));
g.drawImage(bi, x, y, null);
y += height;
}
file = new File("C:/INC/imageCapture_new_.tif");
ImageIO.write(result, "tif", file);
} catch (IOException e) {
e.printStackTrace();
}
// clean up resources
document.dispose();
}
}
The above code is working fine for true type fonts but type3 fonts are not getting displayed in the image. 上面的代码对于真正的字体工作正常,但是在图像中没有显示type3字体。
The open source version of ICEpdf does not support Type 3 fonts. ICEpdf的开源版本不支持Type 3字体。 The PRO version does support Type 3 and can be licensed if needed.
PRO版本确实支持Type 3,并且可以根据需要获得许可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.