fix: 修復行尾格式(CRLF → LF)
This commit is contained in:
parent
a1761b7da5
commit
c2d3d13c89
6 changed files with 243 additions and 77 deletions
|
|
@ -35,13 +35,13 @@ const SUPPORTED_LANGUAGES = [
|
||||||
|
|
||||||
// Tesseract 語言代碼映射(UI 代碼 → Tesseract 代碼)
|
// Tesseract 語言代碼映射(UI 代碼 → Tesseract 代碼)
|
||||||
const LANG_MAP: Record<string, string> = {
|
const LANG_MAP: Record<string, string> = {
|
||||||
"en": "eng",
|
en: "eng",
|
||||||
"zh-TW": "chi_tra",
|
"zh-TW": "chi_tra",
|
||||||
"zh": "chi_sim",
|
zh: "chi_sim",
|
||||||
"ja": "jpn",
|
ja: "jpn",
|
||||||
"ko": "kor",
|
ko: "kor",
|
||||||
"de": "deu",
|
de: "deu",
|
||||||
"fr": "fra",
|
fr: "fra",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
|
|
@ -114,12 +114,15 @@ function runOcrMyPdf(
|
||||||
console.log(`[OCRmyPDF] ✅ OCR 語言: ${lang}`);
|
console.log(`[OCRmyPDF] ✅ OCR 語言: ${lang}`);
|
||||||
|
|
||||||
const args = [
|
const args = [
|
||||||
"-l", lang,
|
"-l",
|
||||||
|
lang,
|
||||||
"--skip-text", // 跳過已有文字的頁面
|
"--skip-text", // 跳過已有文字的頁面
|
||||||
"--optimize", "1", // 輕度優化
|
"--optimize",
|
||||||
|
"1", // 輕度優化
|
||||||
"--deskew", // 自動校正傾斜
|
"--deskew", // 自動校正傾斜
|
||||||
"--rotate-pages", // 自動偵測頁面方向
|
"--rotate-pages", // 自動偵測頁面方向
|
||||||
"--jobs", "2", // 使用 2 個並行處理
|
"--jobs",
|
||||||
|
"2", // 使用 2 個並行處理
|
||||||
inputPath,
|
inputPath,
|
||||||
outputPath,
|
outputPath,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,9 @@ export async function isScannedPdf(
|
||||||
const isScanned = charCount < SCANNED_PDF_TEXT_THRESHOLD;
|
const isScanned = charCount < SCANNED_PDF_TEXT_THRESHOLD;
|
||||||
|
|
||||||
if (isScanned) {
|
if (isScanned) {
|
||||||
console.log(`[PDF-OCR] ⚠️ Detected scanned PDF (chars: ${charCount} < ${SCANNED_PDF_TEXT_THRESHOLD})`);
|
console.log(
|
||||||
|
`[PDF-OCR] ⚠️ Detected scanned PDF (chars: ${charCount} < ${SCANNED_PDF_TEXT_THRESHOLD})`,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log(`[PDF-OCR] ✅ PDF has text layer (chars: ${charCount})`);
|
console.log(`[PDF-OCR] ✅ PDF has text layer (chars: ${charCount})`);
|
||||||
}
|
}
|
||||||
|
|
@ -103,14 +105,7 @@ export function runOcrMyPdf(
|
||||||
// --clean: 清理背景雜訊
|
// --clean: 清理背景雜訊
|
||||||
// --force-ocr: 強制對所有頁面進行 OCR(即使有文字層)
|
// --force-ocr: 強制對所有頁面進行 OCR(即使有文字層)
|
||||||
|
|
||||||
const args = [
|
const args = ["-l", lang, "--skip-text", "--optimize", "1", "--deskew", inputPath, outputPath];
|
||||||
"-l", lang,
|
|
||||||
"--skip-text",
|
|
||||||
"--optimize", "1",
|
|
||||||
"--deskew",
|
|
||||||
inputPath,
|
|
||||||
outputPath,
|
|
||||||
];
|
|
||||||
|
|
||||||
console.log(`[PDF-OCR] Running: ocrmypdf ${args.join(" ")}`);
|
console.log(`[PDF-OCR] Running: ocrmypdf ${args.join(" ")}`);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,23 +25,108 @@ const execWithTimeout = (
|
||||||
|
|
||||||
// 定義所有要檢查的工具
|
// 定義所有要檢查的工具
|
||||||
const tools = [
|
const tools = [
|
||||||
{ cmd: "pandoc -v", name: "Pandoc", errorMsg: "Pandoc is not installed.", formatter: (s: string) => s.split("\n")[0] },
|
{
|
||||||
{ cmd: "ffmpeg -version", name: "FFmpeg", errorMsg: "FFmpeg is not installed.", formatter: (s: string) => s.split("\n")[0] },
|
cmd: "pandoc -v",
|
||||||
{ cmd: "vips -v", name: "Vips", errorMsg: "Vips is not installed.", formatter: (s: string) => s.split("\n")[0] },
|
name: "Pandoc",
|
||||||
{ cmd: "magick --version", name: "ImageMagick", errorMsg: "ImageMagick is not installed.", formatter: (s: string) => s.split("\n")[0]?.replace("Version: ", "") },
|
errorMsg: "Pandoc is not installed.",
|
||||||
{ cmd: "gm version", name: "GraphicsMagick", errorMsg: "GraphicsMagick is not installed.", formatter: (s: string) => s.split("\n")[0] },
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
{ cmd: "inkscape --version", name: "Inkscape", errorMsg: "Inkscape is not installed.", formatter: (s: string) => s.split("\n")[0] },
|
},
|
||||||
{ cmd: "djxl --version", name: "libjxl", errorMsg: "libjxl-tools is not installed.", formatter: (s: string) => s.split("\n")[0] },
|
{
|
||||||
{ cmd: "dasel --version", name: "dasel", errorMsg: "dasel is not installed.", formatter: (s: string) => s.split("\n")[0] },
|
cmd: "ffmpeg -version",
|
||||||
{ cmd: "xelatex -version", name: "XeTeX", errorMsg: "Tex Live with XeTeX is not installed.", formatter: (s: string) => s.split("\n")[0] },
|
name: "FFmpeg",
|
||||||
{ cmd: "resvg -V", name: "resvg", errorMsg: "resvg is not installed", formatter: (s: string) => `resvg v${s.split("\n")[0]}` },
|
errorMsg: "FFmpeg is not installed.",
|
||||||
{ cmd: "assimp version", name: "assimp", errorMsg: "assimp is not installed", formatter: (s: string) => `assimp ${s.split("\n")[5]}` },
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
{ cmd: "ebook-convert --version", name: "calibre", errorMsg: "ebook-convert (calibre) is not installed", formatter: (s: string) => s.split("\n")[0] },
|
},
|
||||||
{ cmd: "heif-info -v", name: "libheif", errorMsg: "libheif is not installed", formatter: (s: string) => `libheif v${s.split("\n")[0]}` },
|
{
|
||||||
{ cmd: "potrace -v", name: "potrace", errorMsg: "potrace is not installed", formatter: (s: string) => s.split("\n")[0] },
|
cmd: "vips -v",
|
||||||
{ cmd: "soffice --version", name: "LibreOffice", errorMsg: "libreoffice is not installed", formatter: (s: string) => s.split("\n")[0] },
|
name: "Vips",
|
||||||
{ cmd: "msgconvert --version", name: "msgconvert", errorMsg: "msgconvert (libemail-outlook-message-perl) is not installed", formatter: (s: string) => s.split("\n")[0] },
|
errorMsg: "Vips is not installed.",
|
||||||
{ cmd: "bun -v", name: "Bun", errorMsg: "Bun is not installed. wait what", formatter: (s: string) => `Bun v${s.split("\n")[0]}` },
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "magick --version",
|
||||||
|
name: "ImageMagick",
|
||||||
|
errorMsg: "ImageMagick is not installed.",
|
||||||
|
formatter: (s: string) => s.split("\n")[0]?.replace("Version: ", ""),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "gm version",
|
||||||
|
name: "GraphicsMagick",
|
||||||
|
errorMsg: "GraphicsMagick is not installed.",
|
||||||
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "inkscape --version",
|
||||||
|
name: "Inkscape",
|
||||||
|
errorMsg: "Inkscape is not installed.",
|
||||||
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "djxl --version",
|
||||||
|
name: "libjxl",
|
||||||
|
errorMsg: "libjxl-tools is not installed.",
|
||||||
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "dasel --version",
|
||||||
|
name: "dasel",
|
||||||
|
errorMsg: "dasel is not installed.",
|
||||||
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "xelatex -version",
|
||||||
|
name: "XeTeX",
|
||||||
|
errorMsg: "Tex Live with XeTeX is not installed.",
|
||||||
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "resvg -V",
|
||||||
|
name: "resvg",
|
||||||
|
errorMsg: "resvg is not installed",
|
||||||
|
formatter: (s: string) => `resvg v${s.split("\n")[0]}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "assimp version",
|
||||||
|
name: "assimp",
|
||||||
|
errorMsg: "assimp is not installed",
|
||||||
|
formatter: (s: string) => `assimp ${s.split("\n")[5]}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "ebook-convert --version",
|
||||||
|
name: "calibre",
|
||||||
|
errorMsg: "ebook-convert (calibre) is not installed",
|
||||||
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "heif-info -v",
|
||||||
|
name: "libheif",
|
||||||
|
errorMsg: "libheif is not installed",
|
||||||
|
formatter: (s: string) => `libheif v${s.split("\n")[0]}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "potrace -v",
|
||||||
|
name: "potrace",
|
||||||
|
errorMsg: "potrace is not installed",
|
||||||
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "soffice --version",
|
||||||
|
name: "LibreOffice",
|
||||||
|
errorMsg: "libreoffice is not installed",
|
||||||
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "msgconvert --version",
|
||||||
|
name: "msgconvert",
|
||||||
|
errorMsg: "msgconvert (libemail-outlook-message-perl) is not installed",
|
||||||
|
formatter: (s: string) => s.split("\n")[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: "bun -v",
|
||||||
|
name: "Bun",
|
||||||
|
errorMsg: "Bun is not installed. wait what",
|
||||||
|
formatter: (s: string) => `Bun v${s.split("\n")[0]}`,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (process.env.NODE_ENV === "production") {
|
if (process.env.NODE_ENV === "production") {
|
||||||
|
|
@ -80,4 +165,3 @@ if (process.env.NODE_ENV === "production") {
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,11 @@ describe("BabelDOC converter - Chinese translation", () => {
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") {
|
if (cmd === "pdftotext") {
|
||||||
// 返回超過 100 個字元,表示 PDF 不需要 OCR
|
// 返回超過 100 個字元,表示 PDF 不需要 OCR
|
||||||
callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", "");
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
} else if (cmd === "babeldoc") {
|
} else if (cmd === "babeldoc") {
|
||||||
babeldocCalled = true;
|
babeldocCalled = true;
|
||||||
babeldocArgs = args;
|
babeldocArgs = args;
|
||||||
|
|
@ -135,7 +139,11 @@ describe("BabelDOC converter - English translation", () => {
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") {
|
if (cmd === "pdftotext") {
|
||||||
callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", "");
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
} else if (cmd === "babeldoc") {
|
} else if (cmd === "babeldoc") {
|
||||||
babeldocArgs = args;
|
babeldocArgs = args;
|
||||||
const outputIndex = args.indexOf("-o");
|
const outputIndex = args.indexOf("-o");
|
||||||
|
|
@ -187,7 +195,11 @@ describe("BabelDOC converter - Traditional Chinese", () => {
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") {
|
if (cmd === "pdftotext") {
|
||||||
callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", "");
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
} else if (cmd === "babeldoc") {
|
} else if (cmd === "babeldoc") {
|
||||||
babeldocArgs = args;
|
babeldocArgs = args;
|
||||||
const outputIndex = args.indexOf("-o");
|
const outputIndex = args.indexOf("-o");
|
||||||
|
|
@ -239,7 +251,11 @@ describe("BabelDOC converter - Output structure", () => {
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") {
|
if (cmd === "pdftotext") {
|
||||||
callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", "");
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
} else if (cmd === "babeldoc") {
|
} else if (cmd === "babeldoc") {
|
||||||
const outputIndex = args.indexOf("-o");
|
const outputIndex = args.indexOf("-o");
|
||||||
if (outputIndex !== -1 && args[outputIndex + 1]) {
|
if (outputIndex !== -1 && args[outputIndex + 1]) {
|
||||||
|
|
@ -277,7 +293,11 @@ describe("BabelDOC converter - Output structure", () => {
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") {
|
if (cmd === "pdftotext") {
|
||||||
callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", "");
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
} else if (cmd === "babeldoc") {
|
} else if (cmd === "babeldoc") {
|
||||||
const outputIndex = args.indexOf("-o");
|
const outputIndex = args.indexOf("-o");
|
||||||
if (outputIndex !== -1 && args[outputIndex + 1]) {
|
if (outputIndex !== -1 && args[outputIndex + 1]) {
|
||||||
|
|
@ -329,7 +349,11 @@ describe("BabelDOC converter - Error handling", () => {
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") {
|
if (cmd === "pdftotext") {
|
||||||
callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", "");
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
} else if (cmd === "babeldoc") {
|
} else if (cmd === "babeldoc") {
|
||||||
const error = new Error("Translation failed") as ExecFileException;
|
const error = new Error("Translation failed") as ExecFileException;
|
||||||
error.code = 1;
|
error.code = 1;
|
||||||
|
|
@ -351,7 +375,11 @@ describe("BabelDOC converter - Error handling", () => {
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") {
|
if (cmd === "pdftotext") {
|
||||||
callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", "");
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
} else if (cmd === "babeldoc") {
|
} else if (cmd === "babeldoc") {
|
||||||
// Don't create output file, simulating failed translation
|
// Don't create output file, simulating failed translation
|
||||||
callback(null, "Complete", "");
|
callback(null, "Complete", "");
|
||||||
|
|
@ -392,7 +420,11 @@ describe("BabelDOC converter - Markdown output format", () => {
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") {
|
if (cmd === "pdftotext") {
|
||||||
callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", "");
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
} else if (cmd === "babeldoc") {
|
} else if (cmd === "babeldoc") {
|
||||||
babeldocArgs = args;
|
babeldocArgs = args;
|
||||||
const outputIndex = args.indexOf("-o");
|
const outputIndex = args.indexOf("-o");
|
||||||
|
|
@ -446,7 +478,11 @@ describe("BabelDOC converter - HTML output format", () => {
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") {
|
if (cmd === "pdftotext") {
|
||||||
callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", "");
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
} else if (cmd === "babeldoc") {
|
} else if (cmd === "babeldoc") {
|
||||||
babeldocArgs = args;
|
babeldocArgs = args;
|
||||||
const outputIndex = args.indexOf("-o");
|
const outputIndex = args.indexOf("-o");
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,13 @@ describe("PDFMathTranslate converter - Chinese translation", () => {
|
||||||
args: string[],
|
args: string[],
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") { callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", ""); } else if (cmd === "pdf2zh") {
|
if (cmd === "pdftotext") {
|
||||||
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
} else if (cmd === "pdf2zh") {
|
||||||
pdf2zhCalled = true;
|
pdf2zhCalled = true;
|
||||||
pdf2zhArgs = args;
|
pdf2zhArgs = args;
|
||||||
|
|
||||||
|
|
@ -116,7 +122,13 @@ describe("PDFMathTranslate converter - English translation", () => {
|
||||||
args: string[],
|
args: string[],
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") { callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", ""); } else if (cmd === "pdf2zh") {
|
if (cmd === "pdftotext") {
|
||||||
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
} else if (cmd === "pdf2zh") {
|
||||||
pdf2zhArgs = args;
|
pdf2zhArgs = args;
|
||||||
const outputDirIndex = args.indexOf("-o");
|
const outputDirIndex = args.indexOf("-o");
|
||||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||||
|
|
@ -165,7 +177,13 @@ describe("PDFMathTranslate converter - Japanese translation", () => {
|
||||||
args: string[],
|
args: string[],
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") { callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", ""); } else if (cmd === "pdf2zh") {
|
if (cmd === "pdftotext") {
|
||||||
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
} else if (cmd === "pdf2zh") {
|
||||||
pdf2zhArgs = args;
|
pdf2zhArgs = args;
|
||||||
const outputDirIndex = args.indexOf("-o");
|
const outputDirIndex = args.indexOf("-o");
|
||||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||||
|
|
@ -214,7 +232,13 @@ describe("PDFMathTranslate converter - Traditional Chinese", () => {
|
||||||
args: string[],
|
args: string[],
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") { callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", ""); } else if (cmd === "pdf2zh") {
|
if (cmd === "pdftotext") {
|
||||||
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
} else if (cmd === "pdf2zh") {
|
||||||
pdf2zhArgs = args;
|
pdf2zhArgs = args;
|
||||||
const outputDirIndex = args.indexOf("-o");
|
const outputDirIndex = args.indexOf("-o");
|
||||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||||
|
|
@ -264,7 +288,13 @@ describe("PDFMathTranslate converter - Output structure", () => {
|
||||||
args: string[],
|
args: string[],
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") { callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", ""); } else if (cmd === "pdf2zh") {
|
if (cmd === "pdftotext") {
|
||||||
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
} else if (cmd === "pdf2zh") {
|
||||||
const outputDirIndex = args.indexOf("-o");
|
const outputDirIndex = args.indexOf("-o");
|
||||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||||
const outputDir = args[outputDirIndex + 1];
|
const outputDir = args[outputDirIndex + 1];
|
||||||
|
|
@ -308,7 +338,13 @@ describe("PDFMathTranslate converter - Output structure", () => {
|
||||||
args: string[],
|
args: string[],
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") { callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", ""); } else if (cmd === "pdf2zh") {
|
if (cmd === "pdftotext") {
|
||||||
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
} else if (cmd === "pdf2zh") {
|
||||||
const outputDirIndex = args.indexOf("-o");
|
const outputDirIndex = args.indexOf("-o");
|
||||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||||
const outputDir = args[outputDirIndex + 1];
|
const outputDir = args[outputDirIndex + 1];
|
||||||
|
|
@ -362,7 +398,13 @@ describe("PDFMathTranslate converter - Error handling", () => {
|
||||||
_args: string[],
|
_args: string[],
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") { callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", ""); } else if (cmd === "pdf2zh") {
|
if (cmd === "pdftotext") {
|
||||||
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
} else if (cmd === "pdf2zh") {
|
||||||
const error = new Error("Translation failed") as ExecFileException;
|
const error = new Error("Translation failed") as ExecFileException;
|
||||||
callback(error, "", "Error: Translation service unavailable");
|
callback(error, "", "Error: Translation service unavailable");
|
||||||
}
|
}
|
||||||
|
|
@ -381,7 +423,13 @@ describe("PDFMathTranslate converter - Error handling", () => {
|
||||||
_args: string[],
|
_args: string[],
|
||||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
) => {
|
) => {
|
||||||
if (cmd === "pdftotext") { callback(null, "This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.", ""); } else if (cmd === "pdf2zh") {
|
if (cmd === "pdftotext") {
|
||||||
|
callback(
|
||||||
|
null,
|
||||||
|
"This is a comprehensive test PDF with more than enough text content to ensure that the OCR detection threshold of 100 characters is exceeded and the PDF is not treated as a scanned document requiring OCR processing.",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
} else if (cmd === "pdf2zh") {
|
||||||
// Don't create any output files
|
// Don't create any output files
|
||||||
callback(null, "Complete", "");
|
callback(null, "Complete", "");
|
||||||
} else if (cmd === "tar") {
|
} else if (cmd === "tar") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue