From 9d1382b69700129a66541d786ba3b784eda56e36 Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 11 Mar 2022 13:36:59 +0000 Subject: 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. --- internal/pipeline/get.go | 2 +- internal/pipeline/pipeline.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'internal') diff --git a/internal/pipeline/get.go b/internal/pipeline/get.go index de4ac3b..8fac060 100644 --- a/internal/pipeline/get.go +++ b/internal/pipeline/get.go @@ -68,7 +68,7 @@ func DownloadBestPngs(dir string, name string, conn Downloader) error { func DownloadPdfs(dir string, name string, conn Downloader) error { anydone := false errmsg := "" - for _, suffix := range []string{".colour.pdf", ".binarised.pdf"} { + for _, suffix := range []string{".colour.pdf", ".binarised.pdf", ".original.pdf"} { key := filepath.Join(name, name+suffix) fn := filepath.Join(dir, name+suffix) err := conn.Download(conn.WIPStorageId(), key, fn) diff --git a/internal/pipeline/pipeline.go b/internal/pipeline/pipeline.go index 40ed02c..cbd179b 100644 --- a/internal/pipeline/pipeline.go +++ b/internal/pipeline/pipeline.go @@ -455,6 +455,12 @@ func Analyse(conn Downloader) func(context.Context, chan string, chan string, ch errc <- fmt.Errorf("Failed to set up PDF: %s", err) return } + fullsizepdf := new(bookpipeline.Fpdf) + err = fullsizepdf.Setup() + if err != nil { + errc <- fmt.Errorf("Failed to set up PDF: %s", err) + return + } binhascontent, colourhascontent := false, false select { @@ -551,6 +557,11 @@ 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 { @@ -575,6 +586,14 @@ func Analyse(conn Downloader) func(context.Context, chan string, chan string, ch return } up <- fn + + fn = filepath.Join(savedir, bookname+".original.pdf") + err = fullsizepdf.Save(fn) + if err != nil { + errc <- fmt.Errorf("Failed to save full size pdf: %s", err) + return + } + up <- fn } select { -- cgit v1.2.1-24-ge1ad