Skip to main content

A powerful PDF generator based on ReportLab

Project description

PDFmanager

一个简单、强大、中文友好的 PDF 生成库,基于 ReportLab 高级封装。

功能特性

  • 一键生成 PDF
  • 完美支持中文
  • 标题、文本、图片、表格快速生成
  • API 极简易用

快速开始

  1. 克隆项目 git clone https://github.com/jianfei1234/PDFManagers.git

  2. 安装依赖 pip install reportlab

  3. 运行示例 python example.py

使用示例

安装包

pip install PDFManagers

初始化

from PDFManagers import PDFManager
import matplotlib.pyplot as plt
from reportlab.lib.colors import Color

#PDF initialization
pdf = PDFManager('text')
#PDF initialization for chinese
#pdf = PDFManager('text', CNfont = 'path of chinese font.ttc')

插入段落

#insert paragraphs
paragraphs = [[('abc' * 30,)]]
pdf.draw_multiple_styled_paragraphs(paragraphs)

'''
#for paragraphes with defined fontname, font size, font color, paragraph alignment, background, border, textbox width, location
paragraphs = [[('abc' * 30, 'Helvetica', 15, 'red', 1)], [('def' * 30,)]]
paragraphs = [[('abc天' * 30, 'SimHei', 15, 'red', 1)], [('def天' * 30,)]]  #using SimHei for chinese
pdf.draw_multiple_styled_paragraphs(paragraphs,
                                        max_width=400,
                                        border_color='red',
                                        gradient_start=Color(142 / 255, 182 / 255, 6 / 255, 150 / 255),
                                        gradient_end=Color(50 / 255, 109 / 255, 173 / 255, 55 / 255),
                                        gradient_direction='horizontal')
'''

插入图片

#insert picture
pdf._add_picture(r"C:\Users\Administrator\Desktop\制作.png", width = 300, x = None, y = None)

#insert matplotlib plot
plt.plot([0, 1], [0, 1])
pdf._add_picture(plt)

插入表格

#insert table
data = [['ddd', 'fgd\n\nggd', 'ss\ndf', 'dgdf', 'fff'],
        ['ddd', 'fgdggd', 'ssdf', 'dgdf', 'fff'],
        ['ddd', 'fg\ndggd', 'ssdf', 'dgdf', 'fff'],
        ['ddd', 'fgdggd', 'ssdfg\ngfdfgdf', 'dgdf', 'fff'],]
pdf.draw_table(data, caption='title', note='note')

保存

#save pdf
pdf.save()

版权说明

Copyright © 2026 【Ma Jianfei】 本库仅限个人学习使用,商业用途请购买授权。

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

pdfmanagers-1.0.3.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

pdfmanagers-1.0.3-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file pdfmanagers-1.0.3.tar.gz.

File metadata

  • Download URL: pdfmanagers-1.0.3.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pdfmanagers-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0e4f4f9c4940a9dd0c34dae4db8e443f7980bded6f559f804f1ea8f196553451
MD5 942479f5ddce733e73638723dbfee00c
BLAKE2b-256 c8e216d44b08628c516ade227afa1f2d3963b0efe2e21a05ca434818edafef4a

See more details on using hashes here.

File details

Details for the file pdfmanagers-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pdfmanagers-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pdfmanagers-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c92f74981decfb4bbea61966fc205e82dbd11185b988f5e93d83ca22d6545b0d
MD5 ecf7f160636a8a315c6d9cc7dcb3222f
BLAKE2b-256 7cd9bd49b2f3cc6b2f4c3edb0002d94ebc9176565bf5aaac3f09789810fe58f9

See more details on using hashes here.

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