从PDFBOX src下载获取Print ImageLocations.java文件.这是一个除了源,只有最后一行是由我,它将输出dpi:
float imageXScale = ctmNew.getXScale();
float imageYScale = ctmNew.getYScale();
System.out.println("position = " + ctmNew.getXPosition() + ", " + ctmNew.getYPosition());
// size in pixel
System.out.println("size = " + imageWidth + "px, " + imageHeight + "px");
// size in page units
System.out.println("size = " + imageXScale + "pu, " + imageYScale + "pu");
// size in inches
imageXScale /= 72;
imageYScale /= 72;
System.out.println("size = " + imageXScale + "in, " + imageYScale + "in");
// size in millimeter
imageXScale *= 25.4;
imageYScale *= 25.4;
System.out.println("size = " + imageXScale + "mm, " + imageYScale + "mm");
System.out.printf("dpi = %.0f dpi (X), %.0f dpi (Y) %n", image.getWidth() * 72 / ctmNew.getXScale(), image.getHeight() * 72 / ctmNew.getYScale());
这是一个示例输出:
找到图像[X0]
position = 0.0,0.0
size = 2544px,3523px< ---- pixels size = 610.56pu,845.52pu< ----“page units”,1pu = 1/72英寸 size = 8.48in,11.743334in 尺寸= 215.39198mm,298.28067mm dpi = 300 dpi(X),300 dpi(Y)