Coding project for daily task automation utilizing Python and the pypdf library.
When exporting PDFs from Google Docs, the files often retain the default title metadata ending in " - Google Docs". This can appear unpolished, especially when sharing via Google Drive, where the title metadata is visible to recipients.
To simplify this, I developed a Python script using the pypdf library to overwrite the PDF title metadata with a clean, custom name. The script reads the original file, updates the metadata and safely replaces the file, making it ideal for refining portfolios or official documents.
Code
# Importing libraries
import os
from pypdf import PdfReader, PdfWriter
# Variables
file_name = "Portfolio"
# Base path
base_path = f"G:\\Meu Drive\\04_Professional\\02_CV\\06_2025\\{file_name}"
# File paths
input_path = f"{base_path}\\{file_name}.pdf"
temp_path = f"{base_path}\\{file_name}_temp.pdf"
# Overwrite PDF metadata
reader = PdfReader(input_path)
writer = PdfWriter()
for page in reader.pages:
writer.add_page(page)
writer.add_metadata({
"/Title": f"{file_name}"
})
with open(temp_path, "wb") as f:
writer.write(f)
os.replace(temp_path, input_path)
print("PDF metadata overwritten successfully.")