Welcome, guest | Sign In | My Account | Store | Cart

This recipe shows how to create simple text calendars as PDF using xtopdf, a Python toolkit for PDF creation.

Python, 29 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
CalendarToPDF.py
Author: Vasudev Ram - www.dancingbison.com
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

try:
    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: http://bit.ly/xtopdf")
    for line in cal_lines:
        if line != "":
            pw.writeLine(line)
    pw.close()
    print "Calendar generated."
except Exception as e:
    traceback.print_exc()
    sys.exit(1)

You may want to do this task to create simple text-only calendars as PDF files for personal or organizational use.

More details and an output sample are available at this blog post:

http://jugad2.blogspot.in/2014/02/create-pdf-calendars-with-xtopdf.html