Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(ocr): confusing message when processing image-based PDFs
Elian Doran92975c75c851
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 7fd92e22d7..55e37c618a 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2231,6 +2231,7 @@"processing_complete": "OCR processing complete.","processing_failed": "Failed to start OCR processing","text_filtered_low_confidence": "OCR detected text with {{confidence}}% confidence, but it was discarded because your minimum threshold is {{threshold}}%.",+ "image_based_pdf_not_supported": "This PDF appears to be image-based (scanned). Text extraction from image-based PDFs is not yet supported.","open_media_settings": "Open Settings","view_extracted_text": "View extracted text (OCR)"},diff --git a/apps/client/src/widgets/type_widgets/ReadOnlyTextRepresentation.tsx b/apps/client/src/widgets/type_widgets/ReadOnlyTextRepresentation.tsxindex a5bada9f6b..03c5a3120d 100644--- a/apps/client/src/widgets/type_widgets/ReadOnlyTextRepresentation.tsx+++ b/apps/client/src/widgets/type_widgets/ReadOnlyTextRepresentation.tsx@@ -69,8 +69,16 @@ export function TextRepresentation({ textUrl, processUrl }: TextRepresentationPrconst result = response.result;const minConfidence = response.minConfidence ?? 0;+ // Check if this is an image-based PDF (no text extracted)+ if (result && !result.text && result.processingType === 'pdf') {+ toast.showPersistent({+ id: `ocr-pdf-unsupported-${randomString(8)}`,+ icon: "bx bx-info-circle",+ message: t("ocr.image_based_pdf_not_supported"),+ timeout: 15000+ });// Check if text was filtered due to low confidence- if (result && !result.text && result.confidence > 0 && minConfidence > 0) {+ } else if (result && !result.text && result.confidence > 0 && minConfidence > 0) {const confidencePercent = Math.round(result.confidence * 100);const thresholdPercent = Math.round(minConfidence * 100);toast.showPersistent({diff --git a/apps/server/src/services/ocr/ocr_service.ts b/apps/server/src/services/ocr/ocr_service.tsindex f59ff8e609..1e526be983 100644--- a/apps/server/src/services/ocr/ocr_service.ts+++ b/apps/server/src/services/ocr/ocr_service.ts@@ -17,6 +17,7 @@ export interface OCRResult {extractedAt: string;language?: string;pageCount?: number;+ processingType?: string;}export interface OCRProcessingOptions {@@ -116,6 +117,7 @@ class OCRService {}const result = await processor.extractText(fileBuffer, { ...options, mimeType });+ result.processingType = processor.getProcessingType();log.info(`OCR extraction completed. Confidence: ${Math.round(result.confidence * 100)}%, Text length: ${result.text.length}`);return result;diff --git a/apps/server/src/services/ocr/processors/pdf_processor.ts b/apps/server/src/services/ocr/processors/pdf_processor.tsindex 9605665857..1b5b8ff464 100644--- a/apps/server/src/services/ocr/processors/pdf_processor.ts+++ b/apps/server/src/services/ocr/processors/pdf_processor.ts@@ -22,10 +22,11 @@ export class PDFProcessor extends FileProcessor {const pdf = await getDocumentProxy(new Uint8Array(buffer));const { totalPages, text } = await extractText(pdf, { mergePages: true });+ const trimmed = text.trim();return {- text: text.trim(),- confidence: 0.99,+ text: trimmed,+ confidence: trimmed.length > 0 ? 0.99 : 0,extractedAt: new Date().toISOString(),language: options.language || "eng",pageCount: totalPagesdiff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.tsindex 63e5c63680..02b0590e7c 100644--- a/packages/commons/src/lib/server_api.ts+++ b/packages/commons/src/lib/server_api.ts@@ -308,6 +308,7 @@ export interface OCRProcessResponse {extractedAt: string;language?: string;pageCount?: number;+ processingType?: string;};/** The minimum confidence threshold that was applied (0-1 scale). */minConfidence?: number;