简体   繁体   中英

How to display PDFs in a SWT-Application?

What is the best way to display PDFs in a swt application? I would prefer an open source solution.

If you can assume that a system-pdf viewer is installed, you can use the Browser widget by setting the following 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>

The src of the embed tag must point to the desired pdf, for local files: file://myPath/../test.pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM