Skip to main content

A module for creating PDF files

Project description

PDF-Maker

A module for creating PDF files manually.

Example usage:

Create a simple PDF with Hello World!

import pdf_maker as pm

file = pm.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_maker as pm

file = pm.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 = pm.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=pm.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_maker as pm

file = pm.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()

Create Canvas

import numpy as np
import pdf_maker as pm

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

cv = pm.Canvas(width=250, height=200, scale=(0, 100, 0, 200), show_frame=True)

cv.text(name="TEXT01", x=50, y=50, text="hello", size=12, font="arial", coordinate="scale")

xs = np.random.randint(low=5, high=85, size=100)
ys = np.random.randint(low=5, high=200, size=100)
for x, y in zip(xs, ys):
    cv.scatter(name=f"SCATTER_{x}_{y}", x=x, y=y, size=2, coordinate="scale", fill_color="red" if y <= 100 else "grey")


for x in range(0, 100):
    cv.line(name=f"LINE_X_{x}", start=[x, 0], end=[x, 200], width=0.5, color="grey")

for y in range(0, 200):
    cv.line(name=f"LINE_Y_{y}", start=[0, y], end=[100, y], width=0.5, color="grey")

file.canvas(margin_left=150, margin_top=100, page=1, canvas=cv)

# 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.2.tar.gz (13.7 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.2-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdf-maker-0.0.2.tar.gz
  • Upload date:
  • Size: 13.7 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.2.tar.gz
Algorithm Hash digest
SHA256 94f0636c34bb4659e6a062a09bd8a5f14b6bd6466f50cc8ecfd8022ba506bd63
MD5 462e8dad4011d140d924e20e8281e850
BLAKE2b-256 36c78ef3f42e6b1420f41fa51737b810f7adb2c0d98bdcf199ef2ff743e3ddaf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdf_maker-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9dfd44006fc92d16b13ea88c216efd970ce80d2937f091f0eae64d9f5a423550
MD5 0c6394ff4eecc488824b81b16bac2647
BLAKE2b-256 61fb8a50654fffd4b13927aec023d88c5b2bffed73fc4bc2fdd1066937e58c30

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