[ Home | Feed | Twitter | Vector Art | Ascii Art | Tutorials ]

Convert HTML Slides to PDF

Mon, 12 Jan 2015

In the December Chennaipy meetup, I did my presentation using asciidoc and dzslides. Though I liked the output, with dzslides' CSS it was not possible to print the slides to PDF. I was looking for ways to convert the slides to PDF, so that I can upload them to slideshare.

After reading through various projects on the Internet, it occurred to me that this can be easily done using selenium. The following Python script opens up the slides, and saves a screenshot of every slide to a separate image file. The slides are advanced by sending the SPACE key stroke, to the browser.

from selenium import webdriver

browser = webdriver.Firefox()
browser.set_window_size(1600, 1200)

for i in range(40):
    browser.save_screenshot("frame%02d.png" % i)
    section = browser.find_element_by_tag_name("section")
    section.send_keys(" ")


The series of screenshots can then be converted to PDF using the following command.

$ convert frame*.png slides.pdf

Well the result is not perfect, for example, the text is no longer selectable, in the resulting PDF, and hyperlinks do not work. But I atleast have something, that can be uploaded to slideshare.

The asciidoc source files of the presentation are available at https://github.com/bravegnu/breaking-free-with-rope The resulting PDF is available at http://www.slideshare.net/VijayKumarBagavathSi/breaking-free-with-rope

Permalink | Add Comment | Share: Twitter, Facebook, Buzz, ... | Tags: python

blog comments powered by Disqus

Powered by Python | Made with PyBlosxom | Valid XHTML 1.1 | Best Viewed With Any Browser | Icon Credits | CC-BY-SA