Skip to main content

Uma biblioteca Python para criar, compor, visualizar, manipular e aplicar OCR em PDFs.

Project description

RabbitPDF

RabbitPDF é uma biblioteca Python para criar, compor, visualizar, manipular e aplicar OCR em arquivos PDF.

Versão atual: 0.3.0.

English README

Recursos

  • Criar PDFs simples a partir de texto, linhas ou imagens.
  • Compor documentos ricos com cabeçalho, rodapé, tabelas, imagens, marca d'água, numeração de páginas e estilos de texto.
  • Renderizar templates JSON com variáveis, tabelas repetíveis e preview web local.
  • Extrair PDFs existentes para JSON-base de template.
  • Ajustar fonte, tamanho, entrelinha, margens independentes, espaçamentos, bordas e padding de tabelas.
  • Juntar, extrair, dividir, criptografar, descriptografar e marcar PDFs existentes.
  • Abrir PDFs no visualizador local ou em uma página HTML simples.
  • Executar OCR em PDFs digitalizados com dependências opcionais.
  • Usar por API Python ou pela CLI rabbitpdf.

Instalação

pip install RabbitPDF

Para OCR:

pip install "RabbitPDF[ocr]"

O OCR também exige o binário do Tesseract instalado no sistema.

Começo Rápido

from rabbitpdf import PDFCreator, PDFViewer

PDFCreator(title="Exemplo").create_from_text(
    "Olá, RabbitPDF!",
    "hello.pdf",
)

PDFViewer("hello.pdf").open()

Para abrir em um viewer web local:

PDFViewer("hello.pdf").web()
PDFViewer("hello.pdf").web(5522)

Em templates, o preview pode ficar junto da criacao:

from rabbitpdf import PDFViewer, render_template_file

created = render_template_file("template.json", "dados.json", "saida.pdf")
PDFViewer.web(created)

Documento Avançado

from reportlab.lib.units import cm

from rabbitpdf import DocumentTheme, RabbitDocument, TableOptions, TextStyle

(
    RabbitDocument(
        title="Relatório",
        page_size="A4",
        left_margin=2.5 * cm,
        right_margin=2.5 * cm,
        top_margin=2.0 * cm,
        bottom_margin=2.0 * cm,
        theme=DocumentTheme(font_size=11, leading=14),
    )
    .add_paragraph("RELATÓRIO", bold=True, underline=True, align="center")
    .add_spacer(16)
    .add_table(
        [
            ["Item", "Valor"],
            ["Subtotal", "R$ 100,00"],
            ["Total", "R$ 100,00"],
        ],
        options=TableOptions(
            repeat_header=True,
            padding=6,
            cell_style=TextStyle(font_size=10, leading=12, space_after=0),
        ),
    )
    .build("relatorio.pdf")
)

CLI

Criar PDF com texto:

rabbitpdf create hello.pdf --text "Olá, RabbitPDF"

Criar PDF a partir de imagens:

rabbitpdf create album.pdf --images pagina-1.png pagina-2.jpg

Juntar PDFs:

rabbitpdf merge final.pdf capa.pdf conteudo.pdf anexos.pdf

Renderizar template com dados:

rabbitpdf template render examples/live_preview_template.json examples/live_preview_data.json invoice.pdf

Abrir preview web do template:

rabbitpdf template preview examples/live_preview_template.json examples/live_preview_data.json

Extrair um PDF para JSON-base de template:

rabbitpdf template extract entrada.pdf template-extraido.json

Abrir PDF pronto em viewer web local:

rabbitpdf view invoice.pdf --web
rabbitpdf view invoice.pdf --web --port 5522

Extrair páginas:

rabbitpdf extract relatorio.pdf resumo.pdf --pages "1,3-5,-1"

Adicionar marca d'água:

rabbitpdf watermark entrada.pdf saida.pdf --text "CONFIDENCIAL"

Se o executável não estiver no PATH, use:

python -m rabbitpdf --help

Exemplos

Os exemplos ficam em examples e geram arquivos em examples/output/.

Execute qualquer exemplo com:

python examples/ex01_quick_start.py

Documentação

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rabbitpdf-0.3.0.tar.gz (80.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rabbitpdf-0.3.0-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file rabbitpdf-0.3.0.tar.gz.

File metadata

  • Download URL: rabbitpdf-0.3.0.tar.gz
  • Upload date:
  • Size: 80.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rabbitpdf-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a659f79fb1272662200a2a3febc1518acac963319224268fee93d9771263e746
MD5 89a0b93937553ab07050bffe5db47ea7
BLAKE2b-256 f9e1093e1e7abf69f3281b869481aef3c2f838602d5da52bff75ebea1d5075cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for rabbitpdf-0.3.0.tar.gz:

Publisher: publish.yml on juca-soft/RabbitPDF

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rabbitpdf-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: rabbitpdf-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 34.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rabbitpdf-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d99ff9c803fa8d659e90bba29fbc4f2dc1ea22de96c3618b61484d6c61c7d6f3
MD5 28cd9297395f50ddba5e3bab9928b915
BLAKE2b-256 0d5d18b75f8312a614e2ce04a456dbe7d061c4fd1656723a9a345336c7a8a50f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rabbitpdf-0.3.0-py3-none-any.whl:

Publisher: publish.yml on juca-soft/RabbitPDF

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page