2016-05-26 95 views
2

我有一些需要在Aurelia視圖中顯示的PDF文件。 這些文件不能直接鏈接 我有一個API函數返回一個字節數組。在Aurelia視圖中顯示PDF內容

在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/[email protected]/aurelia-dependency-injection.js:480:15) 
    at Object.invoke (http://localhost:65397/jspm_packages/npm/[email protected]/aurelia-dependency-injection.js:341:81) 
    at InvocationHandler.invoke (http://localhost:65397/jspm_packages/npm/[email protected]/aurelia-dependency-injection.js:300:168) 
    at Container.invoke (http://localhost:65397/jspm_packages/npm/[email protected]/aurelia-dependency-injection.js:564:25) 
    at StrategyResolver.get (http://localhost:65397/jspm_packages/npm/[email protected]/aurelia-dependency-injection.js:127:37) 
    at Container.get (http://localhost:65397/jspm_packages/npm/[email protected]/aurelia-dependency-injection.js:501:23) 
    at eval (http://localhost:65397/jspm_packages/npm/[email protected]/aurelia-templating.js:3925:73) 
End Inner Error Stack 
------------------------------------------------ 

import語句必須是失敗的,但pdfjs顯示爲我接收狀態200兩個[email protected]成功地加載和加載頁面時的pdfjs。

我找不到Aurelia/pdfjs應用程序的樣本。 重複:我需要嵌入流,因爲PDF不能通過HTTP訪問。

我不知道從這裏到

+0

我也努力尋找任何例子。你有沒有設法找到一個適當的例子? – DeVil

回答

1

走得太遠,因爲我知道沒有什麼特定的Aurelia路上大約加載PDF文件。

您可以使用pdf.js。它有方法getDocument接受存儲在字節數組中的二進制數據。

然後,您可以在視圖中放置一個畫布,在視圖激活過程中加載PDF數據,並在附加html後使用pdf.js將頁面呈現給它。例如代碼檢查通過toddmo回答這個職位:Pdf.js and viewer.js. Pass a stream or blob to the viewer