2017-04-19 23 views
0

我做了一個應用程序,它會使用應用程序內瀏覽器,工作在Android和IOS良好的顯示PDF文件。但我的客戶需要PDF文件不應該爲用戶下載。那麼有沒有其他方法可以單獨顯示PDF文件進行預覽。如何打開離子應用程序內無PDF下載選項或使用inappbrowser沒有允許用戶下載

我聽說過iframe,但無法獲得任何示例代碼將如何工作。請幫助我。

<form class="list cls0Padding" > 
     <div class="item item-body cls0Padding cls0Border"> 
      <div class="row cls0Padding"> 
       <div class="col col-50 clsGrid" href="#" onclick="window.open('http://www.orimi.com/pdf-test.pdf', '_system', 'location=yes'); return false;"> 
        <div class="clsGridOverlay"><span class="clsGridTitle">PDF</span></div> 
       </div> 
       <div class="col col-50 clsGrid" href="#" ng-click="playVideo()"> 
        <div class="clsGridOverlay"><span class="clsGridTitle"> VIDEOS</span></div> 
       </div> 
      </div> 
     </div> 
    </form> 

我的控制器:

$window.OpenLink = function(link) { 
    window.open(link, '_system'); 
    }; 

提前感謝!

回答

0

我懷疑查看實際的PDF,將需要下載。 顯示PDF其他方式將rasterise PDF中的服務器上(每個頁面轉換爲圖像),並創建一個查看器來查看圖像。

+0

做es iframe會根據我需要顯示PDF文件而無需下載? –

+0

iframe實際上是瀏覽器內的瀏覽器,因此將應用相同的規則。 –

+0

你能幫我嗎,我怎麼把PDF轉換成圖像並顯示。我受到了3天以上的打擊。無法找到解決方案 –

0

安裝cordova plugin add org.apache.cordova.inappbrowser 在Android的情況下,我們使用GoogleDocs打開默認的PDF文件android瀏覽器不支持pdf查看。 iOS能夠像往常一樣微笑地處理pdf本身。

例子:

$scope.view_link = function (url, link_type) { 
      if (ionic.Platform.isAndroid()) { 
       if (link_type !== undefined && link_type !== null) { 
        if (link_type.toLowerCase() !== 'html') { 
         url = 'https://docs.google.com/viewer?url=' + encodeURIComponent(url); 
        } 
       } 
      } 
      var ref = window.open(url, '_blank', 'location=no'); 
     } 

更多https://github.com/apache/cordova-plugin-inappbrowser/blob/8ce6b497fa803936784629187e9c66ebaddfbe1b/doc/index.md

,如果你正在尋找iframe嘗試這樣的事情

<iframe ng-src="{{pdfurl}}" style="width:100%; height: 100%;"></iframe> 
在控制器

..

$scope.pdfurl =$sce.trustAsResourceUrl('https://docs.google.com/viewer?url=' + encodeURIComponent($scope.pdf)); 
+0

哦,你在這裏非常感謝。但我的客戶在沒有下載pdf的情況下詢問。它只是預覽alone.So通過使用inappbrowser已經,我已經安裝。我可以做到這一點,沒有下載 –

+0

但使用iframe我怎麼處理onclick功能。 Bec我有兩個網格視圖,如果我按網格,然後我的PDF將打開。請查看我的更新代碼 –

+0

,以便更新我的代碼如何處理iframe,以便在不下載的情況下打開我的pdf –

相關問題