cd /news/developer-tools/script-to-add-a-title-page-to-pdfs · home topics developer-tools article
[ARTICLE · art-11770] src=nand2mario.github.io ↗ pub= topic=developer-tools verified=true sentiment=· neutral

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.

read1 min views23 publishedMar 10, 2025

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):
with tempfile.NamedTemporaryFile(suffix=".pdf", delete=False) as temp_pdf:
pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", "B", 24)
pdf.cell(0, 40, text="", new_x="LMARGIN", new_y="NEXT") # Add vertical spacing
pdf.multi_cell(0, 10, text=title, align="C")
if subtitle:
pdf.set_font("Helvetica", "", 16)

pdf.ln(10) # Space between title and subtitle

pdf.multi_cell(0, 10, text=subtitle, align="C")
pdf.output(temp_pdf.name)

try: subprocess.run([ "pdftk",

temp_pdf.name,
input_pdf,

"cat", "output", output_pdf ], check=True) finally:

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)

── more in #developer-tools 4 stories · sorted by recency
── more on @chatgpt 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/script-to-add-a-titl…] indexed:0 read:1min 2025-03-10 ·