相关疑难解决方法(0)

获取PDPage/PDDocument的DPI以准确计算PDF尺寸

我希望获得 PDF 中每个页面的准确大小,作为我将创建的 PDF 单元测试的一部分。当我处理每个文档中有许多不同页面大小的 PDF 时,代码返回一个维度的 ArrayList。

AFAIK 每个页面也可以有自己的 DPI 设置。

我已经做了相当多的谷歌搜索,但我只想到了这个,它只给了我部分答案,因为我仍然需要计算出每个页面的 DPI 是多少。

PDFBox - 查找页面尺寸

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????
    } …
Run Code Online (Sandbox Code Playgroud)

java dpi pdfbox

2
推荐指数
1
解决办法
4565
查看次数

标签 统计

dpi ×1

java ×1

pdfbox ×1