pdfservice 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gems ADDED
@@ -0,0 +1,2 @@
1
+ sinatra
2
+
data/README.markdown ADDED
@@ -0,0 +1,25 @@
1
+ # PDF Service
2
+
3
+ This is a simple Rack server that accepts web requests posting HTML to be converted into PDF. Uses the wkhtmltopdf binaries.
4
+
5
+
6
+ ## Instant installation and deploy
7
+
8
+ * Clone this: `git clone git://github.com/JackDanger/pdfservice.git`
9
+ * Signup for an account at Heroku ([better details here](http://github.com/sinatra/heroku-sinatra-app))
10
+ * push it to Heroku.com: `git push heroku master`
11
+
12
+
13
+ ## HowTo
14
+
15
+ Once the server is running you need to post a string of html to it and that string will
16
+ be rendered in WebKit and returned to you as a PDF document.
17
+
18
+ require 'pdfservice'
19
+ client = PdfService::Client.new 'http://my-pdfservice-app.heroku.com'
20
+ pdf_content = client.render '<html></html>'
21
+
22
+
23
+ Patches welcome, forks celebrated.
24
+
25
+ Copyright (c) 2010 [Jack Danger Canty](http://jåck.com). Released under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "pdfservice"
5
+ gem.summary = %Q{lightwight HTML-to-PDF server running on Heroku.com}
6
+ gem.description = %Q{Run your own html-to-pdf server for free on Heroku.com}
7
+ gem.email = "gitcommit@6brand.com"
8
+ gem.homepage = "http://github.com/JackDanger/pdfservice"
9
+ gem.authors = ["Jack Danger Canty"]
10
+ gem.add_dependency "sinatra", ">= 1.0.0"
11
+ gem.add_development_dependency "shoulda", ">= 0"
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
+ end
18
+
19
+
20
+
21
+ task :default => :test
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << '.'
26
+ test.pattern = 'test.rb'
27
+ test.verbose = true
28
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
@@ -0,0 +1,14 @@
1
+ credentials: &credentials
2
+ adapter: postgresql
3
+
4
+ development:
5
+ <<: *credentials
6
+ database: shawty_development
7
+
8
+ test:
9
+ <<: *credentials
10
+ database: shawty_test
11
+
12
+ staging:
13
+ <<: *credentials
14
+ database: shawty_staging
data/config.ru ADDED
@@ -0,0 +1,6 @@
1
+ require 'lib/pdf_service_server'
2
+
3
+ ## There is no need to set directories here anymore;
4
+ ## Just run the application
5
+
6
+ run Sinatra::Application
@@ -0,0 +1,3 @@
1
+ module PdfService
2
+ end
3
+ require 'pdf_service_client'
@@ -0,0 +1,29 @@
1
+ #
2
+ # HowTo:
3
+ #
4
+ # client = PdfService::Client.new 'http://my-pdfservice-app.com'
5
+ # pdf_content = client.render '<html></html>'
6
+ #
7
+ module PdfService
8
+ class Client
9
+ # @server: "http://myserver.com"
10
+ def initialize(server)
11
+ require 'net/http'
12
+ @server = URI.parse server
13
+ end
14
+
15
+ def render html
16
+ start do |http|
17
+ http.post '/', html
18
+ end
19
+ end
20
+
21
+ protected
22
+
23
+ def start
24
+ Net::HTTP.start @server.host, @server.port do |http|
25
+ yield http
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,66 @@
1
+ ## Resources
2
+ require 'rubygems'
3
+ gem 'sinatra', :version => '1.0'
4
+ require 'sinatra'
5
+
6
+
7
+
8
+ ## Application
9
+
10
+ get '/' do
11
+ %Q{
12
+ <body style='line-height: 1.8em; font-family: Archer, Museo, Helvetica, Georgia; font-size 25px; text-align: center; padding-top: 20%;'>
13
+ Post some HTML content to this server and receive a PDF document.
14
+ <pre style='font-family: Iconsolata, monospace;background-color:#EEE'>curl -X POST http://#{request.host}/ < some_file.html > some_file.pdf</pre>
15
+ <br />
16
+ Also, try <a href='http://github.com/JackDanger/pdfservice'>the official Ruby client</a>
17
+ </body
18
+ }
19
+ end
20
+
21
+ post '*' do
22
+ begin
23
+ content_type 'application/pdf'
24
+ convert request.env['rack.input'].read
25
+ rescue => error
26
+ puts error.inspect
27
+ status 400
28
+ end
29
+ end
30
+
31
+
32
+ ## HELPERS
33
+
34
+ def wkhtmltopdf
35
+ executable = `which wkhtmltopdf`.chomp
36
+
37
+ if '' == executable.to_s && RUBY_PLATFORM =~ /x86_64-linux/
38
+ executable = File.join File.dirname(__FILE__), '..', 'vendor', 'wkhtmltopdf-amd64-0.10.0_beta5-static-amd64'
39
+ end
40
+ executable
41
+ end
42
+
43
+ def command
44
+ [ wkhtmltopdf,
45
+ "--page-size letter",
46
+ "--margin-right 0",
47
+ "--margin-top 0",
48
+ "--margin-bottom 0",
49
+ "--disable-smart-shrinking",
50
+ "--encoding UTF-8",
51
+ "--margin-left 0",
52
+ "--quiet",
53
+ "-",
54
+ "-"
55
+ ]
56
+ end
57
+
58
+ def convert html
59
+ pdf = Kernel.open('|-', "w+")
60
+ exec command.join(' ') if pdf.nil?
61
+ pdf.puts html
62
+ pdf.close_write
63
+ result = pdf.gets nil
64
+ pdf.close_read
65
+ result
66
+ end
data/lib/pdfservice.rb ADDED
@@ -0,0 +1 @@
1
+ require 'pdf_service'
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{pdfservice}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jack Danger Canty"]
12
+ s.date = %q{2010-08-12}
13
+ s.description = %q{Run your own html-to-pdf server for free on Heroku.com}
14
+ s.email = %q{gitcommit@6brand.com}
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ ".gems",
20
+ "README.markdown",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "config.ru",
24
+ "config/database.yml",
25
+ "lib/pdf_service.rb",
26
+ "lib/pdf_service_client.rb",
27
+ "lib/pdf_service_server.rb",
28
+ "lib/pdfservice.rb",
29
+ "pdfservice.gemspec",
30
+ "test.rb",
31
+ "vendor/wkhtmltopdf-amd64-0.10.0_beta5-static-amd64"
32
+ ]
33
+ s.homepage = %q{http://github.com/JackDanger/pdfservice}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.6}
37
+ s.summary = %q{lightwight HTML-to-PDF server running on Heroku.com}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<sinatra>, [">= 1.0.0"])
45
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<sinatra>, [">= 1.0.0"])
48
+ s.add_dependency(%q<shoulda>, [">= 0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<sinatra>, [">= 1.0.0"])
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ end
54
+ end
55
+
data/test.rb ADDED
@@ -0,0 +1,42 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'shoulda'
6
+ require 'rack/test'
7
+ require 'pdf_service_server'
8
+
9
+ class PdfServiceTest < Test::Unit::TestCase
10
+ include Rack::Test::Methods
11
+
12
+ def app
13
+ Sinatra::Application
14
+ end
15
+
16
+ context "on GET to /" do
17
+ setup {
18
+ get '/'
19
+ }
20
+ should "return ok" do
21
+ assert last_response.ok?
22
+ end
23
+ should "have some kind of welcome" do
24
+ assert last_response.body =~ /curl/
25
+ end
26
+ end
27
+
28
+ context "on POST to /" do
29
+ setup {
30
+ post '/', '<html></html>'
31
+ }
32
+ should "return ok" do
33
+ assert last_response.ok?
34
+ end
35
+ should "return pdf content-type" do
36
+ assert last_response.ok?
37
+ end
38
+ should "return the PDF document" do
39
+ assert last_response.body =~ /^%PDF-1.4/
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdfservice
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jack Danger Canty
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-12 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sinatra
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: shoulda
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Run your own html-to-pdf server for free on Heroku.com
47
+ email: gitcommit@6brand.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - README.markdown
54
+ files:
55
+ - .gems
56
+ - README.markdown
57
+ - Rakefile
58
+ - VERSION
59
+ - config.ru
60
+ - config/database.yml
61
+ - lib/pdf_service.rb
62
+ - lib/pdf_service_client.rb
63
+ - lib/pdf_service_server.rb
64
+ - lib/pdfservice.rb
65
+ - pdfservice.gemspec
66
+ - test.rb
67
+ - vendor/wkhtmltopdf-amd64-0.10.0_beta5-static-amd64
68
+ has_rdoc: true
69
+ homepage: http://github.com/JackDanger/pdfservice
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --charset=UTF-8
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.6
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: lightwight HTML-to-PDF server running on Heroku.com
98
+ test_files: []
99
+