Skip to content

Commit aff26a8

Browse files
committed
report: allow overriding pdf theme, fonts and logo
Let downstream projects brand the PDF report by passing --theme, --fontsdir and --logo to the pdf format, falling back to the bundled 9pm defaults when not given.
1 parent f72ba06 commit aff26a8

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

report.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,20 @@ def _write_tree(self, data, depth):
326326
class PDFReporter(BaseReporter):
327327
"""Generates PDF reports via AsciiDoc conversion."""
328328

329+
def __init__(self, json_data, theme=None, fontsdir=None, logo=None):
330+
"""Initialize with optional asciidoctor-pdf theme/fonts/logo overrides.
331+
332+
When an override is None the bundled 9pm default is used. Callers
333+
(e.g. a downstream project's Makefile) can supply their own theme,
334+
fonts directory and title-page logo to brand the report.
335+
"""
336+
super().__init__(json_data)
337+
script_dir = os.path.dirname(os.path.abspath(__file__))
338+
self.theme = theme or os.path.join(script_dir, 'report', 'theme.yml')
339+
self.fontsdir = fontsdir or os.path.join(script_dir, 'report', 'fonts')
340+
self.logo = logo or (
341+
f'{os.path.join(script_dir, "logo.png")}[top=40%, align=right, pdfwidth=8cm]')
342+
329343
def get_filename(self):
330344
"""Get the output filename for this report type."""
331345
return 'report.pdf'
@@ -346,11 +360,10 @@ def write(self, json_file_path, output_filename=None):
346360
temp_adoc_path = temp_adoc.name
347361

348362
try:
349-
script_dir = os.path.dirname(os.path.abspath(__file__))
350363
cmd = ['asciidoctor-pdf',
351-
'--theme', os.path.join(script_dir, 'report', 'theme.yml'),
352-
'-a', f'pdf-fontsdir={os.path.join(script_dir, "report", "fonts")}',
353-
'-a', f'logo=image:{os.path.join(script_dir, "logo.png")}[top=40%, align=right, pdfwidth=8cm]',
364+
'--theme', self.theme,
365+
'-a', f'pdf-fontsdir={self.fontsdir}',
366+
'-a', f'logo=image:{self.logo}',
354367
'-o', pdf_filename, temp_adoc_path]
355368

356369
result = subprocess.run(cmd, capture_output=True, text=True)
@@ -391,6 +404,13 @@ def main():
391404
help='Report format to generate')
392405
parser.add_argument('json_file', nargs='?', help='Path to the JSON result file (auto-find if omitted)')
393406
parser.add_argument('-o', '--output', help='Output filename (auto-generate if omitted)')
407+
parser.add_argument('--theme', help='asciidoctor-pdf theme file (pdf format only)')
408+
parser.add_argument('--fontsdir', help='asciidoctor-pdf fonts directory (pdf format only)')
409+
parser.add_argument('--logo',
410+
help='Title-page logo, asciidoctor image spec without the '
411+
'leading "image:", e.g. '
412+
'"/path/logo.png[top=40%%, align=right, pdfwidth=8cm]" '
413+
'(pdf format only)')
394414

395415
args = parser.parse_args()
396416

@@ -410,7 +430,8 @@ def main():
410430
elif args.format == 'asciidoc':
411431
AsciiDocReporter(json_data).write(args.json_file, args.output)
412432
elif args.format == 'pdf':
413-
PDFReporter(json_data).write(args.json_file, args.output)
433+
PDFReporter(json_data, theme=args.theme, fontsdir=args.fontsdir,
434+
logo=args.logo).write(args.json_file, args.output)
414435
except Exception as e:
415436
print(f"Error generating report: {e}", file=sys.stderr)
416437
sys.exit(1)

0 commit comments

Comments
 (0)