Few edits
This commit is contained in:
parent
83a5377890
commit
de9b4651c2
3 changed files with 24 additions and 29 deletions
BIN
latest_trial.pdf
BIN
latest_trial.pdf
Binary file not shown.
|
|
@ -2,7 +2,7 @@ from fpdf import FPDF
|
||||||
"""
|
"""
|
||||||
A script for generating A5 size pdf zines
|
A script for generating A5 size pdf zines
|
||||||
with a text-file input, under development,
|
with a text-file input, under development,
|
||||||
GPL3 Licence, Mara Karagianni 22 March 2021
|
GPL3 Licence, Mara Karagianni March 2021
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from fpdf import FPDF
|
||||||
"""
|
"""
|
||||||
A script for generating A5 size pdf zines
|
A script for generating A5 size pdf zines
|
||||||
with a text-file input, under development,
|
with a text-file input, under development,
|
||||||
GPL3 Licence, Mara Karagianni 22 March 2021
|
GPL3 Licence, Mara Karagianni April 2021
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
|
@ -41,19 +41,34 @@ class Zine(FPDF):
|
||||||
self.set_xy(left_margin, top_margin)
|
self.set_xy(left_margin, top_margin)
|
||||||
print('NEW SIGNATURE')
|
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('*****')
|
||||||
print("BOTTOM OF PAGE, height is {}".format(self.get_y()))
|
print("BOTTOM OF PAGE, height is {}".format(self.get_y()))
|
||||||
print('*****')
|
print('*****')
|
||||||
self.set_margins(top_margin, left_max_margin, right_margin)
|
self.set_margins(top_margin, left_max_margin, right_margin)
|
||||||
self.set_xy(left_max_margin, top_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):
|
def position_img(self, img_filename, img_x, img_y):
|
||||||
self.image(img_filename, img_x, img_y, img_len)
|
import subprocess
|
||||||
|
img_size = subprocess.run(
|
||||||
|
["identify", "-format",
|
||||||
|
"%[fx:w/72] by %[fx:h/72] inches",
|
||||||
|
"./%s" % img_filename],
|
||||||
|
stdout=subprocess.PIPE, text=True)
|
||||||
|
|
||||||
|
img_height_inches = img_size.stdout.split(' ')[2]
|
||||||
|
img_width_inches = img_size.stdout.split(' ')[0]
|
||||||
|
img_height_mm = float(img_height_inches) * float(24.5)
|
||||||
|
img_width_mm = float(img_width_inches) * float(24.5)
|
||||||
|
|
||||||
|
previous_y = self.get_y()
|
||||||
|
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,
|
def create_pages(self, filename, max_height, left_margin,
|
||||||
left_max_margin, img_len, top_margin, right_margin,
|
left_max_margin, top_margin, right_margin,
|
||||||
cell_width, cell_height):
|
cell_width, cell_height):
|
||||||
index = 0
|
index = 0
|
||||||
text = open(filename).readlines()
|
text = open(filename).readlines()
|
||||||
|
|
@ -65,27 +80,7 @@ class Zine(FPDF):
|
||||||
# check if we have an image
|
# check if we have an image
|
||||||
if "<img>" in line:
|
if "<img>" in line:
|
||||||
img_filename = line.split("<img>")[1]
|
img_filename = line.split("<img>")[1]
|
||||||
|
self.position_img(img_filename, self.get_x(), self.get_y())
|
||||||
import subprocess
|
|
||||||
img_size = subprocess.run(
|
|
||||||
["identify", "-format",
|
|
||||||
"%[fx:w/72] by %[fx:h/72] inches",
|
|
||||||
"./%s" % img_filename],
|
|
||||||
stdout=subprocess.PIPE, text=True)
|
|
||||||
|
|
||||||
img_height_inches = img_size.stdout.split(' ')[2]
|
|
||||||
img_width_inches = img_size.stdout.split(' ')[0]
|
|
||||||
img_height_mm = float(img_height_inches) * float(24.5)
|
|
||||||
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)
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
# Ommit the image line from writing it as text input
|
# Ommit the image line from writing it as text input
|
||||||
index += 1
|
index += 1
|
||||||
|
|
@ -126,7 +121,7 @@ title = 'Python Mailman Migrations'
|
||||||
|
|
||||||
zine.set_font(text_font, size=text_font_size)
|
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)
|
top_margin, right_margin, cell_width, cell_height)
|
||||||
|
|
||||||
zine.output('latest_trial.pdf')
|
zine.output('latest_trial.pdf')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue