PDF.js Integration Guide

Integrate Sabrina's 10 Key into your PDF viewer

Overview

This guide will help you integrate Sabrina's 10 Key adding machine calculator directly into your PDF.js viewer, allowing you to perform calculations while reviewing PDF documents.

Prerequisites

Installation Steps

Step 1: Download Integration Files

  1. Download the PDF.js integration package from the website
  2. Extract the files to a temporary directory
  3. You should have the following files:
    • sabrina-tenkey-integration.js - Main integration script
    • popup.html - Calculator interface with embedded logic
    • manifest.json - Configuration file

Step 2: Copy Files to PDF.js Directory

Copy the following files to your PDF.js web directory:

your-pdfjs-directory/ ├── web/ │ ├── viewer.html (existing) │ ├── viewer.js (existing) │ ├── sabrina-tenkey-integration.js (new) │ └── popup.html (new)

Step 3: Modify viewer.html

Add the integration script to your viewer.html file. Insert this line before the closing </body> tag:

<!-- Sabrina's 10 Key Integration --> <script src="sabrina-tenkey-integration.js"></script> </body>

Step 4: Configure Integration (Optional)

You can customize the integration by modifying the initialization in viewer.html:

<script> // Custom configuration document.addEventListener('DOMContentLoaded', function() { window.sabrinas10Key = new Sabrinas10KeyIntegration({ position: 'bottom-right', // Options: top-left, top-right, bottom-left, bottom-right, center toggleKey: 'Alt+T', // Keyboard shortcut to toggle calculator autoHide: true, // Hide calculator on startup width: '320px', // Calculator width height: '500px' // Calculator height }); }); </script>

Usage Instructions

Opening the Calculator

Calculator Features in PDF.js

  1. Floating Panel: The calculator appears as a floating panel that can be dragged anywhere on screen
  2. Always on Top: Calculator stays above the PDF content
  3. Resizable: Drag edges to resize (if enabled)
  4. Auto-Hide: Automatically hides when not in use

Keyboard Shortcuts

While the calculator is open:

Advanced Integration

Copying Results to PDF Annotations

To enable copying calculator results directly to PDF annotations:

// In your viewer.js or custom script window.addEventListener('message', function(e) { if (e.data.type === 'calculatorResult') { // Get current annotation tool const annotationManager = PDFViewerApplication.pdfViewer.annotationManager; if (annotationManager) { // Create text annotation with result annotationManager.createTextAnnotation({ page: PDFViewerApplication.page, text: e.data.value, x: lastClickX, y: lastClickY }); } } });

Persistent Tape History

To save calculator tape between sessions:

// Add to sabrina-tenkey-integration.js saveTapeHistory() { const tape = this.iframe.contentWindow.getTapeData(); localStorage.setItem('sabrinas10key_tape', JSON.stringify(tape)); } loadTapeHistory() { const tape = localStorage.getItem('sabrinas10key_tape'); if (tape) { this.iframe.contentWindow.setTapeData(JSON.parse(tape)); } }

Troubleshooting

Calculator Doesn't Appear

  1. Check browser console for errors
  2. Verify all files are in correct directories
  3. Ensure popup.html path is correct in the integration script
  4. Check if popup blockers are interfering

Keyboard Shortcuts Not Working

  1. Ensure PDF viewer has focus
  2. Check for conflicts with PDF.js shortcuts
  3. Try different shortcut combinations

Calculator Loads But Doesn't Function

  1. Verify popup.html loaded correctly with embedded JavaScript
  2. Check for JavaScript errors in console
  3. Ensure no Content Security Policy violations

Browser Compatibility

Security Considerations

Customization Options

Styling

Modify the container styles in sabrina-tenkey-integration.js:

this.container.style.cssText = ` position: fixed; width: ${this.options.width}; height: ${this.options.height}; // Add your custom styles here `;

Adding Custom Buttons

Extend the title bar with custom actions:

titleBar.innerHTML += ` <button onclick="window.sabrinas10Key.minimize()">_</button> <button onclick="window.sabrinas10Key.maximize()">□</button> `;
Note: This integration is provided as-is for use with legally obtained copies of PDF.js.
← Back to Home 📦 Download Integration Package