Skip to content

Commit

Permalink
Merge pull request NAG-DevOps#38 from carlos-encs/poppler
Browse files Browse the repository at this point in the history
Poppler example: interactive job
  • Loading branch information
smokhov authored Feb 27, 2024
2 parents 08a0bc1 + 5f377d5 commit b6a193a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ These are examples either trivial or some are more elaborate. Some are described
- `tmpdir.sh` -- example use of TMPDIR on a local node
- `bash.sh` -- example use with `bash` shell as opposed to `tcsh`
- `manual.sh` -- example job to compile our very manual here to PDF and HTML using LaTeX
- `poppler.txt` -- Interactive job example: PDF rendering using poppler and pdf2image; instructions and code ready to paste.
- Common packages:
- `fluent.sh` -- Fluent job
- `comsol.sh` -- Comsol job
Expand Down
34 changes: 34 additions & 0 deletions src/poppler.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Interactive job example
# PDF rendering using poppler and pdf2image
# It will render each PDF page to a pageXX.jpg file

1. From speed-submit: salloc --mem=1Gb
2. Create conda environment:
2.1 conda create --prefix /speed-scratch/$USER/poppler-venv python=3.8
2.2 conda activate /speed-scratch/$USER/poppler-venv
2.3 conda install -c conda-forge poppler
2.4 pip install pdf2image
2.5 pip install poppler-utils

3. Create python script.

Python script:
from pdf2image import convert_from_path, convert_from_bytes
from pdf2image.exceptions import (
PDFInfoNotInstalledError,
PDFPageCountError,
PDFSyntaxError
)


# Store Pdf with convert_from_path function
images = convert_from_path('./pdf1.pdf')

for i in range(len(images)):

# Save pages as images in the pdf
images[i].save('page'+ str(i) +'.jpg', 'JPEG')

4. Execute the script: python script_name
5. If any rendering error is shown, check if the PDF is composed correctly:
5.1 pdfinfo pdf1.pdf

0 comments on commit b6a193a

Please sign in to comment.