确定PDF文档的纸张大小

时间:2013-03-22 08:23:11

标签: c# pdf

有没有办法确定C#中PDF文档的纸张大小。我发现了一个名为PdfPrintNet的dll,它允许我指定纸张尺寸,但它没有任何方法可以确定当前的纸张尺寸。

3 个答案:

答案 0 :(得分:1)

iTextSharp应该可以帮到你。

public float GetPageHeight(string PathToPDF)
{
    var reader = new PdfReader(PathToPDF);

    // A post script point is 0.352777778mm
    const float postScriptPoints = (float)0.352777778;

    // The height is returned in post script points from iTextSharp
    float height = reader.GetPageSizeWithRotation(1).Height * postScriptPoints;

    reader.Close();

    return height;

}

public float GetPageWidth(string PathToPDF)
{        
    var reader = new PdfReader(PathToPDF);

    // A post script point is 0.352777778mm
    const float postScriptPoints = (float)0.352777778;

    // The height is returned in post script points from iTextSharp
    float width = reader.GetPageSizeWithRotation(1).Width * postScriptPoints;   

    reader.Close();

    return width;

}

How to check a PDFs page size with iTextSharp

修改的代码

答案 1 :(得分:1)

PdfReader reader = new PdfReader(m);
PdfImportedPage page = writer.GetImportedPage(reader, i);
//size information
int wid=page.PageSize.Width
int heigh=page.PageSize.Height

通过这个。 可能会有帮助。

答案 2 :(得分:1)

如果您使用的是PdfPrintNet dll,则可以使用PdfPrint.PaperSize属性来获取pdf文档的大小。

希望有所帮助:)