PDFBox - PageDrawer 在 PdfPagePanel 之外绘制 [英] PDFBox - PageDrawer draws outside the PdfPagePanel

查看:22
本文介绍了PDFBox - PageDrawer 在 PdfPagePanel 之外绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PDFBox 在我的应用程序中显示生成的 pdf 文件.我将 PdfPagePanel 添加到 JScrollPane.当我缩小窗口并出现滚动条时,PageDrawer 会绘制到滚动条上.

I'm using PDFBox to show a generated pdf-file in my application. I added the PdfPagePanel to a JScrollPane. When I make the window smaller and the scrollbars appeare, the PageDrawer draws onto the scrollbars.

PDFReader(PDFBox 的可执行示例)中也会出现这种效果.打开 pdf 文件 -> 缩小窗口大小 -> pdf 内容在滚动条上绘制

This effects also occurs in the PDFReader (executable example of PDFBox). open a pdf-file -> reduce size of window -> pdf-content get's drawn over the scrollbars

有人知道解决这个问题的方法吗?

Does anybody know a way to fix this?

环境:PDFBox 1.7.1、Windows 7、Java 1.6.31

Enviroment: PDFBox 1.7.1, Windows 7, Java 1.6.31

提前致谢,萨沙

推荐答案

我在 1.8.1 中仍然有同样奇怪的问题.

I still have the same weird problem in 1.8.1.

我的解决方案是将页面转换成这样的BufferedImage:

My solution is to convert the page into a BufferedImage like this:

    PDDocument document = PDDocument.load(new File("C:\\Temp\\stuff.pdf"));             
    List<PDPage> allPages = document.getDocumentCatalog().getAllPages();

    PDPage firstPage = allPages.get(0);
    BufferedImage bi = firstPage.convertToImage();

然后创建一个普通的 JPanel 并根据需要在那里显示图像...

Then create a normal JPanel and display the image there as you like it...

希望有帮助.奇怪的问题!祝你好运!

I hope that helps. Weird issue though! Good luck!

这篇关于PDFBox - PageDrawer 在 PdfPagePanel 之外绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆