diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2017-03-12 16:06:49 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2017-03-12 16:06:49 -0700 |
commit | e8002484da81d88e2de218468ed920ab9b1848d2 (patch) | |
tree | 76974b0114e0d9e7b780c4dc63d4c1d3ee68b2e3 | |
parent | 69ece105e8dd278e33f85841947fe5f263bd7437 (diff) | |
download | sscan-e8002484da81d88e2de218468ed920ab9b1848d2.tar.gz |
don't open output file handle
That way, the final PDF file is created only once OCR is complete.
-rw-r--r-- | Main.hs | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -47,7 +47,6 @@ processScanSessDir st dir = withCurrentDirectory dir $ do posix <- getPOSIXTime let stamp = show (round posix :: Int) logH <- openFile (logFile stamp) WriteMode -- TODO maybe AppendMode? - outH <- openFile (outFile stamp) WriteMode void $ case st^.stOutFormat of PDF -> do -- 1. convert tiff->PDF @@ -87,20 +86,19 @@ processScanSessDir st dir = withCurrentDirectory dir $ do -- 4. qpdf (ocrmypdf invokes qpdf but it doesn't use -- --linearize, which shrinks the PDF, often substantially) void $ createProcessWait_ "qpdf" - (proc "qpdf" ["--linearize", "temp.pdf", "-"]) + (proc "qpdf" ["--linearize", "temp.pdf", outFile stamp]) { std_in = NoStream - , std_out = UseHandle outH + , std_out = NoStream , std_err = UseHandle logH } -- assume that only one page was scanned. Not clear how we -- can avoid this assumption when producing a PNG PNG -> void $ createProcessWait_ "convert" - (proc "convert" ["page1" <.> "tiff", "png:-"]) + (proc "convert" ["page1" <.> "tiff", outFile stamp]) { std_in = NoStream - , std_out = UseHandle outH + , std_out = NoStream , std_err = UseHandle logH } - hClose outH hClose logH -- clean up the log file if it's empty finalLog <- readFile (logFile stamp) |