From c7387de325c769bf0b746085f41d3811f5cbc94b Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Tue, 1 May 2018 15:18:28 -0700 Subject: [PATCH] Fix auto rotate --- src/ocrmypdf/pipeline.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ocrmypdf/pipeline.py b/src/ocrmypdf/pipeline.py index a99b81f9..31d3b0db 100644 --- a/src/ocrmypdf/pipeline.py +++ b/src/ocrmypdf/pipeline.py @@ -849,6 +849,7 @@ def weave_layers( pdf_base = pikepdf.open(path_base) keep_open = [] font, font_key = None, None + pdfinfo = context.get_pdfinfo() # Iterate rest for page_num, layers in groups: @@ -877,7 +878,15 @@ def weave_layers( if text and font: # Graft the text layer onto this page, whether new or old - _weave_layers_graft(pdf_base, page_num, text, font, font_key, log) + _weave_layers_graft( + pdf_base, page_num, text, font, font_key, log) + + # Correct the rotation + rotation = pdfinfo[page_num - 1].rotation + rotation = -rotation % 360 + if rotation != 0: + pdf_base.pages[page_num - 1].Rotate = rotation + pdf_base.save(output_file)