summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorNick White <git@njw.name>2022-03-11 17:34:48 +0000
committerNick White <git@njw.name>2022-03-11 17:34:48 +0000
commitaf8650c074bc111200b132b0918d44cacd423b6e (patch)
tree868b45ff75da99d8583bebe60630ef698fe1ae63 /internal
parent9d1382b69700129a66541d786ba3b784eda56e36 (diff)
Separate out fullsize pdf creation from colour pdf creation, so less memory is neededfullsizepdf
Diffstat (limited to 'internal')
-rw-r--r--internal/pipeline/pipeline.go47
1 files changed, 42 insertions, 5 deletions
diff --git a/internal/pipeline/pipeline.go b/internal/pipeline/pipeline.go
index cbd179b..a09a414 100644
--- a/internal/pipeline/pipeline.go
+++ b/internal/pipeline/pipeline.go
@@ -557,11 +557,6 @@ func Analyse(conn Downloader) func(context.Context, chan string, chan string, ch
errc <- fmt.Errorf("Failed to add page %s to PDF: %s", pg.img, err)
return
}
- err = fullsizepdf.AddPage(filepath.Join(savedir, colourfn), filepath.Join(savedir, pg.hocr), false)
- if err != nil {
- errc <- fmt.Errorf("Failed to add page %s to PDF: %s", pg.img, err)
- return
- }
colourhascontent = true
err = os.Remove(filepath.Join(savedir, colourfn))
if err != nil {
@@ -586,7 +581,49 @@ func Analyse(conn Downloader) func(context.Context, chan string, chan string, ch
return
}
up <- fn
+ }
+
+ for _, pg := range colourimgs {
+ select {
+ case <-ctx.Done():
+ errc <- ctx.Err()
+ return
+ default:
+ }
+ logger.Println("Downloading colour page to add to PDF", pg.img)
+ colourfn := pg.img
+ err = conn.Download(conn.WIPStorageId(), bookname+"/"+colourfn, filepath.Join(savedir, colourfn))
+ if err != nil {
+ colourfn = strings.Replace(pg.img, ".jpg", ".png", 1)
+ logger.Println("Download failed; trying", colourfn)
+ err = conn.Download(conn.WIPStorageId(), bookname+"/"+colourfn, filepath.Join(savedir, colourfn))
+ if err != nil {
+ logger.Println("Download failed; skipping page", pg.img)
+ }
+ }
+ if err == nil {
+ err = fullsizepdf.AddPage(filepath.Join(savedir, colourfn), filepath.Join(savedir, pg.hocr), false)
+ if err != nil {
+ errc <- fmt.Errorf("Failed to add page %s to PDF: %s", pg.img, err)
+ return
+ }
+ err = os.Remove(filepath.Join(savedir, colourfn))
+ if err != nil {
+ errc <- err
+ return
+ }
+ }
+ }
+
+ select {
+ case <-ctx.Done():
+ errc <- ctx.Err()
+ return
+ default:
+ }
+
+ if colourhascontent {
fn = filepath.Join(savedir, bookname+".original.pdf")
err = fullsizepdf.Save(fn)
if err != nil {