pdf未在cordova themeableBrowser

时间:2017-05-09 13:56:19

标签: pdf ionic-framework ionic2

我看到一些教程,在离子2中打开pdf,不应该下载给用户。所以我找到了Git hub repo

现在,当我下载项目并运行示例应用程序时,themeableBrowser中的pdf未打开..

它具有以下所有浏览器功能:

inAppBrowser

themeableBrowser

AndroidPDF

但是当我尝试inAppBrowser时,它运行正常。但我需要与themeableBrowser合作,因为我需要一个pdf不应该是可下载的。如果有人清楚我的这个问题,为什么这不是在Android平台上打开。

你可以下载回购,你可以使用它。

请帮帮我。它是我发现工作的唯一来源.. 感谢

1 个答案:

答案 0 :(得分:1)

ionic docs所述,您可以使用此themeablebrowser,这与您尝试使用的cordova themeablebrowser相同。

以下是工作代码段:

home.html档案中:

<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content>
    <button ion-button (click)="test()">Test browser</button>
</ion-content>

home.ts档案中:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { InAppBrowser } from '@ionic-native';
import { ThemeableBrowser, ThemeableBrowserOptions, ThemeableBrowserObject } from '@ionic-native/themeable-browser';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

    constructor(public navCtrl: NavController, private themeableBrowser: ThemeableBrowser) {

  }

  test() {
      const options: ThemeableBrowserOptions = {
          statusbar: {
              color: '#ffffffff'
          },
          toolbar: {
              height: 44,
              color: '#f0f0f0ff'
          },
          title: {
              color: '#003264ff',
              showPageTitle: true
          },
          backButton: {
              image: 'back',
              imagePressed: 'back_pressed',
              align: 'left',
              event: 'backPressed'
          },
          forwardButton: {
              image: 'forward',
              imagePressed: 'forward_pressed',
              align: 'left',
              event: 'forwardPressed'
          },
          closeButton: {
              image: 'close',
              imagePressed: 'close_pressed',
              align: 'left',
              event: 'closePressed'
          },
          customButtons: [
              {
                  image: 'share',
                  imagePressed: 'share_pressed',
                  align: 'right',
                  event: 'sharePressed'
              }
          ],
          menu: {
              image: 'menu',
              imagePressed: 'menu_pressed',
              title: 'Test',
              cancel: 'Cancel',
              align: 'right',
              items: [
                  {
                      event: 'helloPressed',
                      label: 'Hello World!'
                  },
                  {
                      event: 'testPressed',
                      label: 'Test!'
                  }
              ]
          },
          backButtonCanClose: true
      };

      const browser: ThemeableBrowserObject = this.themeableBrowser.create('https://docs.google.com/viewerng/viewer?url=www.pdf995.com/samples/pdf.pdf', '_blank', options);
  }

}

app.module.ts文件中,将ThemeableBrowser @ionic-native/themeable-browser添加到提供商。

添加app.module.ts文件后应如下所示:

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { ThemeableBrowser } from '@ionic-native/themeable-browser';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    ThemeableBrowser,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

这是您在启动的离子应用中需要的所有新增功能,以便您的主题浏览器能够正常运行。

Tested it on android emulator.