如何使用pdf.js [英] How to Use pdf.js

查看:204
本文介绍了如何使用pdf.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用 pdf.js (一种允许嵌入pdf的开源工具)在网页中)。没有关于如何使用它的任何文档。

I am considering using pdf.js (an open source tool that allows embedding of a pdf in a webpage). There isn't any documentation on how to use it.

我假设我做的是使用标题中引用的脚本创建一个html页面,然后在正文中,我把一些函数调用与文件名和位置的数组。任何人都可以帮我吗?

I assume what I do is make an html page with the script referenced in the header, and then in the body, I put some sort of function call with an array of the file name and location. Can anyone help me out here?

推荐答案

试试谷歌 pdf.js文档

/* create the PDF document */

var doc = new pdf();
doc.text(20, 20, 'hello, I am PDF.');
doc.text(20, 30, 'i was created in the browser using javascript.');
doc.text(20, 40, 'i can also be created from node.js');

/* Optional - set properties on the document */
doc.setProperties({
  title: 'A sample document created by pdf.js',
  subject: 'PDFs are kinda cool, i guess',        
  author: 'Marak Squires',
  keywords: 'pdf.js, javascript, Marak, Marak Squires',
  creator: 'pdf.js'
});

doc.addPage();
doc.setFontSize(22);
doc.text(20, 20, 'This is a title');
doc.setFontSize(16); 
doc.text(20, 30, 'This is some normal sized text underneath.');

var fileName = "testFile"+new Date().getSeconds()+".pdf";
var pdfAsDataURI = doc.output('datauri', {"fileName":fileName});

注意:此处提到的pdf.js项目是 https://github.com/Marak/pdf.js ,自该答案发布以来已被弃用。 @ Treffynnon的答案是关于仍然活跃的Mozilla项目( https://github.com/mozilla/pdf.js )大多数搜索者都会寻找。

NOTE: the "pdf.js" project mentioned here is https://github.com/Marak/pdf.js, and has been deprecated since this answer was posted. @Treffynnon's answer is about the still-active Mozilla project (https://github.com/mozilla/pdf.js) that most searchers will be looking for.

这篇关于如何使用pdf.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆