首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ionic2中的PDFJS

ionic2中的PDFJS
EN

Stack Overflow用户
提问于 2016-08-26 06:22:26
回答 2查看 1.7K关注 0票数 0

谁能解释如何在ionic2项目中添加pdfjs,这样我们就可以导入和使用it.Thanks了。

我知道如何使用pdfjs,但无法找到在ionic2项目中导入pdfjs的任何方法。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-10-04 14:23:35

我遵循的步骤是在ionic2.中集成pdfjs。

代码语言:javascript
复制
1 . I created a lib folder inside app folder of ionic2 project and
copied all the pdfjs library files such as js, image, css and html
file inside  lib folder.

2. Wrote a gulp task to add these files into the www > build folder.

这些步骤将把pdfjs添加到ionic2项目中。

在类型记录中使用它的步骤

代码语言:javascript
复制
openPdf(): void {

        var _self = this;

        setTimeout(() => {

            this.pdfjsframe = document.getElementById('pdfViewer');

            if (this.pdfjsframe != null) {
                this.pdfjsframe.onload = function () {
                    _self.loadPdfDocument();
                };
            }

        }, 0);
    }

    loadPdfDocument() {
        var pdfData = this.base64ToUint8Array(this.fileBase64);
        this.pdfjsframe.contentWindow.PDFViewerApplication.open(pdfData);
    }

    base64ToUint8Array(base64) {
        var raw = atob(base64);
        var uint8Array = new Uint8Array(raw.length);
        for (var i = 0; i < raw.length; i++) {
            uint8Array[i] = raw.charCodeAt(i);
        }
        return uint8Array;
    }

用于显示的

代码语言:javascript
复制
 <div id="frameContainer" class="pdfViewerContainer" *ngIf="isPdf">
    <iframe id="pdfViewer" src="build/viewer.html" class="pdfViewerFrame" allowfullscreen> </iframe>
  </div>

css

代码语言:javascript
复制
.pdfViewerContainer
{
    position: fixed;
    height: 100%;
    left: 0px;
    bottom: 0px !important;
    right: 0px;
    z-index: 1;
}

.pdfViewerFrame
{
    width:100%;
    height: 93.5%;
}

.viewerNavbar
{
    position: relative; z-index: 2;
}

css需要改进

注意:我在viewer.js open方法中做了一些更改,希望字节数组作为输入参数。

票数 1
EN

Stack Overflow用户

发布于 2017-03-08 09:48:47

我在一个项目中使用pdfjs,这就是我所做的:-我将pdfjs.js保存在我的资产文件夹中。-我从src/index.html导入

代码语言:javascript
复制
<script src="assets/js/jspdf.debug.js"></script> 
  • 我在代码声明中使用它。在我的例子中,我正在使用它在服务/提供者中重用我的应用程序的任何部分,注入它。
代码语言:javascript
复制
declare let jsPDF;

在您可以无问题地使用之后:

代码语言:javascript
复制
var doc = new jsPDF();
doc.setFontStyle('bold');
doc.text(20, 20, "Parte de Trabajo Número " + serieId);
doc.text(20, 30, "Cliente: " + parte.nombre);
doc.text(20, 40, "Fecha: " + parte.fechaformato);
doc.text(20, 50, "Horas: " + parte.horainiformato + ' a ' + parte.horafinformato);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39159584

复制
相关文章

相似问题

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