Improve logging and text layer scaling

Removed unnecessary console output for non-critical features, including `console.log`, `console.warn`, and `console.error` statements in `setQualityOptions`, `renderTextLayer`, and `renderThumbnail` methods. This reduces noise in production logs.

Added a CSS variable `--scale-factor` to the text layer's `style` in `renderTextLayer` to ensure proper scaling and improve text rendering accuracy. These changes enhance code cleanliness and robustness.
This commit is contained in:
2026-06-06 16:25:07 +02:00
parent d32050ce03
commit 6d8cecc20b

View File

@@ -27,7 +27,6 @@ window.pdfViewer = {
setQualityOptions(options) { setQualityOptions(options) {
this.qualityOptions = { ...this.qualityOptions, ...options }; this.qualityOptions = { ...this.qualityOptions, ...options };
console.log('PDF Viewer quality options updated:', this.qualityOptions);
// Apply CSS variables for dynamic styling // Apply CSS variables for dynamic styling
document.documentElement.style.setProperty('--zoom-transition-duration', `${options.zoomTransitionDuration}ms`); document.documentElement.style.setProperty('--zoom-transition-duration', `${options.zoomTransitionDuration}ms`);
@@ -217,7 +216,6 @@ window.pdfViewer = {
try { try {
const textLayerDiv = document.getElementById('pdf-text-layer'); const textLayerDiv = document.getElementById('pdf-text-layer');
if (!textLayerDiv) { if (!textLayerDiv) {
console.warn('Text layer div not found');
return; return;
} }
@@ -228,6 +226,9 @@ window.pdfViewer = {
textLayerDiv.style.width = `${viewport.width / dpr}px`; textLayerDiv.style.width = `${viewport.width / dpr}px`;
textLayerDiv.style.height = `${viewport.height / dpr}px`; textLayerDiv.style.height = `${viewport.height / dpr}px`;
// Set --scale-factor CSS variable required by PDF.js
textLayerDiv.style.setProperty('--scale-factor', this.scale);
// Get text content from PDF // Get text content from PDF
const textContent = await page.getTextContent(); const textContent = await page.getTextContent();
@@ -244,7 +245,7 @@ window.pdfViewer = {
}).promise; }).promise;
} catch (error) { } catch (error) {
console.error('Error rendering text layer:', error); // Silently handle text layer errors (non-critical feature)
} }
}, },
@@ -322,7 +323,6 @@ window.pdfViewer = {
async renderThumbnail(pageNum, canvasId) { async renderThumbnail(pageNum, canvasId) {
if (!this.pdfDoc) { if (!this.pdfDoc) {
console.error('PDF document not loaded for thumbnail:', pageNum);
return; return;
} }
@@ -337,7 +337,6 @@ window.pdfViewer = {
} }
if (!canvas) { if (!canvas) {
console.error('Canvas not found after retries:', canvasId);
return; return;
} }
@@ -389,7 +388,7 @@ window.pdfViewer = {
// Clear the task when done // Clear the task when done
delete canvas._renderTask; delete canvas._renderTask;
} catch (error) { } catch (error) {
console.error('Error rendering thumbnail', pageNum, ':', error); // Silently handle thumbnail errors (non-critical)
} }
}, },