Ng2-pdf-viewer: Is there any possible way to implement pinch & zoom function in the container canvas?

Created on 14 Oct 2016  路  17Comments  路  Source: VadimDez/ng2-pdf-viewer

For example using hammer.js?

http://hammerjs.github.io/

enhancement help wanted stale

Most helpful comment

  <pinch-zoom>
    <div class="oat-pdf-container">
      <pdf-viewer [src]="pdfSrc"
        [autoresize]="true" 
        [original-size]="false"
        [show-all]="true"
        [zoom]="currentZoom"
        style="display: block;"
      ></pdf-viewer>
    </div>
  </pinch-zoom>

All 17 comments

Looking forward to this feature, as I am applying this to a mobile app.

+1

Any news on this? I can't use this without pinch zoom.

I also am looking for this

Anyone Implemented this? Help needed!

I implemented this in Ionic 3.9.2 in a modal. Here is a Gist to show how to implement.

@tabirkeland That's with buttons though. What about the pinch gesture?

@jtcrowson I have not had the chance to try it which pinch.

You could try using the "pinch" gesture outlined here and calling the zoomIn() and zoomOut() functions depending on user input.

Biggest issue with using a gesture framework (like hammer.js) on the ng2-pdf-viewer is that it disables touch scrolling.

Any luck?

waiting for this as well, tried to get it to work myself but no luck... :(

I got it to work with pinch (although it's not very smooth), but couldn't get scroll to work with it.

using hammerjs it is something like that

const container: HTMLElement = document.getElementById('pdf-file-container');

const hammer = new Hammer(container, {
  domEvents: true
});

hammer.get('pinch').set({
  enable: true
});

hammer.on('pinchend', (event: any) => {
  // get the current zoom value
  let zoom = this.currentZoom;
  // get the scaled amount
  const scale = zoom * event.scale / 10;
  // if the user is zooming in
  if (event.additionalEvent === 'pinchout') {
    zoom += scale;
  } else {
    // if zooming out
    zoom -= scale * 10;
  }

  // if zoom is too small or too big set them to max values
  if (zoom < 1) {
    zoom = 1;
  } else if (zoom > 2) {
    zoom = 2;
  }

  // set the current zoom
  this.currentZoom = zoom;
});

i am not sure if there is a better way but this works fine currently

for ionic 3 users here i found an work arround

using ngx-pinch-zoom, specific query google

  <pinch-zoom>
    <div class="oat-pdf-container">
      <pdf-viewer [src]="pdfSrc"
        [autoresize]="true" 
        [original-size]="false"
        [show-all]="true"
        [zoom]="currentZoom"
        style="display: block;"
      ></pdf-viewer>
    </div>
  </pinch-zoom>

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Gianlu82b19 picture Gianlu82b19  路  4Comments

viktorhajer picture viktorhajer  路  7Comments

kevinariasf picture kevinariasf  路  6Comments

kuba007 picture kuba007  路  3Comments

yashwanth493 picture yashwanth493  路  7Comments