From 906b12fe5445f828f52f6a0397ea565b30fd4e19 Mon Sep 17 00:00:00 2001 From: Peter Nagel Date: Wed, 10 Sep 2014 14:49:38 -0700 Subject: [PATCH] added example to create a pdf --- README.md | 6 ++++++ examples/create_pdf.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 examples/create_pdf.py diff --git a/README.md b/README.md index 2f0a6dc..07cd83b 100644 --- a/README.md +++ b/README.md @@ -518,3 +518,9 @@ lob.Check.create( memo = 'Services Rendered' ) ``` + +## Creating a PDF + +We recommed using [python-pdfkit](https://github.com/JazzCore/python-pdfkit) to generate PDFs using HTML input. This depends on having [wkhtmltopdf](http://wkhtmltopdf.org/) installed. + +You can find an example [here](examples/create_pdf.py) diff --git a/examples/create_pdf.py b/examples/create_pdf.py new file mode 100644 index 0000000..3616cd3 --- /dev/null +++ b/examples/create_pdf.py @@ -0,0 +1,30 @@ +import lob +import pdfkit + +lob.api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc" # Replace this API key with your own. + +body = """ + + +
+ +

Print with Lob

+
+ + +""" + +pdfkit.from_string(body, 'out.pdf', { + 'page-height': '6.25in', + 'page-width': '4.25in', + 'quiet': '' +}) + +example_object = lob.Object.create( + name='Example Object', + file=open('out.pdf', 'rb'), + setting_id=201, + full_bleed=1 +) + +print "Check out the created PDF here: " + example_object.url