Few edits

This commit is contained in:
Mara Karagianni 2021-04-13 19:40:43 +03:00
parent 83a5377890
commit de9b4651c2
3 changed files with 24 additions and 29 deletions

Binary file not shown.

View file

@ -2,7 +2,7 @@ from fpdf import FPDF
"""
A script for generating A5 size pdf zines
with a text-file input, under development,
GPL3 Licence, Mara Karagianni 22 March 2021
GPL3 Licence, Mara Karagianni March 2021
"""
# Variables

View file

@ -2,7 +2,7 @@ from fpdf import FPDF
"""
A script for generating A5 size pdf zines
with a text-file input, under development,
GPL3 Licence, Mara Karagianni 22 March 2021
GPL3 Licence, Mara Karagianni April 2021
"""
# Variables
@ -41,31 +41,14 @@ class Zine(FPDF):
self.set_xy(left_margin, top_margin)
print('NEW SIGNATURE')
def move_to_page_right(self, top_margin, left_max_margin=160, right_margin=20):
def move_to_page_right(self, top_margin, left_max_margin, right_margin):
print('*****')
print("BOTTOM OF PAGE, height is {}".format(self.get_y()))
print('*****')
self.set_margins(top_margin, left_max_margin, right_margin)
self.set_xy(left_max_margin, top_margin)
print("inside move_to_page_righ function, X IS {}".format(self.get_x()))
def position_img(self, img_filename, img_x, img_y, img_len):
self.image(img_filename, img_x, img_y, img_len)
def create_pages(self, filename, max_height, left_margin,
left_max_margin, img_len, top_margin, right_margin,
cell_width, cell_height):
index = 0
text = open(filename).readlines()
for line in text:
if index > len(text)-1:
break
try:
# check if we have an image
if "<img>" in line:
img_filename = line.split("<img>")[1]
def position_img(self, img_filename, img_x, img_y):
import subprocess
img_size = subprocess.run(
["identify", "-format",
@ -79,14 +62,26 @@ class Zine(FPDF):
img_width_mm = float(img_width_inches) * float(24.5)
previous_y = self.get_y()
self.position_img(img_filename,
self.get_x(), self.get_y(), img_width_mm)
#self.get_x(), self.get_y(), img_width_mm)
self.image(img_filename, img_x, img_y, img_width_mm)
# use identify to get the image height and move page height
# to bottom of the image
self.set_xy(self.get_x(), previous_y+img_height_mm)
def create_pages(self, filename, max_height, left_margin,
left_max_margin, top_margin, right_margin,
cell_width, cell_height):
index = 0
text = open(filename).readlines()
for line in text:
if index > len(text)-1:
break
try:
# check if we have an image
if "<img>" in line:
img_filename = line.split("<img>")[1]
self.position_img(img_filename, self.get_x(), self.get_y())
# Ommit the image line from writing it as text input
index += 1
@ -126,7 +121,7 @@ title = 'Python Mailman Migrations'
zine.set_font(text_font, size=text_font_size)
zine.create_pages(filename, max_height, left_margin, left_max_margin, img_len,
zine.create_pages(filename, max_height, left_margin, left_max_margin,
top_margin, right_margin, cell_width, cell_height)
zine.output('latest_trial.pdf')