scroll and zoom two PDF pages

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
softschool
User
Posts: 5
Joined: Thu Jan 19, 2023 11:45 am

scroll and zoom two PDF pages

Post by softschool »

How to simultaneously scroll and zoom two PDF pages horizontally or vertically?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: scroll and zoom two PDF pages

Post by Tracker Supp-Stefan »

Hello softschool,

Are those two pages in the same document?
If they are - please make sure that you switch to "Two pages continuous" mode:
image.png
If you need to scroll two files - try the "Compare Documents" tool - that will generate a special file which will show the two side by side and you can then scroll both almost at the same time. (You might need to turn off the 'Filters' for that comparison file if the results are interfering with the smooth scrolling of both files side by side.)

Kind regards,
Stefan
softschool
User
Posts: 5
Joined: Thu Jan 19, 2023 11:45 am

Re: scroll and zoom two PDF pages

Post by softschool »

It is not the same document, you need to scroll or zoom the pages of the two documents synchronously to view or edit the document like Microsoft Word "view side by side".
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: scroll and zoom two PDF pages

Post by Tracker Supp-Stefan »

Hello softschool,

Even if it is two totally different documents - the "Compare" feature will show them side by side. You can then turn off all the filters so that the 'comparison' does not try to show you differences - and then they should scroll side by side.
I am offering this as a workaround as a true synchronous scrolling in not available for e.g. two files opened side by side in the main Editor window.

Kind regards,
Stefan
benep
User
Posts: 12
Joined: Thu Dec 08, 2022 7:14 am

Re: scroll and zoom two PDF pages

Post by benep »

Hi,

if you want to sync two documents you can try to run this code from the JavaScript console (run again to cancel sync):

Code: Select all

if (!Object.hasOwnProperty.call(global, 'scrollSync')) {
  global.scrollSync = {

  activeDocs: {},
  isActive: false,
  doc1: null,
  doc2: null,
  doc1ID: '',
  doc2ID: '',
  state1: '',
  timer: null,

  getSelectedEntry: function(lst) {
    for (const key in lst) {
      if (Object.hasOwnProperty.call(lst, key)) {
        const val = +lst[key];
        if ( val >= 0) return {key, val};
      }
    }
  },

  checkSync: function() {
    let cnt = 0;
    for (let i = 0; i < app.activeDocs.length; i++) {
      const docIDs = app.activeDocs[i].docID.join('');
      if (docIDs == this.doc1ID || docIDs == this.doc2ID) {
        cnt++;
      }
    }
    if (cnt < 2) {
      global.scrollSync.isActive = false;
      app.clearInterval(global.scrollSync.timer);
      app.alert('Synchronisation of views canceled because of missing document.',1);
    }
  },

  doSync: function() {
    global.scrollSync.checkSync();
    try {
      if (global.scrollSync.isActive) {
        const curState = JSON.stringify(global.scrollSync.doc1.viewState);
        if (curState != global.scrollSync.state1) {
          global.scrollSync.state1 = curState;
          global.scrollSync.doc2.viewState = JSON.parse(curState);
        }
      }
    } catch (err) {
      app.clearInterval(global.scrollSync.timer);
      global.scrollSync.isActive = false;
      console.println(JSON.stringify(err));
      app.alert('There was an unexpexted error! See JS-console for more information.');
    }
  },

  toggleSyncState: function() {
    const me = global.scrollSync;
    if (me.isActive) {
      me.isActive = false;
      app.clearInterval(me.timer);
      app.alert('Synchronisation canceled.',3);
      return;
    }
    if (app.activeDocs.length < 2) {
      app.alert('There need to be at least two opened documents.',1);
    } else {
      const dialog = {
        initialize: function(dlg) {
          const lst1 = {}, lst2 = {};
          me.activeDocs = {};
          for (let i = 0; i < app.activeDocs.length; i++) {
            const doc = app.activeDocs[i];
            const key = (i+1) + ' - ' + (doc.documentFileName.length ? doc.documentFileName : 'New Document*');
            lst1[key] = (i == 0 ? 1 : -1) * (i+1);
            lst2[key] = (i == 1 ? 1 : -1) * (i+1);
            me.activeDocs[key] = doc;
          }
          dlg.load({ lst1, lst2 });
        },
        commit: function(dlg) {
          const data = dlg.store();
          const s1 = me.getSelectedEntry(data.lst1);
          const s2 = me.getSelectedEntry(data.lst2);
          me.doc1 = me.activeDocs[s1.key];
          me.doc2 = me.activeDocs[s2.key];
          me.doc1ID = me.activeDocs[s1.key].docID.join('');
          me.doc2ID = me.activeDocs[s2.key].docID.join('');
          me.isActive = true;
          me.timer = app.setInterval('global.scrollSync.doSync()', 30);
        },
        validate: function(dlg) {
          const data = dlg.store();
          const s1 = me.getSelectedEntry(data.lst1);
          const s2 = me.getSelectedEntry(data.lst2);
          const id1 = me.activeDocs[s1.key].docID.join('');
          const id2 = me.activeDocs[s2.key].docID.join('');
          if (s1.val == s2.val || id1 == id2 ) {
            app.alert('Choose different files.',1);
            return false;
          }
          return true;
        },
        description: { name: 'Sync views', align_children: 'align_left', elements: [
          { type: 'static_text', name: 'Choose which documents shall be synced:' },
          { type: 'cluster', name: 'Doc 1 (parent)', align_children: 'align_left', elements: [
            { type: 'popup', item_id: 'lst1', width: 200 }
          ]},
          { type: 'cluster', name: 'Doc 2 (child)', align_children: 'align_left', elements: [
            { type: 'popup', item_id: 'lst2', width: 200 }
          ]},
          { type: 'ok_cancel', ok_name: 'sync', cancel_name: 'cancel' }
        ]}
      }

      if (app.execDialog(dialog) != 'ok' && me.isActive) {
        me.isActive = false;
        app.clearInterval(me.timer);
        app.alert('Synchronisation canceled.',3);
      }

    }
  }

  };
} else {
  if (typeof global.scrollSync.toggleSyncState == 'function') {
    global.scrollSync.toggleSyncState();
  } else {
    app.alert('There already is another scrollSync object without the toggle function!');
  }
}

Greetings
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: scroll and zoom two PDF pages

Post by Tracker Supp-Stefan »

Hello benep,

Many thanks for the script! That worked lovely (but I had to run it two times initially to get the dialogue to appear). And it syncs the second document with the first, while the second can be scrolled independently if needed.

May I ask where you got that one from?

Kind regards,
Stefan
benep
User
Posts: 12
Joined: Thu Dec 08, 2022 7:14 am

Re: scroll and zoom two PDF pages

Post by benep »

In the JavaScript for Acrobat API reference is an example which I adjusted a bit.
See https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/pdfs/acrobatsdk_jsapiref.pdf on page 259ff
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: scroll and zoom two PDF pages

Post by Tracker Supp-Stefan »

Hello benep,

Thanks for letting me know!

Kind regards,
Stefan
shade-cabin-hammock
User
Posts: 328
Joined: Wed Dec 22, 2021 6:33 am

Re: scroll and zoom two PDF pages

Post by shade-cabin-hammock »

Hi benep,

Thanks for taking the time to work on this and share it.

How do we install it?

Thanks! : )))))))))))))))))

SCH
Sincerely,

SCH
User avatar
rakunavi
User
Posts: 870
Joined: Sat Sep 11, 2021 5:04 am

Re: scroll and zoom two PDF pages

Post by rakunavi »

Hello benep,

Thank you for introducing us to the wonderful script, I am amazed at how much can be done with JavaScript. :o

shade-cabin-hammock wrote: Sun Mar 26, 2023 3:05 am How do we install it?
@SCH - I have commented on the following topic. Please refer to it.

Best regards,
rakunavi
TOP desires for PDFXCE
forum.pdf-xchange.com/viewtopic.php?t=39665 LassoTool
forum.pdf-xchange.com/viewtopic.php?t=38554 CmtGarbled
forum.pdf-xchange.com/viewtopic.php?t=37353 FulScrMultiMon
forum.pdf-xchange.com/viewtopic.php?t=41002 DisableTouchSelect
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: scroll and zoom two PDF pages

Post by Tracker Supp-Stefan »

Hello rakunavi,

Thanks for your help!

@SCH - you just open the JS console (Ctrl + J), then copy and paste the above code, and hit the Run button on the JS console's top left corner.

Kind regards,
Stefan
Post Reply