<分区>
我正在考虑使用 pdf.js (一种允许在网页中嵌入 pdf 的开源工具)。没有关于如何使用它的任何文档。
我假设我所做的是使用 header 中引用的脚本制作一个 html 页面,然后在正文中,我使用文件名和位置数组进行某种函数调用。有人可以帮我吗?
<分区>
我正在考虑使用 pdf.js (一种允许在网页中嵌入 pdf 的开源工具)。没有关于如何使用它的任何文档。
我假设我所做的是使用 header 中引用的脚本制作一个 html 页面,然后在正文中,我使用文件名和位置数组进行某种函数调用。有人可以帮我吗?
最佳答案
在他们的 github readme 上有可用的文档. 他们引用了 following example code :
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
//
// See README for overview
//
'use strict';
//
// Fetch the PDF document from the URL using promises
//
PDFJS.getDocument('helloworld.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);
});
});
关于javascript - 如何使用 pdf.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9328551/
相关文章:
javascript - mocha + mongodb 等待异步结果
jquery - 将剑道图表转换为 pdf 时,它会在 pdf 图表上绘制线条
pdf - 如何从命令行将 PDF 转换为灰度以避免被光栅化?
javascript - Sequelize 查找软删除的行
javascript - 将多个 API 调用合并为一个请求
javascript - 使用 css 和 js 固定文本区域中的文本
c# - 使用 iTextSharp 4.1.6 为特定页面添加书签
android - 如何使用 android native PdfDocument API 创建横向 PDF?