feat: 同步全部系统改动与文档
This commit is contained in:
30
work/system-manual/locate-pdf-pages.js
Normal file
30
work/system-manual/locate-pdf-pages.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { DOMMatrix, ImageData, Path2D } = require('@napi-rs/canvas')
|
||||
|
||||
global.DOMMatrix = DOMMatrix
|
||||
global.ImageData = ImageData
|
||||
global.Path2D = Path2D
|
||||
if (!process.getBuiltinModule) process.getBuiltinModule = name => require(name)
|
||||
|
||||
async function main() {
|
||||
const pdfjs = await import('pdfjs-dist/legacy/build/pdf.mjs')
|
||||
const root = path.resolve(__dirname, '..', '..')
|
||||
const pdfPath = path.resolve(root, 'doc', '大连元利流体技术有限公司MES系统用户操作手册_V1.1_2026-07-23.pdf')
|
||||
const terms = process.argv.slice(2)
|
||||
const pdf = await pdfjs.getDocument({ data: new Uint8Array(fs.readFileSync(pdfPath)), disableWorker: true }).promise
|
||||
console.log(`PDF pages: ${pdf.numPages}`)
|
||||
for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++) {
|
||||
const page = await pdf.getPage(pageNumber)
|
||||
const content = await page.getTextContent()
|
||||
const text = content.items.map(item => item.str).join(' ').replace(/\s+/g, ' ').trim()
|
||||
if (terms.length === 0 || terms.some(term => text.includes(term))) {
|
||||
console.log(`${pageNumber}\t${text.slice(0, 220)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(error => {
|
||||
console.error(error.stack || error.message)
|
||||
process.exitCode = 1
|
||||
})
|
||||
Reference in New Issue
Block a user