set zoomRatio to fit document to screen size
This commit is contained in:
parent
a820314362
commit
0060e2cb73
@ -72,6 +72,13 @@ function setLayerTransform(pageWidth, pageHeight, layerDiv) {
|
||||
layerDiv.style.translate = `${translate.X}px ${translate.Y}px`;
|
||||
}
|
||||
|
||||
function getDefaultZoomRatio(page, orientationDegrees) {
|
||||
const viewport = page.getViewport({scale: 1, rotation: orientationDegrees});
|
||||
const widthZoomRatio = document.body.clientWidth / viewport.width;
|
||||
const heightZoomRatio = document.body.clientHeight / viewport.height;
|
||||
return Math.max(Math.min(widthZoomRatio, heightZoomRatio, channel.getMaxZoomRatio()), channel.getMinZoomRatio());
|
||||
}
|
||||
|
||||
function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
|
||||
pageRendering = true;
|
||||
useRender = !prerender;
|
||||
@ -108,6 +115,14 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultZoomRatio = getDefaultZoomRatio(page, orientationDegrees);
|
||||
|
||||
if (cache.length === 0) {
|
||||
zoomRatio = defaultZoomRatio;
|
||||
newZoomRatio = defaultZoomRatio;
|
||||
channel.setZoomRatio(defaultZoomRatio);
|
||||
}
|
||||
|
||||
const viewport = page.getViewport({scale: newZoomRatio, rotation: orientationDegrees});
|
||||
|
||||
if (useRender) {
|
||||
|
@ -172,6 +172,21 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
||||
return mZoomRatio;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void setZoomRatio(final float ratio) {
|
||||
mZoomRatio = Math.max(Math.min(ratio, MAX_ZOOM_RATIO), MIN_ZOOM_RATIO);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public float getMinZoomRatio() {
|
||||
return MIN_ZOOM_RATIO;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public float getMaxZoomRatio() {
|
||||
return MAX_ZOOM_RATIO;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public int getDocumentOrientationDegrees() {
|
||||
return mDocumentOrientationDegrees;
|
||||
|
Loading…
Reference in New Issue
Block a user