gpt4 book ai didi

java - PDF在java swt浏览器中不显示

转载 作者:行者123 更新时间:2023-11-30 03:01:49 27 4
gpt4 key购买 nike

我正在使用 java swt 浏览器来实现 java 单页应用程序。在浏览器中网页可以成功显示 PDF,但在 swt 浏览器中 PDF 无法正常显示。
我正在使用<object/>标签来显示 PDF。

 $(document).on('click', 'input[type=button]', function(){
var datas = '<object data="files/Documents/'+$(this).attr('class')+'#page=1&zoom=130" type="application/pdf" width="100%" height="100%"></object>';
$('#custom-size-dialogBox').dialogBox({

width: screen.width-100,
height: screen.height-100,
hasMask: true,
title: 'View Details',
hasClose: true,
content: datas

});
});

最佳答案

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

<!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>

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

关于java - PDF在java swt浏览器中不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35764742/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com