Injecting a Branded Header into PDFs at Scale

Adds a website address and phone number to PDF files in bulk.

eCommerce businesses often host a large amount of PDF files to accompany products and ranges. While these files can rank well on search engines and attract users, they often lead visitors away from the main website. This situation can result in potential customers finding what they need in the PDF and, sometimes, making their purchases elsewhere.

Noticing this, I saw a practical opportunity to make these PDFs work harder.

The idea is simple: embed a branded header in each PDF. This header would include a phone number and website address, subtly encouraging users to engage directly with your business.

For details on how to implement this, including features, settings, and step-by-step instructions, keep reading. Or, if you’re ready to start right away, go ahead and download the script.

The Premise

The idea is to download all PDF files from the CMS, inject a telephone number and a clickable URL to the company’s website.

Whilst links in PDFs are unlikely to move the needle for SEO it’s still an excellent branding and conversion exercise, potentially driving traffic and phone calls, especially at scale.

By default the script just adds a banner at the top of the first page including a clickable link and a telephone number.

The source code is also a good jumping off point if you wanted to modify it.

Some ideas for modification include:

  • Displaying the banner at the footer of every page.
  • Adding a company logo
  • Adding a call to action

For my purposes, simply adding a link and phone number was enough, so I’ve kept the script quite fairly minimal.

Website link and telephone number automatically injected into a PDF file.
Website link and telephone number automatically injected into a PDF file.

Running the Script

Some basic knowledge is required to get started, but it’s not too difficult to get started.

  1. Download the script from my github
  2. Install the requirements file
  3. Download all PDFs from the server and place them in a folder, using the example in the script as a guide.
  4. Experiment with the customisation options until you have a good fit for your branding
  5. Upload the new PDF files overwriting the old ones*.

*I strongly recommend creating a backup before overwriting on the server. The script will not overwrite the original files, but you can never be too careful!

Features

A branded SONY TV PDF File
A branded SONY TV PDF File

Branding: Adds a banner to the top of all PDF files hosted on your site including a clickable link and telephone number.

Fonts: Use any font your like, making it easy to align with your brand’s identity.

Colours: The script supports text and header colour customisation. Simply grab the hex codes to align with your branding, and you’re all set!

Header Size: The script offers a simple way to adjust the size of the header on the page. Perfect for getting the look and feel just right.

Folder Structure Efficiency This script will process files and folders recursively and replicate the output. This means you can simply dump the current media folder(s) from your CMS, and the script will process all files and subfolders. It will then save the new files in exactly the same structure so they can be uploaded again with the new branding. It also preserves the original files.

Text Sizing and Positioning The script automatically adjusts the text size and position based on the PDF’s dimensions, ensuring a consistent look across different documents.

Subtle Branding Your brand elements are added to the top of each page without altering the existing content, maintaining the integrity of the original document.

Unique File Naming

Suffixes & Dates: The script can append suffixes and the current date to filenames, helping to distinguish between new and old files easily.

Configuration Options

Configuration Description Code
Custom Font Path (Optional) Points to the custom font file for PDF headers. FONT_PATH = "/python_scripts/pdf_branding/custom_fonts/Roboto-Bold.ttf"
Input Directory Directory with original PDF files to modify. INPUT_DIR = "/python_scripts/pdf_branding/input"
Output Directory Where the script saves modified PDF files. OUTPUT_DIR = "/python_scripts/pdf_branding/output"
Phone Number Phone number for the PDF header. PHONE_NUMBER = "01234 567 890"
Website URL Website URL for the PDF header. WEBSITE = "www.acme.com"
Filename Suffix Suffix for modified PDF filenames. SUFFIX = "_acme_"
Header Space Height Height of space at PDF top for the header. SPACE_HEIGHT = 30
Header Text Font Font for the text in PDF header. TEXT_FONT = "Roboto-Bold"
Header Text Size Font size for the header text. TEXT_FONT_SIZE = 14
Text Color Color of the header text. TEXT_COLOR = HexColor("#FFFFFF")
Background Color Background color of the header. BACKGROUND_COLOR = HexColor("#D91800")
Append Suffix Flag Whether to append suffix to output filenames. APPEND_SUFFIX = False
Append Date Flag Whether to append current date to output filenames. APPEND_DATE = False

Contact Me

This script should be fairly straightforward for anyone to run with a little bit of Python knowledge.

That said, if you would like this script to be run as a managed service or modified to your requirements, please get in touch using the form provided.