You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9.9 KiB

ASCII Canvas

(using Reportlab to export it as a PDF)

In [81]:
width = 75
height = 65
In [87]:
multipage = False
In [88]:
# Simple fill-up of a page, to set the reach of our canvas
lines = [] # All the lines will be stored here

for linenumber in range(height):
    line = 'x' * width
    lines.append(line)

print('\n'.join(lines))
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxx
In [ ]:
# Another variation
import random 

lines = []

txt = open('txt/language.txt', 'r').read()
words = txt.split()

for linenumber in range(height):
    word = random.choice(words)
    length_of_word = len(word)
    nr_of_words_fit_in_line = width / length_of_word
    line = word * int(nr_of_words_fit_in_line)
    lines.append(line)
    
print('\n'.join(lines))
In [90]:
# Same variation, but with multiple pages
import random 

multipage = True

lines = []
pages = []

txt = open('txt/language.txt', 'r').read()
words = txt.split()

for page in range(100):
    
    for linenumber in range(height):
        word = random.choice(words)
        length_of_word = len(word)
        nr_of_words_fit_in_line = width / length_of_word
        line = word * int(nr_of_words_fit_in_line)
        lines.append(line)
        
    # Add a page
    pages.append(lines)
    lines = []
    
In [ ]:
 
In [ ]:
 
In [ ]:
 

Exporting with Reportlab

In [91]:
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm

pagewidth = 210*mm
pageheight = 297*mm

c = Canvas("pdf/ASCII-canvas-to-PDF.pdf", pagesize=(pagewidth, pageheight), bottomup=0)
c.setFont('Courier', 12)

start_y = 10*mm # start position of the lines

y = start_y
lineheight = 4*mm

if multipage == True:
    for page in pages:
        for line in page:
            c.drawCentredString(pagewidth/2, y, line)
            y += lineheight
        c.showPage()
        y = start_y
else:
    for line in lines:
        c.drawCentredString(pagewidth/2, y, line)
        y += lineheight
    
c.save()
In [ ]: