首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用pdf.js

如何使用pdf.js
EN

Stack Overflow用户
提问于 2012-02-17 20:53:14
回答 1查看 169.4K关注 0票数 93

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

我假设我要做的是制作一个html页面,在头部引用脚本,然后在主体中放入某种类型的函数调用,其中包含文件名和位置的数组。有人能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-17 20:54:59

试试谷歌搜索pdf.js documentation

代码语言:javascript
复制
/* 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),这是大多数搜索者都会寻找的。

票数 33
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9328551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档