如何获取PDF页面的出血盒大小?

问题描述 投票:0回答:1

我试图从PDF中获取所有可能的页面边界,但是当我要求“出血”时,我得到一个Null值:

private void button2_Click(object sender, EventArgs e)
    {
        string source = @"C:\\Users\\numx\\Desktop\\TestPDF.pdf";
        PdfReader reader = new PdfReader(source);

        iTextSharp.text.Rectangle cropBox = reader.GetCropBox(1);
        iTextSharp.text.Rectangle mediaBox = reader.GetBoxSize(1, "media");
        iTextSharp.text.Rectangle trimBox = reader.GetBoxSize(1, "trim");          
        iTextSharp.text.Rectangle artBox = reader.GetBoxSize(1, "art");

        iTextSharp.text.Rectangle bleedBox = reader.GetBoxSize(1, "bleed");

        MessageBox.Show(bleedBox.ToString());
        reader.Close();

    }
itext
1个回答
0
投票

回顾我们在评论中讨论过的内容。

当你这样做:

iTextSharp.text.Rectangle bleedBox = reader.GetBoxSize(1, "bleed");

然后当PDF定义出血盒时,bleedBoxRectangle类的一个实例;当没有定义出血盒时,bleedBoxNull。在后一种情况下,当您在其上调用ToString()方法时,您将获得异常。

所以,如果你需要bleedBox,首先检查bleedBox是否是Null。如果不是,请使用bleedBox对象。如果不是,请改用裁剪框。如果没有裁剪框,​​请使用媒体框。

在所有页面边界中,只有媒体框是必需的。所有其他类型的页面边界都是可选的。

© www.soinside.com 2019 - 2024. All rights reserved.