Comments (9)
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.
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.
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.
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.
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
any hints or clues how to do this? thanks very much !
from ng2-pdf-viewer.
@nessgor, did you bind pdfDidLoad
function to your class ?
from ng2-pdf-viewer.
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.
You need to add to the constructor
of PDFContentPage
:
this.pdfDidLoad = this.pdfDidLoad.bind(this);
from ng2-pdf-viewer.
It works!! thanks a lot !!
from ng2-pdf-viewer.
Related Issues (20)
- Uncaught TypeError: B.split(...).at is not a function
- Integrating custom script/features of adobe acrobat with ng2-pdf-viewer
- Pdf viewer shows stuck to load pdf file on Iphone 12 /13 HOT 1
- Hello everyone, I'm using pdf viewer version 6.3.2 and it runs fine locally but after build and publish I'm having this issue Refused to create a worker from 'blob
- Support for Angular version v17 HOT 4
- ReferenceError: Cannot access module before initialization ionic angular android 12 HOT 1
- 'PdfViewerModule' does not appear to be an NG module class
- ng2-pdf-viewer not working in Angular 17
- Getting Error "Worker was Destroyed" while loading large sized Pdf.
- Not works in IOS
- pef(Listeners): not removed
- Appending Date and Time with author name in annotation yellow text popup
- Any plans to upgrade to latest pdf.js version HOT 1
- Large file not shows starting pages quickly, is there any way to control chunk requests' sequence for linearization?
- How to get total page count of PDF? HOT 1
- CSP unsafe-inline directive blocks pdf viewer
- Not rendering PDF in angular 17, ng2-pdf-viewer : v10.0.0 HOT 1
- Perticular renge load like pages 5-12 only
- Can't show pdf error ERR_CERT_DATE_INVALID HOT 3
- Thumbnail View I have shown up but scroll issue happned
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng2-pdf-viewer.