Comments (9)
Here is a patch (JS version) to use SVG rendering:
PdfViewerComponent.prototype.renderPage = function (pageNumber) {
var _this = this;
return this._pdf.getPage(pageNumber).then(function (page) {
var viewport = page.getViewport(_this._zoom, _this._rotation);
var container = _this.element.nativeElement.querySelector('div');
var canvas = document.createElement('canvas');
var div = document.createElement('div');
if (!_this._originalSize) {
viewport = page.getViewport(_this.element.nativeElement.offsetWidth / viewport.width, _this._rotation);
}
if (!_this._showAll) {
_this.removeAllChildNodes(container);
}
div.appendChild(canvas);
// container.appendChild(div);
// Set dimensions
container.style.width = viewport.width + 'px';
container.style.height = viewport.height + 'px';
// SVG rendering by PDF.js
page.getOperatorList()
.then(function (opList) {
var svgGfx = new window.PDFJS.SVGGraphics(page.commonObjs, page.objs);
return svgGfx.getSVG(opList, viewport);
})
.then(function (svg) {
container.appendChild(svg);
});
return;
This is the best solution. Rendering quality is optimal on all platforms and performance seems to be better too.
Reference: https://www.sitepoint.com/custom-pdf-rendering/
from ng2-pdf-viewer.
My patch above uses SVG and not a higher resolution bitmap. Performance is therefore better. Please consider adding SVG support too.
from ng2-pdf-viewer.
@cbratschi may i have demo ?
from ng2-pdf-viewer.
@liangwenzhong We are using the patch as part of an Ionic 2 project. Rendering quality is great on iOS and desktop devices. There was only a problem with a missing font we fixed by updating some PDFs. Unfortunately I cannot provide an online demo because this is a private business app.
from ng2-pdf-viewer.
@cbratschi i also use ionic 2 !~ i think we doing the same thing !~but i still have a problem ~~can i use the pinch event ? i wanna zoom the pdf file ~~~~have u did this ?
from ng2-pdf-viewer.
@liangwenzhong The SVG based rendering should be fine for zooming without quality loss. What I would need is resize support e.g. from portrait to landscape on mobile devices. Pinching is probably more complicated as this discussion exhibits:
I hope the SVG patch will be integrated soon.
from ng2-pdf-viewer.
@cbratschi thanks for ur replay so much !~ i have anothre problem . i use ur script below:
PdfViewerComponent.prototype['renderPage'] = function(pageNumber) {
var _this = this;
return this._pdf.getPage(pageNumber).then(function(page) {
var viewport = page.getViewport(_this._zoom, _this._rotation);
var container = _this.element.nativeElement.querySelector('div');
var canvas = document.createElement('canvas');
var div = document.createElement('div');
if (!_this._originalSize) {
viewport = page.getViewport(_this.element.nativeElement.offsetWidth / viewport.width, _this._rotation);
}
if (!_this._showAll) {
_this.removeAllChildNodes(container);
}
div.appendChild(canvas);
container.appendChild(div);
// SVG rendering by PDF.js
page.getOperatorList()
.then(function(opList) {
var svgGfx = new window['PDFJS'].SVGGraphics(page.commonObjs, page.objs);
return svgGfx.getSVG(opList, viewport);
})
.then(function(svg) {
container.appendChild(svg);
});
return;
});
}
a very strange problem happened~
the page's become inverted order . the page2 go to the first page ,the page1 go to the second page .
have u resolve this ? :)
from ng2-pdf-viewer.
@cbratschi i fix the inverted order problem . :) like:
but, i got another problem -.- !~
how to catch the error event ? if an error happened?how can i catch?
just like : if error ,i have to hide the loading and alert some tips .
from ng2-pdf-viewer.
@cbratschi did the change in 1.1.4
from ng2-pdf-viewer.
Related Issues (20)
- 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
- Range requests / partial responses do not work in chrome
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.