pdfthat-client¶ ↑
This gem allows you to play nicely with pdfth.at
Overview¶ ↑
pdfTH.AT is a HTML to PDF rendering system that allows you to hand in HTML or a URL and have that rendered into a PDF. This can be done on a queue and posted back to your system, or rendered in real time and returned as base64 encoded data.
You’ll need a free account from pdfth.at to play along, log in and get your token to access the system.
Requirements¶ ↑
-
HTTParty >= 0.5.2
Installation¶ ↑
This library is intended to be installed as a Gem.
$ gem install pdfthat-client
You might need administrator privileges on your system to install it.
Getting Started¶ ↑
You’ll need an API token to use this gem, head over to pdfth.at to sign up for one, development accounts are free and can be used straight away.
Include the gem in your Gemfile, if you are running Rails
gem "pdfthat-client", :require => "pdfthat"
Include it like any other gem otherwise
require 'pdfthat'
If using rails, Initialise the library in a preinitializer
Pdfthat.configure do |pdf| pdf.token = "<token goes here>" end
Otherwise, initialise it before you use it.
By Default, the client will be talking to the pdfthat DEVELOPMENT api, to override this setting:
Pdfthat.configure do |pdf| pdf.token = "<token goes here>" pdf.production = true end
Usage¶ ↑
Using the pdfTHAT Queue for a URL
Pdfthat.create_document(:document => {:url => "http://google.com.au/"})
Using the pdfTHAT Queue for a URL with a postback
Pdfthat.create_document(:document => {:url => "http://google.com.au/", :postback_url => "http://exampl.com/documents/done"})
Using the pdfTHAT Queue for HTML
Pdfthat.create_document(:document => {:html_string => "<html><head><title>My Page</title></head><body><strong>This is my page</strong></body></html>"})
Using the pdfTHAT Queue for HTML with a postback
Pdfthat.create_document(:document => {:html_string => "<html><head><title>My Page</title></head><body><strong>This is my page</strong></body></html>", :postback_url => "http://exampl.com/documents/done"})
Using pdfTHAT in real-time for a URL
Pdfthat.create_document(:document => {:url => "http://google.com.au/",:wait_for_pdf => true})
Using pdfTHAT in real-time for HTML
Pdfthat.create_document(:document => {:url => "<html><head><title>My Page</title></head><body><strong>This is my page</strong></body></html>",:wait_for_pdf => true})
The results of these calls will be similar to:
{"s3_bucket"=>"bucket", "media_type"=>"screen", "created_at"=>"Mon Feb 22 00:30:56 UTC 2010", "upload_time"=>nil, "upload_results"=>nil, "error_messages"=>[], "uuid"=>"76f93970-0177-012d-4131-0026b0d759a2", "updated_at"=>"Mon Feb 22 00:30:56 UTC 2010", "postback_url"=>nil, "url"=>"http://google.com.au/", "render_time"=>nil, "storage_url"=> "http://s3.amazonaws.com/bucket/76f93970-0177-012d-4131-0026b0d759a2.pdf", "return_pdf"=>false, "id"=>202, "successful"=>true, "user_id"=>1, "styles"=>nil, "render_results"=>nil, "media"=>"screen", "development"=>false, "workflow_state"=>"new", "wait_for_pdf"=>false, "postback_time"=>nil, "html_string"=>nil, "postback_results"=>nil}
To query the document at a later date, use:
Pdfthat.get_document(:id => "76f93970-0177-012d-4131-0026b0d759a2")
It’ll return the same result as the create_document method.
NOTE: If you are using the wait_for_pdf method, you will also get an attribute called “base64_pdf_data” that includes the PDF file encoded in base64. This is only available in the results of the create method, to access the document after that, use the storage_url attribute
Note on Patches/Pull Requests¶ ↑
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright¶ ↑
Copyright © 2010 mattallen. See LICENSE for details.