PyPDF2 para manipular arquivos PDF (PdfReader)

This commit is contained in:
Luiz Otávio
2023-02-18 09:30:27 -03:00
parent e47c563aa7
commit 5c8e72c804
2 changed files with 26 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -1,4 +1,4 @@
# # PyPDF2 para manipular arquivos PDF (Instalação)
# PyPDF2 para manipular arquivos PDF (PdfReader)
# PyPDF2 é uma biblioteca de manipulação de arquivos PDF feita em Python puro,
# gratuita e de código aberto. Ela é capaz de ler, manipular, escrever e unir
# dados de arquivos PDF, assim como adicionar anotações, transformar páginas,
@@ -7,3 +7,28 @@
# Link: https://pypdf2.readthedocs.io/en/3.0.0/
# Ative seu ambiente virtual
# pip install pypdf2
from pathlib import Path
from PyPDF2 import PdfReader
PASTA_RAIZ = Path(__file__).parent
PASTA_ORIGINAIS = PASTA_RAIZ / 'pdfs_originais'
PASTA_NOVA = PASTA_RAIZ / 'arquivos_novos'
RELATORIO_BACEN = PASTA_ORIGINAIS / 'R20230210.pdf'
PASTA_NOVA.mkdir(exist_ok=True)
reader = PdfReader(RELATORIO_BACEN)
# print(len(reader.pages))
# for page in reader.pages:
# print(page)
# print()
page0 = reader.pages[0]
imagem0 = page0.images[0]
# print(page0.extract_text())
# with open(PASTA_NOVA / imagem0.name, 'wb') as fp:
# fp.write(imagem0.data)