Metadata-Version: 2.4
Name: RabbitPDF
Version: 0.3.0
Summary: Uma biblioteca Python para criar, compor, visualizar, manipular e aplicar OCR em PDFs.
Project-URL: Homepage, https://github.com/juca-soft/RabbitPDF
Project-URL: Repository, https://github.com/juca-soft/RabbitPDF
Project-URL: Issues, https://github.com/juca-soft/RabbitPDF/issues
Author: Juca Soft
License-Expression: MIT
License-File: LICENSE
Keywords: ocr,pdf,reportlab,tesseract,viewer
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Text Processing
Requires-Python: >=3.9
Requires-Dist: pdfplumber>=0.11
Requires-Dist: pypdf>=4.0
Requires-Dist: reportlab>=4.0
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: twine>=5.0; extra == 'dev'
Provides-Extra: ocr
Requires-Dist: pillow>=10; extra == 'ocr'
Requires-Dist: pymupdf>=1.24; extra == 'ocr'
Requires-Dist: pytesseract>=0.3.10; extra == 'ocr'
Description-Content-Type: text/markdown

# RabbitPDF

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

Versão atual: `0.3.0`.

[English README](README.en.md)

## 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

```bash
pip install RabbitPDF
```

Para OCR:

```bash
pip install "RabbitPDF[ocr]"
```

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

## Começo Rápido

```python
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:

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

Em templates, o preview pode ficar junto da criacao:

```python
from rabbitpdf import PDFViewer, render_template_file

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

## Documento Avançado

```python
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:

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

Criar PDF a partir de imagens:

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

Juntar PDFs:

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

Renderizar template com dados:

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

Abrir preview web do template:

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

Extrair um PDF para JSON-base de template:

```bash
rabbitpdf template extract entrada.pdf template-extraido.json
```

Abrir PDF pronto em viewer web local:

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

Extrair páginas:

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

Adicionar marca d'água:

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

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

```bash
python -m rabbitpdf --help
```

## Exemplos

Os exemplos ficam em [examples](examples) e geram arquivos em
`examples/output/`.

- [ex01_quick_start.py](examples/ex01_quick_start.py): PDF simples a partir de texto.
- [ex02_image_album.py](examples/ex02_image_album.py): PDF a partir de imagens.
- [ex03_rich_document.py](examples/ex03_rich_document.py): documento com cabeçalho,
  rodapé, marca d'água e placeholder.
- [ex04_table_report.py](examples/ex04_table_report.py): relatório com tabela.
- [ex05_key_value_document.py](examples/ex05_key_value_document.py): documento
  chave/valor.
- [ex06_invoice_template.py](examples/ex06_invoice_template.py): invoice com
  template e variáveis.
- [ex07_parecer_documental.py](examples/ex07_parecer_documental.py): parecer
  documental com template.
- [ex08_pdf_operations.py](examples/ex08_pdf_operations.py): merge, watermark,
  extração e split.
- [ex09_security.py](examples/ex09_security.py): criptografia e descriptografia.
- [ex10_live_preview.py](examples/ex10_live_preview.py): preview web vivo.
- [ex11_cloudflare_invoice.py](examples/ex11_cloudflare_invoice.py): fatura estilo
  Cloudflare com paginacao automatica.

Execute qualquer exemplo com:

```bash
python examples/ex01_quick_start.py
```

## Documentação

- [Introdução](docs/introducao.md)
- [Documentos avançados](docs/documentos-avancados.md)
- [Templates e Preview](docs/templates.md)
- [Extrair Template de PDF](docs/extrair-template.md)
- [Preview Web](docs/preview-web.md)
- [Parecer Documental com Template](docs/parecer-documental.md)
- [Operações em PDFs](docs/operacoes-pdf.md)
- [CLI](docs/cli.md)
- [Exemplos](docs/exemplos.md)
- [Referência da API](docs/referencia-api.md)
