summaryrefslogtreecommitdiff
path: root/cmd/rescribe/main.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2022-03-11 13:36:59 +0000
committerNick White <git@njw.name>2022-03-11 13:36:59 +0000
commit9d1382b69700129a66541d786ba3b784eda56e36 (patch)
treea1e607d55dbd08b586f528eea07ea15079ed1684 /cmd/rescribe/main.go
parentd6e1cb61da7a9155023ce9dece96da79c7246790 (diff)
Add initial support for full-size PDF generation
Some issues: 1) The PDF generation stores every page in memory while it constructs it. That means that there's a higher chance of failure due to running out of memory with these. There's no getting around this except by improving the PDF generation library, which is not easy. 2) Currently I've just changed the pipeline to always generate these full size PDFs, and then the rescribe tool will just delete them if they weren't requested. This is bad in particular because of point 1, and would probably cause issues of failures in the server pipeline as a result Therefore the plan is to add a tag to queue messages so that full size generation can be selectively enabled. Also, it should be split from the loop with colour pdf generation, as holding them both in RAM at the same time is unnecessary.
Diffstat (limited to 'cmd/rescribe/main.go')
-rw-r--r--cmd/rescribe/main.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/cmd/rescribe/main.go b/cmd/rescribe/main.go
index 83153c6..96f6162 100644
--- a/cmd/rescribe/main.go
+++ b/cmd/rescribe/main.go
@@ -157,6 +157,7 @@ These training files are included in rescribe, and are always available:
`)
tesscmd := flag.String("tesscmd", deftesscmd, "The Tesseract executable to run. You may need to set this to the full path of Tesseract.exe if you're on Windows.")
wipe := flag.Bool("wipe", false, "Use wiper tool to remove noise like gutters from page before processing.")
+ fullpdf := flag.Bool("fullpdf", false, "Create a full-size searchable PDF (rather than a reduced size one).")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), usage)
@@ -306,7 +307,7 @@ These training files are included in rescribe, and are always available:
ispdf = true
}
- err = startProcess(ctx, *verboselog, tessCommand, bookdir, bookname, trainingName, savedir, tessdir, !*wipe)
+ err = startProcess(ctx, *verboselog, tessCommand, bookdir, bookname, trainingName, savedir, tessdir, !*wipe, *fullpdf)
if err != nil {
log.Fatalln(err)
}
@@ -446,7 +447,7 @@ func rmIfNotImage(f string) error {
return nil
}
-func startProcess(ctx context.Context, logger log.Logger, tessCommand string, bookdir string, bookname string, trainingName string, savedir string, tessdir string, nowipe bool) error {
+func startProcess(ctx context.Context, logger log.Logger, tessCommand string, bookdir string, bookname string, trainingName string, savedir string, tessdir string, nowipe bool, fullpdf bool) error {
cmd := exec.Command(tessCommand, "--help")
pipeline.HideCmd(cmd)
_, err := cmd.Output()
@@ -544,8 +545,17 @@ func startProcess(ctx context.Context, logger log.Logger, tessCommand string, bo
// to .pdf.
binpath := filepath.Join(savedir, bookname+".binarised.pdf")
colourpath := filepath.Join(savedir, bookname+".colour.pdf")
+ fullsizepath := filepath.Join(savedir, bookname+".original.pdf")
pdfpath := filepath.Join(savedir, bookname+" searchable.pdf")
+ // If full size pdf is requested, replace colour.pdf with it,
+ // otherwise just remove it
+ if fullpdf {
+ _ = os.Rename(fullsizepath, colourpath)
+ } else {
+ _ = os.Remove(fullsizepath)
+ }
+
_, err = os.Stat(binpath)
binexists := err == nil || os.IsExist(err)
_, err = os.Stat(colourpath)