【问题标题】:How to display PDFs in a SWT-Application?如何在 SWT 应用程序中显示 PDF?
【发布时间】:2013-06-01 02:44:54
【问题描述】:

在 swt 应用程序中显示 PDF 的最佳方式是什么?我更喜欢开源解决方案。

【问题讨论】:

  • 你能不能也打开一个pdf阅读器?
  • 你可以在这个问题中找到一些:Java PDF Viewer
  • 没有外部 PDF 阅读器不是一个选项。
  • stackoverflow.com/questions/9061288/… 如果没有其他内容,您可以尝试将其转换为 HTML 并使用浏览器小部件

标签: java pdf swt eclipse-rcp


【解决方案1】:

如果您可以假设安装了 system-pdf 查看器,则可以通过设置以下 HTML 来使用 Browser 小部件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>

</head>
<body onResize="fit();">
<embed
    type="application/pdf"
    src="http://www.adobe.com/security/pdfs/riskcompliance_faq.pdf"
    id="pdfDocument">
</embed>    
<script type="text/javascript">
fit();
function fit() {
 var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
document.getElementById('pdfDocument').width = myWidth;
document.getElementById('pdfDocument').height = myHeight;
}</script>
</body>
</html>

embed 标签的 src 必须指向所需的 pdf,对于本地文件:file://myPath/../test.pdf

【讨论】:

    猜你喜欢
    • 2014-03-04
    • 2018-08-16
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多