2026-06-23 15:33:22 +08:00
|
|
|
|
//go:build nofitz
|
|
|
|
|
|
|
|
|
|
|
|
package services
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/pdfcpu/pdfcpu/pkg/api"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func extractTextWithFitz(inputPath string) (string, error) {
|
2026-06-30 12:30:49 +08:00
|
|
|
|
return extractTextNoFitz(inputPath)
|
|
|
|
|
|
}
|
2026-06-23 15:33:22 +08:00
|
|
|
|
|
2026-06-30 12:30:49 +08:00
|
|
|
|
func extractTextNoFitz(inputPath string) (string, error) {
|
|
|
|
|
|
// nofitz模式下的简化文本提取
|
2026-06-23 15:33:22 +08:00
|
|
|
|
pageCount, err := api.PageCountFile(inputPath)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return "", fmt.Errorf("count pages failed: %v", err)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-30 12:30:49 +08:00
|
|
|
|
// 返回基本信息,提示用户使用完整版以获得更好的文本提取
|
|
|
|
|
|
return fmt.Sprintf("PDF has %d pages\n\n注意:当前为精简模式,文本提取功能受限。\n如需完整功能,请使用包含MuPDF库的版本。", pageCount), nil
|
2026-06-23 15:33:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func pdfToImagesWithFitz(inputPath, outputDir, format string, dpi float64) ([]string, error) {
|
2026-06-30 12:30:49 +08:00
|
|
|
|
return pdfToImagesNoFitz(inputPath, outputDir, format, dpi)
|
|
|
|
|
|
}
|
2026-06-23 15:33:22 +08:00
|
|
|
|
|
2026-06-30 12:30:49 +08:00
|
|
|
|
func pdfToImagesNoFitz(inputPath, outputDir, format string, dpi float64) ([]string, error) {
|
|
|
|
|
|
// nofitz模式下不支持PDF转图片,返回友好错误提示
|
|
|
|
|
|
return nil, fmt.Errorf("PDF转图片功能需要MuPDF库支持。请使用完整版安装包或安装MuPDF后重试")
|
2026-06-23 15:33:22 +08:00
|
|
|
|
}
|