Coder Social home page Coder Social logo

Comments (9)

VadimDez avatar VadimDez commented on May 24, 2024

Did you try to pass callback to [on-load-complete] ? There you can get pdf once it's loaded. See https://github.com/VadimDez/ng2-pdf-viewer#on-load-complete

from ng2-pdf-viewer.

ctbolton avatar ctbolton commented on May 24, 2024

Thanks Vadim. I did try that. I can see the number of pages from the PDF in the on-load-complete function but the UI isnt showing the update. I'm sure it has to do with it updating after the UI has already completed rendering or a parent/child type scope issue. I've tried using the NgZone as well as some other "digest update" type features as well, but can't seem to get it to work.

from ng2-pdf-viewer.

VadimDez avatar VadimDez commented on May 24, 2024

It may be because you didn't bind the callback function, did you?
Otherwise show what are you trying to do in the callback function.

from ng2-pdf-viewer.

ctbolton avatar ctbolton commented on May 24, 2024

Thanks Vadim. I took another look at your latest check in for the zoom property and got it working. Thanks again for the super fast response!

from ng2-pdf-viewer.

nessgor avatar nessgor commented on May 24, 2024

Hello @VadimDez I got a similar issue

  pdfDidLoad(pdf: any) {
    this.totalPages = pdf.numPages;
    console.log(this);
    console.log(pdf);
  }

I want to retrieve the numPages variable and set to the totalPages variable to my own class
but "this." is referencing to the PDFViewerComponent Class, not my own class

image

any hints or clues how to do this? thanks very much !

from ng2-pdf-viewer.

VadimDez avatar VadimDez commented on May 24, 2024

@nessgor, did you bind pdfDidLoad function to your class ?

from ng2-pdf-viewer.

nessgor avatar nessgor commented on May 24, 2024

Don't know how to bind the pdfDidLoad function to my class, by adding the [on-load-complete] ??

pdf.html

<ion-header>
    <ion-toolbar>
        <ion-buttons left>
            <button ion-button (click)="dismiss()">
        <ion-icon name="arrow-round-back"></ion-icon>
      </button>
        </ion-buttons>
        <ion-title>
            {{name}}
        </ion-title>
    </ion-toolbar>
</ion-header>

<ion-content scroll="false">
    <ion-scroll class="zoom-pane" scrollX="true" scrollY="true" zoom="true" maxZoom="3">
        <pdf-viewer [src]="pdfSrc" [page]="page" [original-size]="true" [zoom]="zoom" [show-all]="false" [on-load-complete]="pdfDidLoad"></pdf-viewer>
    </ion-scroll>
</ion-content>

<ion-footer>
    <ion-item>
        <ion-range min="1" [max]="totalPages" step="1" snaps="true" color="secondary" [(ngModel)]="page">
            <ion-label range-left>
                <button ion-button (click)="prevPage()">
                    <ion-icon name="arrow-round-back"></ion-icon>
                </button> 1
            </ion-label>
            <ion-label range-right>
                {{totalPages}}
                <button ion-button (click)="nextPage()">
                    <ion-icon name="arrow-round-forward"></ion-icon>
                </button>
            </ion-label>
        </ion-range>
    </ion-item>
</ion-footer>

pdf.ts

import { Component } from '@angular/core';
import { NavParams, NavController, LoadingController } from 'ionic-angular';
import { URL } from '../../url';

@Component({
  selector: 'page-pdf',
  templateUrl: 'pdf.html'
})

export class PDFContentPage {
  name: string;
  pdfSrc: string;
  zoom: number = 0.9;
  page: number = 1;
  totalPages: number;
  loading: any;

  constructor(
    public params: NavParams,
    public navCtrl: NavController,
    public loadingCtrl: LoadingController,
  ) {
    this.name = this.params.get('name');
    this.pdfSrc = URL.BASE_URL + this.params.get('url');

    this.loading = this.loadingCtrl.create({
      content: 'Loading pdf...',
      spinner: "crescent",
      dismissOnPageChange: false,
      duration: 5000
    });
    this.loading.present();
  }

  dismiss() {
    this.navCtrl.pop();
  }

  prevPage() {
    if (this.page > 1) {
      this.page--;
    }
  }
  nextPage() {
    if (this.page < this.totalPages) {
      this.page++;
    }
  }

  pdfDidLoad(pdf: any) {
    this.totalPages = pdf.numPages;
    console.log(this);
    console.log(pdf);
  }

  ionViewDidEnter() {
    this.loading.dismiss();
  }

}

from ng2-pdf-viewer.

VadimDez avatar VadimDez commented on May 24, 2024

You need to add to the constructor of PDFContentPage:

this.pdfDidLoad = this.pdfDidLoad.bind(this);

from ng2-pdf-viewer.

nessgor avatar nessgor commented on May 24, 2024

It works!! thanks a lot !!

from ng2-pdf-viewer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.