|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "# !python -m pip install pdf2image\n", |
| 10 | + "from pdf2image import convert_from_path\n", |
| 11 | + "\n", |
| 12 | + "from os import listdir\n", |
| 13 | + "from os.path import isfile, join" |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "code", |
| 18 | + "execution_count": null, |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "# set directory path\n", |
| 23 | + "dir_pth = f\"./\"\n", |
| 24 | + "\n", |
| 25 | + "filenames = [f for f in listdir(dir_pth) if isfile(join(dir_pth, f))]\n", |
| 26 | + "\n", |
| 27 | + "for filename in filenames:\n", |
| 28 | + " fn, fn_type = filename.split(\".\")\n", |
| 29 | + " if fn_type == \"pdf\":\n", |
| 30 | + " pages = convert_from_path(filename, 500)\n", |
| 31 | + " for i, page in enumerate(pages):\n", |
| 32 | + " page.save(f'{fn}{i+1}.jpg', 'JPEG') " |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "code", |
| 37 | + "execution_count": null, |
| 38 | + "metadata": {}, |
| 39 | + "outputs": [], |
| 40 | + "source": [ |
| 41 | + "type(page) # Out: PIL.PpmImagePlugin.PpmImageFile" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "code", |
| 46 | + "execution_count": null, |
| 47 | + "metadata": {}, |
| 48 | + "outputs": [], |
| 49 | + "source": [] |
| 50 | + } |
| 51 | + ], |
| 52 | + "metadata": { |
| 53 | + "kernelspec": { |
| 54 | + "display_name": "Python 3", |
| 55 | + "language": "python", |
| 56 | + "name": "python3" |
| 57 | + }, |
| 58 | + "language_info": { |
| 59 | + "codemirror_mode": { |
| 60 | + "name": "ipython", |
| 61 | + "version": 3 |
| 62 | + }, |
| 63 | + "file_extension": ".py", |
| 64 | + "mimetype": "text/x-python", |
| 65 | + "name": "python", |
| 66 | + "nbconvert_exporter": "python", |
| 67 | + "pygments_lexer": "ipython3", |
| 68 | + "version": "3.7.4" |
| 69 | + } |
| 70 | + }, |
| 71 | + "nbformat": 4, |
| 72 | + "nbformat_minor": 2 |
| 73 | +} |
0 commit comments