我希望获得PDF中每个页面的准确大小,作为我将要创建的PDF的单元测试的一部分。当我处理每个文档中具有许多不同页面大小的PDF时,代码将返回维度的数组列表。
每个页面也可以有自己的 DPI 设置。
我已经做了很多谷歌搜索,但我只想出了这个,这只给了我一部分答案,因为我仍然需要弄清楚每个页面的DPI是什么。
public static ArrayList<float[]> getDimentions(PDDocument document) {
ArrayList<float[]> dimensions = new ArrayList<>();
float[] dim = new float[2];
//Loop Round Each Page
//Get Dimensions of each page and DPI
for (int i = 0; i < document.getNumberOfPages(); i++) {
PDPage currentPage = document.getPage(i);
PDRectangle mediaBox = currentPage.getMediaBox();
float height = mediaBox.getHeight();
float width = mediaBox.getWidth();
// How do I get the DPI now????
}
//Calculate Size of Page in mm (
//Get Dimensions of each page and DPI ( https://stackoverflow.com/questions/20904191/pdfbox-find-page-dimensions/20905166 )
//Add size of page to list of page sizes
//Return list of page sizes.
return dimensions;
}
回首忆惘然
相关分类