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:
@@ -27,7 +27,6 @@ window.pdfViewer = {
|
||||
|
||||
setQualityOptions(options) {
|
||||
this.qualityOptions = { ...this.qualityOptions, ...options };
|
||||
console.log('PDF Viewer quality options updated:', this.qualityOptions);
|
||||
|
||||
// Apply CSS variables for dynamic styling
|
||||
document.documentElement.style.setProperty('--zoom-transition-duration', `${options.zoomTransitionDuration}ms`);
|
||||
@@ -217,7 +216,6 @@ window.pdfViewer = {
|
||||
try {
|
||||
const textLayerDiv = document.getElementById('pdf-text-layer');
|
||||
if (!textLayerDiv) {
|
||||
console.warn('Text layer div not found');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -227,6 +225,9 @@ window.pdfViewer = {
|
||||
// Set text layer dimensions to match canvas display size
|
||||
textLayerDiv.style.width = `${viewport.width / 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
|
||||
const textContent = await page.getTextContent();
|
||||
@@ -244,7 +245,7 @@ window.pdfViewer = {
|
||||
}).promise;
|
||||
|
||||
} 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) {
|
||||
if (!this.pdfDoc) {
|
||||
console.error('PDF document not loaded for thumbnail:', pageNum);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -337,7 +337,6 @@ window.pdfViewer = {
|
||||
}
|
||||
|
||||
if (!canvas) {
|
||||
console.error('Canvas not found after retries:', canvasId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -389,7 +388,7 @@ window.pdfViewer = {
|
||||
// Clear the task when done
|
||||
delete canvas._renderTask;
|
||||
} catch (error) {
|
||||
console.error('Error rendering thumbnail', pageNum, ':', error);
|
||||
// Silently handle thumbnail errors (non-critical)
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user