4

I am using pdf.js to display a pdf. I would like the handtool to be on as the default setting, rather than people having to access it via clicking on the button.

This is the html button code:

  <button id="toggleHandTool" class="secondaryToolbarButton handTool" title="Enable hand tool" tabindex="27" data-l10n-id="hand_tool_enable">
              <span data-l10n-id="hand_tool_enable_label">Enable hand tool</span>
            </button>

This is the code on the .js document:

    var HandTool = {
  initialize: function handToolInitialize(options) {
    var toggleHandTool = options.toggleHandTool;
    this.handTool = new GrabToPan({
      element: options.container,
      onActiveChanged: function(isActive) {
        if (!toggleHandTool) {
          return;
        }
        if (isActive) {
          toggleHandTool.title =
            mozL10n.get('hand_tool_disable.title', null, 'Disable hand tool');
          toggleHandTool.firstElementChild.textContent =
            mozL10n.get('hand_tool_disable_label', null, 'Disable hand tool');
        } else {
          toggleHandTool.title =
            mozL10n.get('hand_tool_enable.title', null, 'Enable hand tool');
          toggleHandTool.firstElementChild.textContent =
            mozL10n.get('hand_tool_enable_label', null, 'Enable hand tool');
        }
      }
    });
    if (toggleHandTool) {
      toggleHandTool.addEventListener('click', this.toggle.bind(this), false);
    }

toggle: function handToolToggle() {
this.handTool.toggle();
SecondaryToolbar.close();
 },

Can I add something to my html to turn that on immediately after page load? Or can I change the .js file to do that?

4 Answers 4

9

I was just trying to achieve the same thing.

Apparently it's as simple as changing enableHandToolOnLoad: false to enableHandToolOnLoad: true in viewer.js.

Probably this wasn't possible at the time you've posted this question.

3

OK I worked it out.....

I added:

<body onLoad="HandTool.toggle()">

to the end of the html, just before

</body>
3

In viewer.js, turn cursorToolOnLoad to 1 in getDefaultPreferences.

1

You can do this call once the viewer page is initialized.

 PDFViewerApplication.pdfCursorTools.switchTool(1);

Select: 0, Hand: 1, Zoom: 2

1
  • Note: Zoom is defined in the code but only gives a switchTool: "2" is an unsupported value. message. Commented Feb 26 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.