fix: 修復行尾格式(CRLF → LF)
This commit is contained in:
parent
a1761b7da5
commit
c2d3d13c89
6 changed files with 243 additions and 77 deletions
|
|
@ -7,7 +7,7 @@ services:
|
|||
container_name: convertx-cn
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000" # 只允許本機存取,透過反向代理對外
|
||||
- "127.0.0.1:3000:3000" # 只允許本機存取,透過反向代理對外
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
environment:
|
||||
|
|
@ -18,8 +18,8 @@ services:
|
|||
- TZ=Asia/Taipei
|
||||
|
||||
# 安全性設定
|
||||
- HTTP_ALLOWED=false # 禁止 HTTP(使用 HTTPS)
|
||||
- TRUST_PROXY=true # 信任反向代理
|
||||
- HTTP_ALLOWED=false # 禁止 HTTP(使用 HTTPS)
|
||||
- TRUST_PROXY=true # 信任反向代理
|
||||
- ACCOUNT_REGISTRATION=false # 關閉公開註冊
|
||||
|
||||
# 清理設定
|
||||
|
|
|
|||
|
|
@ -24,24 +24,24 @@ import type { ExecFileFn } from "./types";
|
|||
|
||||
// 內建支援的 OCR 語言(與 PDFMathTranslate 風格一致)
|
||||
const SUPPORTED_LANGUAGES = [
|
||||
"en", // English
|
||||
"zh-TW", // 繁體中文
|
||||
"zh", // 簡體中文
|
||||
"ja", // 日本語
|
||||
"ko", // 한국어
|
||||
"de", // Deutsch
|
||||
"fr", // Français
|
||||
"en", // English
|
||||
"zh-TW", // 繁體中文
|
||||
"zh", // 簡體中文
|
||||
"ja", // 日本語
|
||||
"ko", // 한국어
|
||||
"de", // Deutsch
|
||||
"fr", // Français
|
||||
] as const;
|
||||
|
||||
// Tesseract 語言代碼映射(UI 代碼 → Tesseract 代碼)
|
||||
const LANG_MAP: Record<string, string> = {
|
||||
"en": "eng",
|
||||
en: "eng",
|
||||
"zh-TW": "chi_tra",
|
||||
"zh": "chi_sim",
|
||||
"ja": "jpn",
|
||||
"ko": "kor",
|
||||
"de": "deu",
|
||||
"fr": "fra",
|
||||
zh: "chi_sim",
|
||||
ja: "jpn",
|
||||
ko: "kor",
|
||||
de: "deu",
|
||||
fr: "fra",
|
||||
};
|
||||
|
||||
export const properties = {
|
||||
|
|
@ -114,12 +114,15 @@ function runOcrMyPdf(
|
|||
console.log(`[OCRmyPDF] ✅ OCR 語言: ${lang}`);
|
||||
|
||||
const args = [
|
||||
"-l", lang,
|
||||
"--skip-text", // 跳過已有文字的頁面
|
||||
"--optimize", "1", // 輕度優化
|
||||
"--deskew", // 自動校正傾斜
|
||||
"--rotate-pages", // 自動偵測頁面方向
|
||||
"--jobs", "2", // 使用 2 個並行處理
|
||||
"-l",
|
||||
lang,
|
||||
"--skip-text", // 跳過已有文字的頁面
|
||||
"--optimize",
|
||||
"1", // 輕度優化
|
||||
"--deskew", // 自動校正傾斜
|
||||
"--rotate-pages", // 自動偵測頁面方向
|
||||
"--jobs",
|
||||
"2", // 使用 2 個並行處理
|
||||
inputPath,
|
||||
outputPath,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -67,7 +67,9 @@ export async function isScannedPdf(
|
|||
const isScanned = charCount < SCANNED_PDF_TEXT_THRESHOLD;
|
||||
|
||||
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 {
|
||||
console.log(`[PDF-OCR] ✅ PDF has text layer (chars: ${charCount})`);
|
||||
}
|
||||
|
|
@ -103,14 +105,7 @@ export function runOcrMyPdf(
|
|||
// --clean: 清理背景雜訊
|
||||
// --force-ocr: 強制對所有頁面進行 OCR(即使有文字層)
|
||||
|
||||
const args = [
|
||||
"-l", lang,
|
||||
"--skip-text",
|
||||
"--optimize", "1",
|
||||
"--deskew",
|
||||
inputPath,
|
||||
outputPath,
|
||||
];
|
||||
const args = ["-l", lang, "--skip-text", "--optimize", "1", "--deskew", inputPath, outputPath];
|
||||
|
||||
console.log(`[PDF-OCR] Running: ocrmypdf ${args.join(" ")}`);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,23 +25,108 @@ const execWithTimeout = (
|
|||
|
||||
// 定義所有要檢查的工具
|
||||
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: "vips -v", name: "Vips", errorMsg: "Vips is not installed.", 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]}` },
|
||||
{
|
||||
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: "vips -v",
|
||||
name: "Vips",
|
||||
errorMsg: "Vips is not installed.",
|
||||
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") {
|
||||
|
|
@ -80,4 +165,3 @@ if (process.env.NODE_ENV === "production") {
|
|||
}
|
||||
})();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,11 @@ describe("BabelDOC converter - Chinese translation", () => {
|
|||
) => {
|
||||
if (cmd === "pdftotext") {
|
||||
// 返回超過 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") {
|
||||
babeldocCalled = true;
|
||||
babeldocArgs = args;
|
||||
|
|
@ -135,7 +139,11 @@ describe("BabelDOC converter - English translation", () => {
|
|||
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.", "");
|
||||
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") {
|
||||
babeldocArgs = args;
|
||||
const outputIndex = args.indexOf("-o");
|
||||
|
|
@ -187,7 +195,11 @@ describe("BabelDOC converter - Traditional Chinese", () => {
|
|||
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.", "");
|
||||
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") {
|
||||
babeldocArgs = args;
|
||||
const outputIndex = args.indexOf("-o");
|
||||
|
|
@ -239,7 +251,11 @@ describe("BabelDOC converter - Output structure", () => {
|
|||
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.", "");
|
||||
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") {
|
||||
const outputIndex = args.indexOf("-o");
|
||||
if (outputIndex !== -1 && args[outputIndex + 1]) {
|
||||
|
|
@ -277,7 +293,11 @@ describe("BabelDOC converter - Output structure", () => {
|
|||
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.", "");
|
||||
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") {
|
||||
const outputIndex = args.indexOf("-o");
|
||||
if (outputIndex !== -1 && args[outputIndex + 1]) {
|
||||
|
|
@ -329,7 +349,11 @@ describe("BabelDOC converter - Error handling", () => {
|
|||
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.", "");
|
||||
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") {
|
||||
const error = new Error("Translation failed") as ExecFileException;
|
||||
error.code = 1;
|
||||
|
|
@ -351,7 +375,11 @@ describe("BabelDOC converter - Error handling", () => {
|
|||
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.", "");
|
||||
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") {
|
||||
// Don't create output file, simulating failed translation
|
||||
callback(null, "Complete", "");
|
||||
|
|
@ -392,7 +420,11 @@ describe("BabelDOC converter - Markdown output format", () => {
|
|||
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.", "");
|
||||
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") {
|
||||
babeldocArgs = args;
|
||||
const outputIndex = args.indexOf("-o");
|
||||
|
|
@ -446,7 +478,11 @@ describe("BabelDOC converter - HTML output format", () => {
|
|||
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.", "");
|
||||
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") {
|
||||
babeldocArgs = args;
|
||||
const outputIndex = args.indexOf("-o");
|
||||
|
|
|
|||
|
|
@ -55,7 +55,13 @@ describe("PDFMathTranslate converter - Chinese translation", () => {
|
|||
args: string[],
|
||||
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;
|
||||
pdf2zhArgs = args;
|
||||
|
||||
|
|
@ -116,7 +122,13 @@ describe("PDFMathTranslate converter - English translation", () => {
|
|||
args: string[],
|
||||
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;
|
||||
const outputDirIndex = args.indexOf("-o");
|
||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||
|
|
@ -165,7 +177,13 @@ describe("PDFMathTranslate converter - Japanese translation", () => {
|
|||
args: string[],
|
||||
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;
|
||||
const outputDirIndex = args.indexOf("-o");
|
||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||
|
|
@ -214,7 +232,13 @@ describe("PDFMathTranslate converter - Traditional Chinese", () => {
|
|||
args: string[],
|
||||
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;
|
||||
const outputDirIndex = args.indexOf("-o");
|
||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||
|
|
@ -264,7 +288,13 @@ describe("PDFMathTranslate converter - Output structure", () => {
|
|||
args: string[],
|
||||
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");
|
||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||
const outputDir = args[outputDirIndex + 1];
|
||||
|
|
@ -308,7 +338,13 @@ describe("PDFMathTranslate converter - Output structure", () => {
|
|||
args: string[],
|
||||
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");
|
||||
if (outputDirIndex !== -1 && args[outputDirIndex + 1]) {
|
||||
const outputDir = args[outputDirIndex + 1];
|
||||
|
|
@ -362,7 +398,13 @@ describe("PDFMathTranslate converter - Error handling", () => {
|
|||
_args: string[],
|
||||
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;
|
||||
callback(error, "", "Error: Translation service unavailable");
|
||||
}
|
||||
|
|
@ -381,7 +423,13 @@ describe("PDFMathTranslate converter - Error handling", () => {
|
|||
_args: string[],
|
||||
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
|
||||
callback(null, "Complete", "");
|
||||
} else if (cmd === "tar") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue