我需要检测 PDF 文档的页面方向。这样做,我正在尝试获取单个页面的页面大小:
pdfGen = createPdf.makePdf("doc.pdf");
document = pdfGen.getDocument();
document.setMargins(80, 80, 80, 80);
writer = pdfGen.getWriter();
document.add(new Paragraph("some content"));
document.add(new AreaBreak(PageSize.A4.rotate()));
document.add(new Paragraph("more content"));
document.add(new AreaBreak(PageSize.A4));
document.add(new Paragraph("even more content"));
Rectangle rect = document.getPdfDocument().getPage(1).getPageSizeWithRotation(); // e.g. the 1st page
document.close();
writer.close();
但我得到的只是这行: .NullPointerExceptionRectangle rect = document.getPdfDocument().getPage(1).getPageSizeWithRotation()
java.lang.NullPointerException
at com.itextpdf.kernel.pdf.PdfDictionary.get(PdfDictionary.java:456)
at com.itextpdf.kernel.pdf.PdfDictionary.getAsArray(PdfDictionary.java:156)
at com.itextpdf.kernel.pdf.PdfPage.getMediaBox(PdfPage.java:516)
at com.itextpdf.kernel.pdf.PdfPage.getPageSize(PdfPage.java:125)
at com.itextpdf.kernel.pdf.PdfPage.getPageSizeWithRotation(PdfPage.java:134)
at com.myPackage.MyClass.myFunc(MyClass.java:15)
// ...
阿晨1998
天涯尽头无女友
相关分类