{"action":"created","issue":{"url":"https://api.github.com/repos/jbarlow83/OCRmyPDF/issues/2","labels_url":"https://api.github.com/repos/jbarlow83/OCRmyPDF/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/jbarlow83/OCRmyPDF/issues/2/comments","events_url":"https://api.github.com/repos/jbarlow83/OCRmyPDF/issues/2/events","html_url":"https://github.com/jbarlow83/OCRmyPDF/issues/2","id":106254251,"number":2,"title":"Some input PDFs with Tesseract-OCR throw error in PyPDF2.utils.PdfReadError(Unexpected escaped string: b'{')' raised in ...","user":{"login":"OCRmyPDF-issuebot","id":14266523,"avatar_url":"https://avatars.githubusercontent.com/u/14266523?v=3","gravatar_id":"","url":"https://api.github.com/users/OCRmyPDF-issuebot","html_url":"https://github.com/OCRmyPDF-issuebot","followers_url":"https://api.github.com/users/OCRmyPDF-issuebot/followers","following_url":"https://api.github.com/users/OCRmyPDF-issuebot/following{/other_user}","gists_url":"https://api.github.com/users/OCRmyPDF-issuebot/gists{/gist_id}","starred_url":"https://api.github.com/users/OCRmyPDF-issuebot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCRmyPDF-issuebot/subscriptions","organizations_url":"https://api.github.com/users/OCRmyPDF-issuebot/orgs","repos_url":"https://api.github.com/users/OCRmyPDF-issuebot/repos","events_url":"https://api.github.com/users/OCRmyPDF-issuebot/events{/privacy}","received_events_url":"https://api.github.com/users/OCRmyPDF-issuebot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-09-14T01:14:30Z","updated_at":"2015-09-14T01:14:32Z","closed_at":null,"body":"<a href=\"https://github.com/Wikinaut\"><img src=\"https://avatars.githubusercontent.com/u/1151915?v=3\" align=\"left\" width=\"96\" height=\"96\" hspace=\"10\"></img></a> **Issue by [Wikinaut](https://github.com/Wikinaut)**\n_Mon Sep  7 18:56:47 2015_\n_Originally opened as https://github.com/fritz-hh/OCRmyPDF/issues/120_\n\n----\n\nA few PDF input files (**which were already processed by tesseract-ocr pdf mode**) throw an error in OCRmyPDF even in the ```--force-ocr``` mode. At the moment, I have no idea what exactly happens, but the problem appears to be in PyPDF2 (I use PyPDF2 1.25.1).\r\n\r\nThe error message is only shown when OCRmyPDF is used with the ```-v``` option.\r\n\r\nDo you have an idea what went wrong in these cases, or what else can be done to let OCRmyPDF apply another OCR run to such a PDF?\r\n\r\n\r\nFull output:\r\n```\r\nTasks which will be run:\r\nTask enters queue = 'ocrmypdf.main.repair_pdf' \r\nOriginal exception:\r\n    Exception #1\r\n      'PyPDF2.utils.PdfReadError(Unexpected escaped string: b'{')' raised in ...\r\n       Task = def ocrmypdf.main.repair_pdf(...):\r\n       Job  = [ARCHIV.pdf -> .../com.github.ocrmypdf.49q2h1fj/ARCHIV.repaired.pdf, <ocrmypdf.main.WrappedLogger>, [], <_thread.lock>]\r\n    \r\n    Traceback (most recent call last):\r\n      File \"/usr/lib/python3.4/site-packages/ruffus/task.py\", line 751, in run_pooled_job_without_exceptions\r\n        register_cleanup, touch_files_only)\r\n      File \"/usr/lib/python3.4/site-packages/ruffus/task.py\", line 567, in job_wrapper_io_files\r\n        ret_val = user_defined_work_func(*params)\r\n      File \"/usr/local/src/OCRmyPDF/ocrmypdf/main.py\", line 372, in repair_pdf\r\n        pdfinfo.extend(pdf_get_all_pageinfo(output_file))\r\n      File \"/usr/local/src/OCRmyPDF/ocrmypdf/pageinfo.py\", line 145, in pdf_get_all_pageinfo\r\n        return [_pdf_get_pageinfo(infile, n) for n in range(pdf.numPages)]\r\n      File \"/usr/local/src/OCRmyPDF/ocrmypdf/pageinfo.py\", line 145, in <listcomp>\r\n        return [_pdf_get_pageinfo(infile, n) for n in range(pdf.numPages)]\r\n      File \"/usr/local/src/OCRmyPDF/ocrmypdf/pageinfo.py\", line 115, in _pdf_get_pageinfo\r\n        text = page.extractText()\r\n      File \"/usr/lib/python3.4/site-packages/PyPDF2/pdf.py\", line 2566, in extractText\r\n        content = ContentStream(content, self.pdf)\r\n      File \"/usr/lib/python3.4/site-packages/PyPDF2/pdf.py\", line 2645, in __init__\r\n        self.__parseContentStream(stream)\r\n      File \"/usr/lib/python3.4/site-packages/PyPDF2/pdf.py\", line 2677, in __parseContentStream\r\n        operands.append(readObject(stream, None))\r\n      File \"/usr/lib/python3.4/site-packages/PyPDF2/generic.py\", line 71, in readObject\r\n        return ArrayObject.readFromStream(stream, pdf)\r\n      File \"/usr/lib/python3.4/site-packages/PyPDF2/generic.py\", line 166, in readFromStream\r\n        arr.append(readObject(stream, pdf))\r\n      File \"/usr/lib/python3.4/site-packages/PyPDF2/generic.py\", line 77, in readObject\r\n        return readStringFromStream(stream)\r\n      File \"/usr/lib/python3.4/site-packages/PyPDF2/generic.py\", line 386, in readStringFromStream\r\n        raise utils.PdfReadError(r\"Unexpected escaped string: %s\" % tok)\r\n    PyPDF2.utils.PdfReadError: Unexpected escaped string: b'{'\r\n```\n"},"comment":{"url":"https://api.github.com/repos/jbarlow83/OCRmyPDF/issues/comments/139934814","html_url":"https://github.com/jbarlow83/OCRmyPDF/issues/2#issuecomment-139934814","issue_url":"https://api.github.com/repos/jbarlow83/OCRmyPDF/issues/2","id":139934814,"user":{"login":"OCRmyPDF-issuebot","id":14266523,"avatar_url":"https://avatars.githubusercontent.com/u/14266523?v=3","gravatar_id":"","url":"https://api.github.com/users/OCRmyPDF-issuebot","html_url":"https://github.com/OCRmyPDF-issuebot","followers_url":"https://api.github.com/users/OCRmyPDF-issuebot/followers","following_url":"https://api.github.com/users/OCRmyPDF-issuebot/following{/other_user}","gists_url":"https://api.github.com/users/OCRmyPDF-issuebot/gists{/gist_id}","starred_url":"https://api.github.com/users/OCRmyPDF-issuebot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCRmyPDF-issuebot/subscriptions","organizations_url":"https://api.github.com/users/OCRmyPDF-issuebot/orgs","repos_url":"https://api.github.com/users/OCRmyPDF-issuebot/repos","events_url":"https://api.github.com/users/OCRmyPDF-issuebot/events{/privacy}","received_events_url":"https://api.github.com/users/OCRmyPDF-issuebot/received_events","type":"User","site_admin":false},"created_at":"2015-09-14T01:14:32Z","updated_at":"2015-09-14T01:14:32Z","body":"<a href=\"https://github.com/jbarlow83\"><img src=\"https://avatars.githubusercontent.com/u/1825843?v=3\" align=\"left\" width=\"48\" height=\"48\" hspace=\"10\"></img></a> **Comment by [jbarlow83](https://github.com/jbarlow83)**\n_Mon Sep  7 22:13:55 2015_\n\n----\n\nI'd like the PDF because any errors get added to the test suite. I'm less interested in what produced the problem so much as trying to make sure all readable PDFs are accepted even if they are invalid.\r\n\r\nYour project is quite similar to what this one does right now - just so you're aware. ocrmypdf converts pages to PNG uses ghostscript (btw: ImageMagick's convert also uses ghostscript, it just uses it badly), then uses tesseract for PDF rendering (optional with `--pdf-renderer tesseract`), and then uses ghostscript to merge. The error you ran into is in the first step, not later on in the pipeline. \r\n\r\nTesseract's PDF rendering has some issues (at least as of 3.03). It gets DPI wrong, it produces PDFs with syntax errors, and it can inflate file size in some situations. For those reasons `--pdf-renderer tesseract` is not the default. I'll be adding code to repair those problems or (more likely) extract the OCR layer from Tesseract's output and graft it into the final PDF, so that I can insert the text layer without transcoding any images.\n"}}