PDFs are getting rendered vertically mirrored
See original GitHub issueConfiguration:
- Web browser and its version: Google Chrome Version 71.0.3578.98 (Official Build) (64-bit)
- Operating system and its version: Tried on Ubuntu 18.04 and Windows 10
- PDF.js version: 2.0.943 (current from npm)
- Is a browser extension: no
Steps to reproduce the problem:
I’ve copied the code from https://mozilla.github.io/pdf.js/examples/#hello-world-with-document-load-error-handling and changed 2 things:
- added authorization headers (works fine when in jsfiddle)
viewport.height
and.width
both areNaN
, so I’ve added a fallback to viewBox-properties
var loadingTask = pdfjsLib.getDocument({
url: url,
httpHeaders: {
'Authorization': server.headers.get('Authorization')
}
});
loadingTask.promise.then(function (pdf) {
console.log('PDF loaded');
// Fetch the first page
var pageNumber = 1;
pdf.getPage(pageNumber).then(function (page) {
console.log('Page loaded');
var scale = 1.5;
var viewport = page.getViewport({
scale: scale
});
// Prepare canvas using PDF page dimensions
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height ||viewport.viewBox[3]; /* viewport.height is NaN */
canvas.width = viewport.width || viewport.viewBox[2]; /* viewport.width is also NaN */
// Render PDF page into canvas context
var renderContext = {
canvasContext: context,
viewport: viewport
};
var renderTask = page.render(renderContext);
renderTask.promise.then(function () {
console.log('Page rendered');
});
});
}, function (reason) {
// PDF loading error
console.error(reason);
});
What is the expected behavior?
Correct Rendering of the PDF
What went wrong? (add screenshot)
As you can see, the PDF is vertically mirrored. This is not a problem with this specific PDF, as it is rendered correctly here and the issue happens with any other PDFs I’ve tested.
I think it has something to do with viewport.heightand
.widthbeing
NaN` and/or the fact that the example uses a newer (2.1.something) version of PDF.js, but I’d like to use the npm package.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
When I print my PDF document, it is showing as a mirror ...
Answer: In Adobe, select the 'Print' command and then select the 'Advanced' button within the print status window. Lastly, select the option 'Print...
Read more >PDF.JS PDF is not rendering properly, appears mirrored and ...
The PDF is upside down and mirrored. I've looked around and a common cause of this is re-using the canvas for multiple renders,...
Read more >Advanced PDF print settings - Acrobat Pro - Adobe Support
Mirrors the imageable area across the horizontal and vertical axes so that it is wrong reading. Type is readable when the photosensitive layer ......
Read more >3 Free and Best Ways to Mirror PDF Easily - UPDF
1. Mirror the page without rasterizing the document ... The easiest method is to print from the PDF machine with Postscript mirroring. To...
Read more >Downloading or delivering dashboards in rendered formats
By default, a PDF file mirrors what you see when you view the dashboard in your browser at a width of 1680 pixels....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think it may be because of:
Could you try with
var viewport = page.getViewport(scale);
to see if that works? If so, we need to make a new release because this recently changed and we updated the examples already.var viewport = page.getViewport(scale);
fixed the problem, thank you.