Showing posts with label Python-APIs. Show all posts
Showing posts with label Python-APIs. Show all posts

Saturday, March 7, 2015

PDFCrowd and its HTML to PDF API (for Python and other languages)

By Vasudev Ram


PDFcrowd is a web service that I came across recently. It allows users to convert HTML content to PDF. This can be done both via the PDFcrowd site - by entering either the content or the URL of an HTML page to be converted to PDF - or via the PDFcrowd API, which has support for multiple programming languages, including for Python. I tried multiple approaches, and all worked fairly well.

A slightly modified version of a simple PDFcrowd API example from their site, is shown below.

# Demo program to show how to use the PDFcrowd API
# to convert HTML content to PDF.
# Author: Vasudev Ram - www.dancingbison.com

import pdfcrowd

try:
    # create an API client instance
    # Dummy credentials used; to actually run the program, enter your own.
    client = pdfcrowd.Client("user_name", "api_key")
    client.setAuthor('author_name')
    # Dummy credentials used; to actually run the program, enter your own.
    client.setUserPassword('user_password')

    # Convert a web page and store the generated PDF in a file.
    pdf = client.convertURI('http://www.dancingbison.com')
    with open('dancingbison.pdf', 'wb') as output_file:
        output_file.write(pdf)
    
    # Convert a web page and store the generated PDF in a file.
    pdf = client.convertURI('http://jugad2.blogspot.in/p/about-vasudev-ram.html')
    with open('jugad2-about-vasudevram.pdf', 'wb') as output_file:
        output_file.write(pdf)

    # convert an HTML string and save the result to a file
    output_file = open('html.pdf', 'wb')
    html = "My Small HTML File"
    client.convertHtml(html, output_file)
    output_file.close()

except pdfcrowd.Error, why:
    print 'Failed:', why
I used three calls to the API. For the first two calls, the inputs were: 1) my web site, 2) the about page of my blog.

Screenshots of the results of those two calls are below. You can see that they correspond closely to the originals.

Screenshot of generated PDF of dancingbison.com site



Screenshot of generated PDF of About Vasudev Ram page on jugad2.blogspot.com blog



- Vasudev Ram - Online Python training and programming

Dancing Bison Enterprises

Signup to hear about new Python or PDF related products created by me.

Posts about Python  Posts about xtopdf

Contact Page

Wednesday, October 8, 2014

New: The Hacker News API (with Python support)


By Vasudev Ram


Hacker News (HN), a.k.a. news.ycombinator.com has introduced an API for their site - the Hacker News API.

Hacker News is a tech and other news site popular with developers, entrepreneurs and others, which was set up by Paul Graham, founder of Y Combinator, a startup incubator / accelerator.

HN thread about the Hacker News API.

The Hacker News API on Github.

The API has been built in partnership with Firebase, a startup that is a graduate of the Y Combinator incubator / accelerator.

There is a Firebase REST API available to access the Hacker News data.

They mention two Python wrappers for the Firebase REST API:

python-firebase, Python interface to the Firebase REST API, by Özgür Vatansever

and another one, also called

python-firebase, Python wrapper for the Firebase API by Michael Huynh.

The news about the Hacker News API was posted just today.

I'll experiment over some days with the API and then may write another post about using it from Python.

- Vasudev Ram - Python training and consulting - Dancing Bison Enterprises

Click here to signup for email notifications about new products and services from Vasudev Ram.

Contact Page