Fix PDF parser - use pdf-parse with proper CommonJS import
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import multer from 'multer'
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import * as pdfjsLib from 'pdfjs-dist'
|
||||
import { createRequire } from 'module'
|
||||
|
||||
// PDF.js Worker konfigurieren
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker.min.js'
|
||||
const require = createRequire(import.meta.url)
|
||||
const pdfParse = require('pdf-parse')
|
||||
|
||||
// Handle both dev and production paths
|
||||
const getDataPath = (filename) => {
|
||||
@@ -68,22 +68,12 @@ export default defineEventHandler(async (event) => {
|
||||
})
|
||||
}
|
||||
|
||||
// PDF-Text extrahieren mit PDF.js
|
||||
// PDF-Text extrahieren mit pdf-parse
|
||||
const pdfBuffer = await fs.readFile(file.path)
|
||||
const pdfData = await pdfjsLib.getDocument({ data: pdfBuffer }).promise
|
||||
|
||||
let fullText = ''
|
||||
|
||||
// Alle Seiten durchgehen
|
||||
for (let pageNum = 1; pageNum <= pdfData.numPages; pageNum++) {
|
||||
const page = await pdfData.getPage(pageNum)
|
||||
const textContent = await page.getTextContent()
|
||||
const pageText = textContent.items.map(item => item.str).join(' ')
|
||||
fullText += pageText + '\n'
|
||||
}
|
||||
const pdfData = await pdfParse(pdfBuffer)
|
||||
|
||||
// Text in HTML-Format konvertieren
|
||||
const htmlContent = convertTextToHtml(fullText)
|
||||
const htmlContent = convertTextToHtml(pdfData.text)
|
||||
|
||||
// Config aktualisieren
|
||||
const configPath = getDataPath('config.json')
|
||||
|
||||
@@ -96,5 +96,12 @@
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEiLCJlbWFpbCI6ImFkbWluQGhhcmhlaW1lcnRjLmRlIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNzYxMTM1ODY3LCJleHAiOjE3NjE3NDA2Njd9.sddugktX9lZkJjZvbUzAEsP3OTf_n8J6T1tpdjEfeVY",
|
||||
"createdAt": "2025-10-22T12:24:27.778Z",
|
||||
"expiresAt": "2025-10-29T12:24:27.778Z"
|
||||
},
|
||||
{
|
||||
"id": "1761136733918",
|
||||
"userId": "1",
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEiLCJlbWFpbCI6ImFkbWluQGhhcmhlaW1lcnRjLmRlIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNzYxMTM2NzMzLCJleHAiOjE3NjE3NDE1MzN9.rzxassQ4Uj-nXfL2y1sygzshW0YovdYR2GUjosXoPF8",
|
||||
"createdAt": "2025-10-22T12:38:53.918Z",
|
||||
"expiresAt": "2025-10-29T12:38:53.918Z"
|
||||
}
|
||||
]
|
||||
@@ -8,6 +8,6 @@
|
||||
"phone": "",
|
||||
"active": true,
|
||||
"created": "2025-10-21T00:00:00.000Z",
|
||||
"lastLogin": "2025-10-22T12:24:27.785Z"
|
||||
"lastLogin": "2025-10-22T12:38:53.919Z"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user