A: Simply add a script tag to your HTML:
<script src="https://cdn.jsdelivr.net/gh/BrunoRNS/SimplePDFviewer@latest/min/core.min.js"></script>Or download core.min.js and host it locally. See the Installation section in the USAGE guide for more options.
A: SimplePDFviewer requires:
- A modern web browser (Chrome 45+, Firefox 40+, Safari 10+, Edge 12+)
- Internet connection (if using CDN-hosted PDFs)
- JavaScript enabled
For optimal experience on older browsers, consider adding polyfills for ResizeObserver and Promises.
A: No, SimplePDFviewer is designed for the browser only. It uses browser APIs like DOM, Canvas, and ResizeObserver that don't exist in Node.js. For server-side PDF rendering, consider other solutions like pdf-lib or PDFKit.
A: Yes! SimplePDFviewer uses CSS classes that you can override. See Customization section for detailed styling examples. You can change colors, fonts, sizes, and layout.
A: Yes! SimplePDFviewer now includes text selection support enabled by default. Users can:
- Highlight and select text directly from PDF pages
- Copy text to clipboard with Ctrl+C / Cmd+C
- Paste selected text into other applications
- Toggle text selection on/off as needed
Text Selection Features:
- Enabled by default (no configuration needed)
- Uses a transparent overlay that doesn't affect PDF visibility
- Automatically renders for every page
- Can be disabled at startup or toggled at runtime
Disable Text Selection:
// Option 1: Disable at initialization
const viewer = PDFViewer.init(container, course, {
enableTextSelection: false
});
// Option 2: Disable after initialization
viewer.setTextSelectionEnabled(false);
// Check current state
if (viewer.enableTextSelection) {
console.log('Text selection is enabled');
}How It Works:
Text selection uses pdf.js's TextLayerBuilder to create a transparent text layer positioned on top of the PDF canvas. This allows users to select text without affecting the visual rendering of the PDF. The text layer is automatically created when each page loads and can be toggled without reloading.
A: Text selection has minimal performance impact:
- Rendering: The transparent text layer renders asynchronously after the PDF canvas, so it doesn't slow down page display
- Memory: The text layer adds a small amount of memory for DOM elements and text content
- Optional: Can be disabled entirely if not needed, eliminating any overhead
- Efficient: Uses pdf.js's optimized TextLayerBuilder implementation
Most users will notice no performance difference. For very large documents (500+ pages), disabling text selection can provide a minor improvement in memory usage.
A: Currently, text selection styling uses the browser's default selection color. You cannot customize the highlight color or make the text layer visible without disabling it. The transparent overlay design is intentional to preserve the original PDF appearance.
If you need advanced text selection features (custom colors, annotations, highlighting save), consider using the full pdf.js library directly.
A: Yes! SimplePDFviewer now includes built-in zoom controls (100-200% zoom range) with:
- Zoom in/out buttons in the toolbar
- Manual zoom input field
- Automatic zoom reset to 100% when navigating pages
// Control zoom programmatically
viewer.setZoom(150); // Set to 150%
console.log(viewer.zoom); // Current zoom: 150
// Click Next/Previous - zoom automatically resets to 100%
viewer.nextPage(); // zoom = 100 after navigationFor CSS-based scaling (alternative), you can still use transforms:
.pdf-viewer-canvas-container {
transform: scale(1.2);
transform-origin: top center;
}See Zoom Control in the USAGE guide for details.
A: No, SimplePDFviewer doesn't include built-in search. For text-searchable PDFs, you'd need to integrate the full pdf.js library or add a search layer with additional PDF.js capabilities.
A: While there's no built-in page jump feature, you can use the loadChapter() method and create custom controls:
function jumpToChapter(moduleIndex, chapterIndex) {
viewer.loadChapter(moduleIndex, chapterIndex);
}For page numbers within a chapter, you'd need to extend the library with keyboard input or button controls.
A: SimplePDFviewer automatically resets zoom to 100% and scroll position to the top-left (0,0) when you navigate between pages or chapters. This is by design for better UX - it ensures:
- You see the entire new page without unexpected zoom levels
- Navigation feels consistent and predictable
- You don't have to manually re-orient after switching pages
This happens automatically on:
nextPage()/ Previous page button clicksloadChapter()/ sidebar chapter selection- Arrow key navigation
The reset is transparent and cannot be disabled.
A: The most common issue is CORS (Cross-Origin Resource Sharing). PDFs must be served from a CORS-enabled server. Check:
- Browser console (F12 → Console) for error messages
- Network tab (F12 → Network) to verify the PDF URL returns status 200
- Server headers - ensure
Access-Control-Allow-Origin: *is set
If hosting on a different domain, configure your server or use a CORS proxy.
A: No, that's by design! On mobile devices (<768px width), the sidebar is hidden to save space. Use the hamburger menu (☰) button at the top-left to toggle it. On desktop, the sidebar is always visible.
A: This shouldn't happen - SimplePDFviewer renders at devicePixelRatio for sharp text. If you see blurry rendering:
- Clear your browser cache (Ctrl+Shift+Delete)
- Try a different PDF
- Check browser console for errors
- Test in incognito mode
A: Possible causes:
- Rapidly resizing the browser - This is expected, rendering updates dynamically
- Very large PDFs (500+ pages) - Split into multiple chapters
- Low-end device - Older devices struggle with canvas rendering
To optimize:
- Use smaller, optimized PDFs
- Avoid rapid window resizing
- Split large documents into chapters
A: Pass an onError callback to the init function:
const viewer = PDFViewer.init(container, course, {
onError: (error) => {
console.error(`${error.type}: ${error.message}`);
// Handle error appropriately
}
});Error types include load (PDF loading failed) and render (page rendering failed).
A: Follow these tips:
- Compress PDFs - Use tools like GhostScript to reduce file size
- Use a CDN - Serve PDFs from a content delivery network close to users
- Split large documents - Break PDFs into multiple chapters
- Enable caching - Set proper HTTP cache headers on your server
- Optimize images - Remove unnecessary images or compress them
A: PDFs with hundreds of pages can work, but performance degrades. The viewer renders the entire PDF in memory for page access. For very large documents:
- Split into multiple chapters (recommended)
- Use higher-end devices for viewing
- Optimize the PDF itself
A: SimplePDFviewer relies on pdf.js for PDF parsing. pdf.js is a well-maintained Mozilla project, but like any complex software, vulnerabilities could theoretically exist.
Best practices:
- Keep the library updated
- Only load PDFs from trusted sources
- Use CSP (Content Security Policy) headers
- Sanitize any user-provided content
For security-critical applications, audit the code and dependencies yourself.
A: No, SimplePDFviewer is purely a frontend library. It doesn't collect, transmit, or store any user data. Your viewing history, PDFs, and interactions exist only in your browser memory.
A: See CONTRIBUTING.md for detailed guidelines on contributing. Generally:
- Fork the repository
- Create a feature branch
- Make improvements (don't change core architecture)
- Update tests if applicable
- Submit a pull request with a clear description
A: Yes! SimplePDFviewer is stable and used in production. However:
- Monitor for updates and security fixes
- Always test thoroughly with your PDFs
- Have fallbacks for older browsers
- Consider supporting users with JavaScript disabled
A: See the Browser Support table in the USAGE guide. In summary:
- Modern browsers (Chrome, Firefox, Safari, Edge) are fully supported
- Internet Explorer 11 has limited support (no high-DPI rendering)
- Mobile browsers (iOS Safari, Chrome Mobile) are fully supported
A: Please submit an issue on GitHub Issues with:
- Description of the bug
- Steps to reproduce
- Expected vs. actual behavior
- Browser and OS information
- Console error messages (if any)
This helps the maintainers fix issues quickly.
A: SimplePDFviewer is licensed under the MIT License, which is permissive and open-source. You can use it freely in commercial and personal projects. See LICENSE.txt.
A: pdf.js is developed by Mozilla and uses the Apache-2.0 License. See THIRD_PARTY_NOTICES.md for complete details about third-party licenses.
A: Not required by the MIT License, but appreciated! If you use SimplePDFviewer in your project, a mention in your README or documentation is welcome.
A: Absolutely! Many use SimplePDFviewer for viewing research papers, theses, and academic materials. It's perfect for that use case.
A: Yes! You can initialize multiple viewers on different containers:
const viewer1 = PDFViewer.init(container1, course1);
const viewer2 = PDFViewer.init(container2, course2);Each viewer operates independently.
A: The minified version (core.min.js) is approximately 10-15 KB gzipped. Plus pdf.js adds ~300KB. This is already quite optimized for a PDF viewer.
A: Updates are released when bugs are fixed or features are added. Follow the GitHub repository for updates. All changes follow semantic versioning.
A: Not officially maintained, but SimplePDFviewer is simple enough to add type definitions. Consider contributing TypeScript definitions if you create them!
Didn't find your answer? Open an issue on GitHub or check the full USAGE guide.