admin管理员组文章数量:1435859
Fancybox is great but the default pdf implementation does not work very well because support, look and feel depends on OS, browser and adobe installation. PDF.js solves that by using a web standards-based platform for parsing and rendering PDFs. How to embed pdf.js viewer inside a fancybox?
Fancybox is great but the default pdf implementation does not work very well because support, look and feel depends on OS, browser and adobe installation. PDF.js solves that by using a web standards-based platform for parsing and rendering PDFs. How to embed pdf.js viewer inside a fancybox?
Share Improve this question asked Oct 27, 2016 at 7:30 PaintoshiPaintoshi 98612 silver badges13 bronze badges1 Answer
Reset to default 5Here's my solution how you can use pdf.js together with fancybox. It works x-browsers (at least the ones I tried), automatically & dynamically scales to browser view size and looks nice! The exact loading behavior can be a bit different between browsers though.
You will need to include jquery, fancybox and pdf.js:
- http://jquery./download/
- http://fancyapps./fancybox/
- https://github./mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website
If you want to embed pdf.js inside a static div instead of a fancybox, please have a look at https://pdfobject./
<html>
<head>
<!-- Add jQuery library -->
<script type="text/javascript" src="./includes/js/jquery-3.1.1.min.js"></script>
<!-- Add fancyBox main JS and CSS files -->
<script type="text/javascript" src="./includes/js/fancybox/jquery.fancybox.js?v=2.1.5"></script>
<link rel="stylesheet" type="text/css" href="./includes/js/fancybox/jquery.fancybox.css?v=2.1.5" media="screen" />
<script type="text/javascript">
var pdfOpenParams = "#page=1&pagemode=none"; //pagemode=none,bookmarks,thumbs
$(document).ready(function () {
//Fancybox settings
$(".fancybox-pdf").fancybox({
type: 'iframe',
padding: 0,
openEffect: 'fade',
openSpeed: 150,
closeEffect: 'fade',
closeSpeed: 150,
closeClick: true,
width: '60%',
height: '100%',
maxWidth: '100%',
maxHeight: '100%',
iframe: {
preload: false
},
//Define PDF.js viewer with optional parameters
beforeLoad: function () {
var url = $(this.element).attr("href");
this.href = "./includes/js/pdfjs/web/viewer.html?file=" + url + pdfOpenParams;
}
});
});
</script>
</head>
<body>
<a class="fancybox-pdf" href="http://localhost/pdf/pdf-sample.pdf">View PDF</a>
</body>
</html>
本文标签: javascriptHow to embed pdfjs in a fancyboxStack Overflow
版权声明:本文标题:javascript - How to embed pdf.js in a fancybox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745625285a2666932.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论