Last active
March 30, 2021 16:57
-
-
Save JonathanLalou/f29d950db91419534f75b29d2c288691 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| echo ON | |
| echo PDF to docx | |
| echo usage: pdf2doc FooBarBoo.pdf | |
| echo This will generate: FooBarBoo-jpeg.docx (a docx with JPEG pictures of the PDF) and FooBarBoo-OCR.docx (a docx with OCR-ized content of the PDF) | |
| cd %CD% | |
| where /q gswin32.exe || set PATH=C:\win32app\ghostscript-9.27\bin;%PATH% | |
| where /q soffice.exe || set PATH=C:\win32app\LibreOffice-6.1\App\libreoffice\program;%PATH% | |
| :LOOP | |
| if "%1" == "" goto END | |
| set FILENAME=%1 | |
| set FILENAME=%FILENAME:~0,-4% | |
| echo XXXXXXXXX %FILENAME% XXXXXXXXXXXXX | |
| C:\win32app\ImageMagick-7.0.11-0-portable-Q8-x86\convert -density 300 %FILENAME%.pdf %FILENAME%-%%03d.jpg | |
| C:\win32app\ImageMagick-7.0.11-0-portable-Q8-x86\convert %FILENAME%-*.jpg %FILENAME%-jpeg.pdf | |
| soffice --infilter="writer_pdf_import" --convert-to docx %FILENAME%-jpeg.pdf | |
| :waitForJpegPdf | |
| IF NOT EXIST %FILENAME%-jpeg.pdf ( | |
| sleep 5 | |
| goto waitForJpegPdf | |
| ) | |
| soffice --infilter="writer_pdf_import" --convert-to docx %FILENAME%.pdf | |
| :waitForOcrPdf | |
| IF NOT EXIST %FILENAME%.pdf ( | |
| sleep 5 | |
| goto waitForOcrPdf | |
| ) | |
| mv %FILENAME%.docx %FILENAME%-OCR.docx | |
| rm -rf %FILENAME%-*.jpg | |
| rm -rf %FILENAME%-jpeg.pdf | |
| SHIFT /1 | |
| goto LOOP | |
| :END | |
| echo Job is finished |
Author
Author
Update: accept a list of arguments (pdf2doc.bat foo.pdf bar.pdf boo.pdf).
Author
Update: sleep less ;-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick and dirty script to convert PDF documents to DocX.
This is useful to store some PDFs in GoogleDrive without consuming quota (...until June 2021!).