Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion screenplain/export/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sys
import os
import re

from reportlab import platypus
from reportlab.lib import colors, pagesizes
Expand Down Expand Up @@ -509,6 +510,34 @@ def add_lines(story, attribute, style, space_before=0):
return story


def pdf_metadata(screenplay):
title_lines = screenplay.get_rich_attribute("Title")
author_lines = [
*screenplay.get_rich_attribute("Author"),
*screenplay.get_rich_attribute("Authors"),
]
subject_lines = screenplay.get_rich_attribute("Subject")
keywords_lines = screenplay.get_rich_attribute("Keywords")

lang_lines = [
*screenplay.get_rich_attribute("Lang"),
*screenplay.get_rich_attribute("Language"),
]

return {
"title": ' '.join([str(line) for line in title_lines]) or None,
"subject": ' '.join([str(line) for line in subject_lines]) or None,
"author": ', '.join([str(line) for line in author_lines]) or None,
"keywords": [
word.strip()
for line in keywords_lines
for word in re.split('[,;/]', str(line))
if word.strip()
],
"lang": ' '.join([str(line) for line in lang_lines]) or None,
}


def to_pdf(
screenplay, output_filename,
template_constructor=DocTemplate,
Expand Down Expand Up @@ -540,10 +569,12 @@ def to_pdf(
# Ignore unknown types
pass

meta = pdf_metadata(screenplay)
doc = template_constructor(
output_filename,
pagesize=(settings.page_width, settings.page_height),
settings=settings,
has_title_page=has_title_page
has_title_page=has_title_page,
**meta,
)
doc.build(story)
Loading