【问题标题】:Display PDF Content in an Aurelia View在 Aurelia 视图中显示 PDF 内容
【发布时间】:2016-05-26 18:42:55
【问题描述】:

我有一些 PDF 文件需要在 Aurelia 视图中显示。 这些文件不能通过直接链接获得 我有一个返回字节数组的 API 函数。

在 ASP.Net 中,我可以控制响应对象的标头和内容类型,并且可以将内容 BinaryWrite 写入响应。

我不知道如何在 Aurelia 中执行此操作。 有什么建议吗?

编辑: 我正在尝试按照建议使用 pdf.js。 Aurelia 中的注射失败。

import {inject} from "aurelia-framework";
import {HttpClient} from "aurelia-fetch-client";
import {PDF} from "pdfjs-dist"

@inject(Router, HttpClient, PDF)
export class PDFView {

    constructor(router, http, pdf) {

        this.router = router;
        this.http = http;
        this.pdf = pdf;

    }

控制台显示此错误:

Inner Error:
Message: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?
Inner Error Stack:
Error: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?
    at Container.get (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection@1.0.0-beta.1.2.3/aurelia-dependency-injection.js:480:15)
    at Object.invoke (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection@1.0.0-beta.1.2.3/aurelia-dependency-injection.js:341:81)
    at InvocationHandler.invoke (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection@1.0.0-beta.1.2.3/aurelia-dependency-injection.js:300:168)
    at Container.invoke (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection@1.0.0-beta.1.2.3/aurelia-dependency-injection.js:564:25)
    at StrategyResolver.get (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection@1.0.0-beta.1.2.3/aurelia-dependency-injection.js:127:37)
    at Container.get (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection@1.0.0-beta.1.2.3/aurelia-dependency-injection.js:501:23)
    at eval (http://localhost:65397/jspm_packages/npm/aurelia-templating@1.0.0-beta.1.2.7/aurelia-templating.js:3925:73)
End Inner Error Stack
------------------------------------------------

导入语句肯定失败,但 pdfjs 似乎加载成功,因为我在页面加载时收到 pdfjs-dist@1.5.294.js 和 pdfjs 的状态 200。

我找不到 Aurelia / pdfjs 应用程序的示例。 重复:我需要嵌入流,因为 PDF 不能通过 HTTP 获得。

我不知道从这里去哪里

【问题讨论】:

  • 我也在努力寻找任何例子。你有没有找到合适的例子?

标签: pdf aurelia pdf.js


【解决方案1】:

据我所知,关于加载 pdf 文件,Aurelia 并没有什么特别之处。

您可以使用pdf.js。它有方法 getDocument 接受存储在字节数组中的二进制数据。

然后您可以在视图中放置一个画布,在视图激活期间加载 pdf 数据,并在附加 html 后使用 pdf.js 将页面呈现到其中。例如,toddmo 对此帖子的代码检查答案:Pdf.js and viewer.js. Pass a stream or blob to the viewer

【讨论】:

    猜你喜欢
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 2018-10-10
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多