New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify "to fit page width/height into constrained box" use case #5628
Comments
This comment has been minimized.
This comment has been minimized.
There is also another option: give user base viewport already pre-scaled using some utility function, for example:
and document this... or even utility to allow autoscale/align |
Initial problem was "to fit page width/height into constrained box", so probably we shall look into solving/making it more convinient first. |
Any update on this matter? I'm trying to get a page to fit into a box. When manually specifying the canvas width, things worked smoothly. Now though, to get Annotation layers to work, I'm using the web/pdf_viewer.js file and I can't get the same scaling to work. I have code like so: var container = document.getElementById("container");
const i = 1
// Get desired page
pdf.getPage(i).then(function(pdfPage) {
const scale = container.offsetWidth / pdfPage.getViewport(1.0).width;
var pdfPageView = new PDFJS.PDFPageView({
container: container,
id: i,
scale: scale,
defaultViewport: pdfPage.getViewport(scale),
// We can enable text/annotations layers, if needed
textLayerFactory: new PDFJS.DefaultTextLayerFactory(),
annotationLayerFactory: new PDFJS.DefaultAnnotationLayerFactory()
});
// Associates the actual page with the view, and drawing it
pdfPageView.setPdfPage(pdfPage);
return pdfPageView.draw();
}); When calling pdfPage.getViewport(1).width, it returns 612 - but when rendered with a scale of Thanks for any guidance you may be able to provide! |
Get deep into the |
Could we get some kind of documentation as to why this is been used? I'm just artificially removing this factor at the moment (which sucks for readability...) |
In the html/css world 1in = 96pixels, in PDF the default is 1in = 72pixels. The scale is used so when showing 100% a PDF that is 8.5in should show up on the screen as 8.5in. |
I experienced the same thing as isTravis. Viewport.width was 612, but pdf was rendering 816. My work around was just to declare CSS_UNITS again locally so I could use it to recalculate the scale like this:
|
thanks @joshuahutchison for the example, I had a similar problem and this fixed it :) |
For example, remove CSS_UNIT scaling from the pdf_page_view.js or make it configurable.
There is a confusion when there is an attempt to fit pdfpageview into width/height constraints, see http://logs.glob.uno/?c=mozilla%23pdfjs#c29228
The text was updated successfully, but these errors were encountered: