Java itext:如何检测PDF方向

Java itext:如何检测PDF方向,java,pdf,itext,Java,Pdf,Itext,我使用itext5来缩小pdf文档,但是我注意到pdf文档元数据中很少使用旋转信息,通过检查页面的宽度和高度仍然可以找到方向,但是对于下面的pdf文档,我最终得到了一个既有横向页面又有纵向页面的pdf,但是所有页面都以相同的方向呈现(在普通pdf查看器中)。 我的问题是,这些信息存储在哪里?pdf查看器如何按其应有的方式呈现文档 这是使用的方法: Document document = new Document(MarginsPDFHelper.DIM_PAGE, MarginsPDFHel

我使用itext5来缩小pdf文档,但是我注意到pdf文档元数据中很少使用旋转信息,通过检查页面的宽度和高度仍然可以找到方向,但是对于下面的pdf文档,我最终得到了一个既有横向页面又有纵向页面的pdf,但是所有页面都以相同的方向呈现(在普通pdf查看器中)。 我的问题是,这些信息存储在哪里?pdf查看器如何按其应有的方式呈现文档

这是使用的方法:

Document document = new Document(MarginsPDFHelper.DIM_PAGE, MarginsPDFHelper.MARGIN_GEN, MarginsPDFHelper.MARGIN_GEN, MarginsPDFHelper.MARGIN_TOP, MarginsPDFHelper.MARGIN_BOT);
try {
    PdfReader reader = new PdfReader(pdfByte);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, outputStream);
    document.open();
    PdfContentByte content = writer.getDirectContent();
    for (int i = 1; i <= reader.getNumberOfPages(); i++) {
        document.newPage();
        PdfImportedPage page = writer.getImportedPage(reader, i);
        Rectangle pageSize = reader.getPageSizeWithRotation(i);
        float scaleX = MarginsPDFHelper.DIM_PAGE.getWidth() / pageSize.getWidth();
        float scaleY = MarginsPDFHelper.DIM_PAGE.getHeight() / pageSize.getHeight();
        float scale = Math.min(scaleX, scaleY);
        content.addTemplate(page, scale, 0, 0, scale, 0, 0);
    }
    return outputStream.toByteArray();
} catch (Exception e) {
    LOGGER.error("Can not scale pdf", e);
} finally {
    if (document.isOpen()) {
        document.close();
    }                                                                                                                        }
Document Document=新文档(MarginsPDFHelper.DIM\u页面、MarginsPDFHelper.MARGIN\u GEN、MarginsPDFHelper.MARGIN\u GEN、MarginsPDFHelper.MARGIN\u TOP、MarginsPDFHelper.MARGIN\u BOT);
试一试{
PdfReader读取器=新PdfReader(pdfByte);
ByteArrayOutputStream outputStream=新建ByteArrayOutputStream();
PdfWriter writer=PdfWriter.getInstance(文档,outputStream);
document.open();
PdfContentByte content=writer.getDirectContent();

对于(int i=1;i如果您仍然对此感兴趣,那么代码将完全忽略页面旋转值(示例文件的第一页为90,下一页为0)。在这方面,您能够检索的元数据检索到的页面旋转值不正确。如果您仍然对此感兴趣,则代码完全忽略页面旋转值(示例文件的第一页为90,下一页为0)。在这方面,您能够检索的元数据检索到的页面旋转值不正确。