javascript - Chrome 和 FF 下载嵌入 URL 数据

标签 javascript html google-chrome firefox pdf

我在我的页面上设置了嵌入

<embed src="http://yoursite.com/the.pdf" width="500" height="375">

加载页面时,chrome 会提示下载文件的位置。

提供文件服务的 php 确实使用内联 header

偶数PDF Object无法在任一浏览器中工作,但可以在 safari 中工作

我使用的是 Mac,但我已经确认在 Windows 上有相同的结果

最佳答案

这对我在 Mac 上的 Chrome 中有效,希望有帮助。

<head lang="en">
    <script src="js/pdf.js"></script>
    <script>
        PDFJS.getDocument('read_me.pdf').then(function(pdf) {
            // Using promise to fetch the page
            pdf.getPage(1).then(function(page) {
                var scale = 1.5;
                var viewport = page.getViewport(scale);

                //
                // Prepare canvas using PDF page dimensions
                //
                var canvas = document.getElementById('the-canvas');
                var context = canvas.getContext('2d');
                canvas.height = viewport.height;
                canvas.width = viewport.width;

                //
                // Render PDF page into canvas context
                //
                var renderContext = {
                    canvasContext: context,
                    viewport: viewport
                };
                page.render(renderContext);
            });
        });
    </script>
</head>
<body>
    <canvas id="the-canvas"></canvas>
</body>

转述自https://github.com/mozilla/pdf.js/blob/master/examples/helloworld/hello.js

干杯, 八打灵再也

关于javascript - Chrome 和 FF 下载嵌入 URL 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30469915/

相关文章:

javascript - "-"在 chrome 内存 devtool 的距离字段中意味着什么

javascript - 用于匹配函数参数的正则表达式

javascript - 如何在 javascript 中编写自己的确认对话框?

javascript - 如何用鼠标拖放?

javascript - jQuery SlideOut 函数从右到左

html - 在 Chrome 响应模式下 block 元素之间添加一个像素

javascript - 如何使用 Javascript 使 div 中的图像出现

html - 将div内容拉伸(stretch)到页面底部固定位置页脚

google-chrome - 与所有 google 等顶级域匹配的内容脚本。*

html - 提高 Google Chrome 中滚动捕捉的灵敏度