Skip to main content

A module for creating PDF files

Project description

PDF-Tool

A module for creating PDF files manually.

Example usage:

Create a simple PDF with Hello World!

import pdf_tool as pt

file = pt.NewPDF(filepath="myPDF.pdf")

# write text to the given page
file.text(page=0, x=300, y=600, line_space=2,
   text=f"Hello <red>World</red>!", size=36)

file.save()

Add pages

import pdf_tool as pt

file = pt.NewPDF(filepath="myPDF.pdf")

print(file.get_page_indexes())

file.set_page_size(index=0, width=1000, height=1000)

file.add_page(size=(500, 500))

new_page_content = pt.Obj(index="9", type="Stream")
file.add_obj(obj=new_page_content)

page_parent = file.get_obj(type="Pages")[0]
page_font = file.get_obj(type="Font")[0]
file.add_obj(index="10", type="Page", contents="9", parent=page_parent.index(), mediabox=[0, 0, 400, 800],
             resources=pt.Resources(font=page_font.get_font_name(), font_index=page_font.index()))

print(file.get_page_indexes())

file.text(page=1, x=200, y=600, line_space=2,
          text=f"This is the <red>first</red> page.", size=36)
file.text(page=2, x=200, y=200, line_space=2,
          text=f"This is the <blue>second</blue> page.", size=24)
file.text(page=3, x=200, y=500, line_space=2,
          text=f"This is the 3<sup>th</sup> page.<r>New line.", size=24)

file.move_page(from_index=1, to_index=3, base=1)

file.save()

Draw scatters and lines

import pdf_tool as pt

file = pt.NewPDF(filepath="myPDF.pdf")

# write text to the given page

# draw lines to the given page
file.line(page=0, start=[100, 100], end=[300, 300], width=1, color="black")
file.line(page=0, start=[500, 100], end=[300, 300], width=5, color="red")

# draw a rectangle to the given page
file.rect(page=0, left_bottom=[100, 100], width=400, height=400, line_width=1, color="blue")

# draw scatters
for i in range(50):
    file.scatter(page=0, x=200 + i * 10, y=400 + i * 2, size=4)
    file.scatter(page=0, x=500 - i * 10, y=400 + i * 2, size=4, type="rectangle")

# save pdf
file.save()

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

pdf-maker-0.0.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

pdf_maker-0.0.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file pdf-maker-0.0.1.tar.gz.

File metadata

  • Download URL: pdf-maker-0.0.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for pdf-maker-0.0.1.tar.gz
Algorithm Hash digest
SHA256 222f074e42c44dbffdad6372230f0ffaee80ff568dbe54cc34c5f0bc1db65a6f
MD5 896c96fee343196bc420844c451a9e88
BLAKE2b-256 ac9de95ab929de9c4cf7a45383eedc215034bb0a628df640a453ada19b2e0324

See more details on using hashes here.

File details

Details for the file pdf_maker-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pdf_maker-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for pdf_maker-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f34c1adc46261ba502d070fc3bf8e9e4784b26f64ad4c4fcc7151d0257e77a04
MD5 ce63c95b21c9a7ad35cbe06285877872
BLAKE2b-256 d42b728f92fc76845792866e7202afca1735df1bdf924de04adcbbe91b650089

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