2026-07-02 09:46:33 +08:00
|
|
|
package pdf
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"image"
|
|
|
|
|
|
|
|
|
|
pdf "ragflow/internal/deepdoc/parser/pdf/type"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// MockEngine is a minimal pdf.PDFEngine stub for unit/integration tests.
|
|
|
|
|
type MockEngine struct {
|
2026-07-10 10:36:10 +08:00
|
|
|
Chars map[int][]pdf.TextChar
|
|
|
|
|
NumPages int
|
|
|
|
|
RenderW int
|
|
|
|
|
RenderH int
|
|
|
|
|
RenderPageImageFunc func(pg int, dpi float64) (image.Image, error)
|
2026-07-02 09:46:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MockEngine) ExtractChars(pg int) ([]pdf.TextChar, error) {
|
|
|
|
|
return m.Chars[pg], nil
|
|
|
|
|
}
|
|
|
|
|
func (m *MockEngine) RenderPage(pg int, dpi float64) ([]byte, error) {
|
|
|
|
|
return nil, ErrNoPDFData
|
|
|
|
|
}
|
|
|
|
|
func (m *MockEngine) RenderPageImage(pg int, dpi float64) (image.Image, error) {
|
2026-07-10 10:36:10 +08:00
|
|
|
if m.RenderPageImageFunc != nil {
|
|
|
|
|
return m.RenderPageImageFunc(pg, dpi)
|
|
|
|
|
}
|
2026-07-02 09:46:33 +08:00
|
|
|
w, h := m.RenderW, m.RenderH
|
|
|
|
|
if w <= 0 {
|
|
|
|
|
w = 100
|
|
|
|
|
}
|
|
|
|
|
if h <= 0 {
|
|
|
|
|
h = 100
|
|
|
|
|
}
|
|
|
|
|
return image.NewRGBA(image.Rect(0, 0, w, h)), nil
|
|
|
|
|
}
|
|
|
|
|
func (m *MockEngine) PageCount() (int, error) {
|
|
|
|
|
if m.NumPages <= 0 {
|
|
|
|
|
return 1, nil
|
|
|
|
|
}
|
|
|
|
|
return m.NumPages, nil
|
|
|
|
|
}
|
|
|
|
|
func (m *MockEngine) RawData() []byte { return nil }
|
|
|
|
|
func (m *MockEngine) Close() error { return nil }
|
|
|
|
|
func (m *MockEngine) Outlines() ([]pdf.Outline, error) { return nil, nil }
|