Script to Add a Title Page to PDFs The article presents a Python script that automatically adds a title page to PDF documents, specifically designed for use with PDFs generated from ChatGPT conversations. The script uses the `fpdf2` library to create a temporary title page with a title and optional subtitle, then merges it with the original PDF using the `pdftk` command-line tool. It includes a command-line interface for specifying the input PDF, output file, title text, and an optional subtitle. Script to Add a Title Page to PDFs I've recently found myself frequently using the "ChatGPT to PDF" Chrome extension to convert ChatGPT conversations into PDF documents. The Deep Research discussions in particular contain valuable info worth preserving in ebook format. However they lack proper title pages. So here's a quick Python script to add a simple title page to PDF documents. title4pdf.py : import os import tempfile import subprocess from fpdf import FPDF def add title page input pdf, output pdf, title, subtitle=None : Create temporary title page PDF with tempfile.NamedTemporaryFile suffix=".pdf", delete=False as temp pdf: Create title page with fpdf2 pdf = FPDF pdf.add page pdf.set font "Helvetica", "B", 24 Calculate centered position for title pdf.cell 0, 40, text="", new x="LMARGIN", new y="NEXT" Add vertical spacing pdf.multi cell 0, 10, text=title, align="C" Add subtitle if provided if subtitle: pdf.set font "Helvetica", "", 16 pdf.ln 10 Space between title and subtitle pdf.multi cell 0, 10, text=subtitle, align="C" Save temporary title page pdf.output temp pdf.name try: Merge PDFs using pdftk subprocess.run "pdftk", temp pdf.name, input pdf, "cat", "output", output pdf , check=True finally: Clean up temporary file os.remove temp pdf.name if name == " main ": import argparse parser = argparse.ArgumentParser description="Add title page to PDF" parser.add argument "input", help="Input PDF file" parser.add argument "title", help="Title text" parser.add argument "output", help="Output PDF file" parser.add argument "--subtitle", help="Subtitle text optional " args = parser.parse args add title page args.input, args.output, args.title, args.subtitle