我希望獲得PDF中每個頁面的準(zhǔn)確大小,作為我將要創(chuàng)建的PDF的單元測試的一部分。當(dāng)我處理每個文檔中具有許多不同頁面大小的PDF時,代碼將返回維度的數(shù)組列表。每個頁面也可以有自己的 DPI 設(shè)置。我已經(jīng)做了很多谷歌搜索,但我只想出了這個,這只給了我一部分答案,因為我仍然需要弄清楚每個頁面的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;}
獲取網(wǎng)頁/PD 文檔的 DPI 以準(zhǔn)確計算 PDF 尺寸
慕桂英3389331
2022-09-28 09:46:23