Saturday, February 15, 2014

Create PDF calendars with xtopdf

By Vasudev Ram

As I keep working on xtopdf, my Python toolkit for PDF creation, every now and then I get ideas for new applications that use xtopdf.

Today I thought of using xtopdf with Python to generate PDF calendars.

Here is a program, CalendarToPDF, which shows how to do that:
Author: Vasudev Ram -
Copyright 2014 Vasudev Ram
This is a demo program to generate PDF calendars.

import sys
import traceback
from debug1 import debug1
import calendar
from PDFWriter import PDFWriter

    cal = calendar.TextCalendar(calendar.SUNDAY)
    cal_str = cal.formatmonth(2014, 02, 4, 2)
    cal_lines = cal_str.split("\n")
    pw = PDFWriter("Calendar-February-2014.pdf")
    pw.setFont("Courier", 10)
    pw.setHeader("Calendar for February 2014")
    pw.setFooter("Generated by xtopdf:")
    for line in cal_lines:
        if line != "":
    print "Calendar generated."
except Exception as e:

This example program generates a simple PDF text calendar for February 2014. Run it with:


This is a screenshot of the resulting PDF output:


Read posts about xtopdf on my blog.

- Vasudev Ram - Python training and consulting

Contact Page

No comments: