java获取PDF页面长宽
1.引入依赖
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.70</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.2</version>
</dependency>
2.获取长宽并转为cm
String filename = "C:\\Users\\Admin\\Desktop\\发票.pdf";
PdfReader reader = new PdfReader(filename);
Rectangle pageSize = reader.getPageSize(1);
float height1 = pageSize.getHeight();
float width1 = pageSize.getWidth();
System.out.println("width = "+width1+"pt, height = "+height1 + "pt");
PdfReader pdfreader = new PdfReader(filename);
Document document = new Document(pdfreader.getPageSize(3));
float width2 = document.getPageSize().getWidth();
float height2 = document.getPageSize().getHeight();
System.out.println("widths = "+width2+"pt, heights = "+height2 + "pt");
double d = 0.0352778;
System.out.println("widths = "+ d * width2+ "cm, heights = "+ d *height2 +"cm");