-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmupdf.go
38 lines (30 loc) · 941 Bytes
/
mupdf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package dossier
import (
"context"
"github.com/gabriel-vasile/mimetype"
"github.com/hansmi/dossier/internal/muparser"
"github.com/hansmi/dossier/internal/mutool"
)
type MuPdfParserFactory struct {
// Command arguments to invoke MuPDF's "mutool" program. Leave empty to use
// the default.
MutoolCommand []string
// Command arguments to invoke the "xmllint" program. Leave empty to use
// the default.
XmllintCommand []string
}
func (f MuPdfParserFactory) makeTool() *mutool.Wrapper {
return mutool.New(mutool.Options{
MutoolCommand: f.MutoolCommand,
XmllintCommand: f.XmllintCommand,
})
}
func (f MuPdfParserFactory) Check(ctx context.Context) error {
return f.makeTool().CheckCommands(ctx)
}
func (f MuPdfParserFactory) Create(path, contentType string) (Parser, error) {
if !mimetype.EqualsAny(contentType, muparser.SupportedContentTypes...) {
return nil, nil
}
return muparser.New(path, f.makeTool()), nil
}