旋转90度的itext Pdf横向页面页脚

我正在使用itext版本5将页脚放在现有的pdf文件中,我有两个实现IEventHandler接口的类,一个是文档在横向上,另一个是文档在纵向上,我使用此代码来知道pdf模式:

        PdfPage pdfPage = pdfDocument.getPage(1);
        Rectangle rectangle = pdfPage.getPageSize();
        return rectangle.getHeight() > rectangle.getWidth();

如果函数返回true,则假定文档为纵向模式。 现在我有一个问题,如果方法pdfPage.getRotation()的值类似90,因为矩形的值是Height:842.0 Width:595.0,并且始终为纵向,页面页脚打印在文档的左侧。 我的句柄事件代码是:

@Override
    public void handleEvent(Event evento) {
        try {
            PdfDocumentEvent pdfEvento = (PdfDocumentEvent) evento;
            PdfDocument pdfDocumento = pdfEvento.getDocument();
            PdfPage pagina = pdfEvento.getPage();
            int numeroPagina = pdfDocumento.getPageNumber(pagina);
            PdfCanvas pdfCanvas = new PdfCanvas(pagina.newContentStreamBefore(),pagina.getResources(),pdfDocumento);
            Canvas canvas = new Canvas(pdfCanvas,pdfDocumento,new Rectangle(margenIzquierdo,pagina.getPageSize().getWidth() - 52,altoTabla));
            PdfFont tipoLetra = PdfFontFactory.createFont(StandardFonts.HELVETICA);
            Paragraph parrafo = new Paragraph().add(String.valueOf(numeroPagina)).setfont(tipoLetra).setfontSize(7);
            canvas.showTextAligned(parrafo,alineacionX,alineacionY,TextAlignment.CENTER);
            canvas.add(cargarPie());
            canvas.close();
            pdfCanvas.release();
        } catch (DocumentoItextExcepcion | IOException e) {
            LOGGER.error(e);
        }

    }
huanglianxing 回答:旋转90度的itext Pdf横向页面页脚

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3095087.html

大家都在问