Tag: pdfjs

我怎样才能得到TypeScript加载PDF.js NPM模块和@types绑定生成工作Node.JS代码的方式?

上下文 我正在尝试将PDF.JS导入到TypeScript项目中。 我正在使用pdfjs-dist的DefinitelyTyped 绑定 ,通过npm install @types/pdfjs-dist和npm install pdfjs-dist 。 问题 我似乎无法得到TypeScript编译我的项目。 我使用直接从DefinitelyTypedtesting中复制的源代码。 这是我试图编译的简化(仅删除)代码(来自DefinitelyTyped的testing代码的确切副本也以相同的方式失败): import { PDFJSStatic } from 'pdfjs-dist'; var PDFJS: PDFJSStatic; PDFJS.getDocument('helloworld.pdf').then(console.log); TypeScript查找types声明模块,并认为PDFJSStatic的导入是有效的。 它不认为PDFJS是初始化的,但如果我在tsconfigclosuresstrict的代码编译,但它编译为: "use strict"; exports.__esModule = true; var PDFJS; PDFJS.getDocument('helloworld.pdf').then(console.log); 这显然不起作用。 这不是将汇编语句编译成任何东西。 题 如何将PDF.JS导入到TypeScript项目中并通过@types/pdfjs-dist的声明文件将其编译为工作Node.JS代码? 我所试过的 我已经尝试过不同的import变化,无济于事。 切换到require也似乎没有帮助。 我已经validation了pdjs-dist依赖项和@types/pdfjs-dist依赖项的存在,更新以及可以直接从NodeJS(非TypeScript程序)使用。 我已经尝试过我的tsconfig module各种值。 他们有时会更改生成的代码,但是他们都不会将其更改为包含所需的导入。 我已经尝试在import行上添加/// <reference path="../node_modules/@types/pdfjs-dist/index.d.ts" /> 。 这并没有改变行为。 环境 tsc版本2.4.2,节点8.5和npm 5.3。 我在我的项目根目录中有以下tsconfig.json […]

如何在PDF.js中启用文本select

我正在尝试使用pdf.js来显示PDF文件。 我已经可以显示PDF,但文本select未启用。 有人可以给一个小例子如何在pdf.js中启用文本select? 我已经尝试了几件事,但没有成功。 我的代码目前看起来像这样: PDFJS.getDocument('someRandom.pdf').then(function(pdf){ pdf.getPage(1).then(function(page) { // you can now use *page* here var scale = 1.5; var viewport = page.getViewport(scale); var canvas = document.getElementById('the-canvas'); var context = canvas.getContext('2d'); canvas.height = viewport.height; canvas.width = viewport.width; var renderContext = { canvasContext: context, viewport: viewport }; page.render(renderContext); }); }); 我还包括这个: <script src="../pdfjs/pdf.js"></script> <script>PDFJS.workerSrc ="../pdfjs/pdf.worker.js"</script> 此示例呈现PDF,但文本select未启用。 […]