summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2023-03-01 17:38:55 +0100
committerMartin Vilcans <martin@librador.com>2023-03-01 17:43:41 +0100
commitdd8f8428a1cbf34761ca48bdfe7c38f30f67bd7b (patch)
tree7135eb4ea9daa418408b933d71de6d0ad69d4cbc
parent3d9dbb4ac06f9b4b5316c2bf2b26c6caf6ef83c9 (diff)
Add support for choosing letter or A4 page size.page-size
Now A4 output works the output doesn't look good. The top margin is too big.
-rw-r--r--screenplain/export/pdf.py20
-rw-r--r--screenplain/main.py5
2 files changed, 17 insertions, 8 deletions
diff --git a/screenplain/export/pdf.py b/screenplain/export/pdf.py
index 5c15de5..d6569ff 100644
--- a/screenplain/export/pdf.py
+++ b/screenplain/export/pdf.py
@@ -33,6 +33,11 @@ def create_default_settings():
return Settings()
+def get_page_size(name: str):
+ """Get the page size with the given name, e.g. 'a4' or 'legal'"""
+ return getattr(pagesizes, name.upper())
+
+
class Settings:
# General styles
default_style: ParagraphStyle
@@ -62,8 +67,7 @@ class Settings:
frame_height: float
frame_width: float
- page_width: float
- page_height: float
+ page_size: (float, float)
def __init__(
self,
@@ -84,16 +88,16 @@ class Settings:
self.characters_per_line = characters_per_line
self.frame_height = self.line_height * self.lines_per_page
self.frame_width = self.characters_per_line * self.character_width
- [self.page_width, self.page_height] = page_size
+ self.page_size = page_size
self.left_margin = 1.5 * inch
- self.right_margin = self.page_width - (
+ self.right_margin = self.page_size[0] - (
self.left_margin + self.frame_width
)
self.top_margin = 1 * inch
- self.bottom_margin = self.page_height - (
+ self.bottom_margin = self.page_size[1] - (
self.top_margin + self.frame_height
)
- self.title_frame_width = self.page_width - (
+ self.title_frame_width = self.page_size[0] - (
self.left_margin + self.left_margin
)
self.strong_slugs = strong_slugs
@@ -204,7 +208,7 @@ class DocTemplate(BaseDocTemplate):
if page >= 2:
self.canv.drawRightString(
self.settings.left_margin + self.settings.frame_width,
- self.settings.page_height - 42,
+ self.settings.page_size[1] - 42,
'%s.' % page
)
self._handle_pageBegin()
@@ -365,7 +369,7 @@ def to_pdf(
doc = template_constructor(
output_filename,
- pagesize=(settings.page_width, settings.page_height),
+ pagesize=settings.page_size,
settings=settings,
has_title_page=has_title_page
)
diff --git a/screenplain/main.py b/screenplain/main.py
index f3a1dce..f2c33a2 100644
--- a/screenplain/main.py
+++ b/screenplain/main.py
@@ -41,6 +41,10 @@ def main(args):
)
)
parser.add_option(
+ '--page-size', choices=('letter', 'a4'), default='letter',
+ help='Page size for PDF output: letter or a4'
+ )
+ parser.add_option(
'--bare',
action='store_true',
dest='bare',
@@ -127,6 +131,7 @@ def main(args):
from screenplain.export import pdf
settings = pdf.create_default_settings()
settings.strong_slugs = options.strong
+ settings.page_size = pdf.get_page_size(options.page_size)
pdf.to_pdf(screenplay, output, settings=settings)
finally:
if output_file: