Python · Test Data

Generate Batches of Placeholder PDFs and Images for Upload Testing

TL;DR

Set a name, a count and an icon folder; the scripts produce numbered test documents (PDF via Word, or PNG/JPG via Pillow) for testing upload forms and workflows.

Updated 1 min read

Pythonpython-docxPillowcomtypes

Download source (ZIP)v1.0.0 · 4 files · 12 KB · MIT license

Abstract

The problem

Testing upload forms and document workflows needs dozens of distinct sample files, and creating them by hand is slow.

The solution

Two scripts generate N numbered files: one builds Word documents and converts them to PDF through Microsoft Word, the other draws PNG/JPG images with Pillow. Each shows a heading, date, time and a centred icon cycled from a folder.

The result

Any number of unique, clearly labelled test files in seconds.

Input & Output

Input
  • An icon/image folder
  • base_name, count and output folder set in the script
Output
  • {base_name}_{n}.pdf (Word route) or .png/.jpg (image route)
Optional output
  • Intermediate .docx files (delete line is commented out)

System Diagram

How It Works

Circular image selection

Icons are taken in sorted order and wrap around, starting from image_start_index.

Two output routes

Word-to-PDF via python-docx and Word automation, or PNG/JPG via Pillow.

Configurable layout

Heading size, image height, canvas size and formats are all parameters.

Timestamped content

Each file shows the generation date and time so test files are easy to tell apart.

Configuration

OptionPurpose
base_name / countFile name prefix and how many files to create.
image_folder / output_dirWhere icons are read from and results are written.
image_start_index1-based start position in the sorted icon list.
output_formatsImage route only: ('png', 'jpg').

How to Run

Install
pip install -r requirements.txt
PDF route (Windows + Microsoft Word)
python word_to_pdf_batch.py
Image route
python image_batch.py

Source Code

word_to_pdf_batch.pypreview
import os
import sys
from datetime import datetime
from docx import Document
from docx.shared import Pt, Inches
from docx.enum.text import WD_ALIGN_PARAGRAPH
import comtypes.client
import logging

# Setup logging
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')

def create_batch_word_pdfs(
    base_name,
    count,
    image_folder,
    output_dir=".",
    heading_font_size=24,
    image_height_in_inches=2.0,
    image_start_index=1  # 1-based index
):
    """
    Generates 'count' PDFs with:
      - Filename: {base_name}_{i}.pdf
      - Heading: {base_name}_{i}
      - Date/Time with labels
      - Image from sorted list in image_folder (circular if needed)
    
    Parameters:
      base_name (str): e.g., "Sample-1_Document"
      count (int): Number of PDFs to generate (e.g., 5)
      image_folder (str): Folder containing images
      output_dir (str): Output directory
      image_start_index (int): 1-based start index in sorted image list
    """
    try:
        # Validate inputs
        if count < 1:
            raise ValueError("Count must be at least 1.")
        if image_start_index < 1:
            raise ValueError("image_start_index must be >= 1.")

        output_dir = os.path.abspath(output_dir)
        os.makedirs(output_dir, exist_ok=True)

        # Get and sort images
        if not os.path.isdir(image_folder):
            raise FileNotFoundError(f"Image folder not found: {image_folder}")
        
        valid_ext = ('.png', '.jpg', '.jpeg', '.bmp', '.gif', '.tiff')
        image_files = sorted([
            f for f in os.listdir(image_folder)
            if f.lower().endswith(valid_ext)
        ])
        
        if not image_files:
            raise FileNotFoundError(f"No valid images found in: {image_folder}")
        
        total_images = len(image_files)
        logging.info(f"Found {total_images} images (sorted alphabetically).")

… 88 more lines - loading the full file

Download source (ZIP)v1.0.0 · 4 files · 12 KB · MIT license

Released under the MIT license. Free to use, modify and share.

Impact & Benefits

Fast QA data for upload and workflow testing.
Reproducible, numbered, labelled files.
No design work needed.

Frequently Asked Questions

How do I generate many PDF files with Python?

word_to_pdf_batch.py builds a .docx per file with python-docx and exports it to PDF through Word automation (Windows).

Can I make PNG or JPG test images instead?

Yes. image_batch.py draws the same layout with Pillow and saves PNG and/or JPG.

Is it meant for real documents?

No. It is for placeholder test data only.

Related

© 2026 Thuyavan Sivarasa. Script code is MIT licensed.