README.md in pdfkit-0.8.2 vs README.md in pdfkit-0.8.3
- old
+ new
@@ -41,12 +41,26 @@
# Add any kind of option through meta tags
PDFKit.new('<html><head><meta name="pdfkit-page_size" content="Letter"')
PDFKit.new('<html><head><meta name="pdfkit-cookie cookie_name1" content="cookie_value1"')
PDFKit.new('<html><head><meta name="pdfkit-cookie cookie_name2" content="cookie_value2"')
```
+
+### Resolving relative URLs and protocols
+
+If the source HTML has relative URLs (`/images/cat.png`) or
+[protocols](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#prurl)
+(`//example.com/site.css`) that need to be resolved, you can pass `:root_url`
+and `:protocol` options to PDFKit:
+
+```ruby
+PDFKit.new(html, root_url: 'http://mysite.com/').to_file
+# or:
+PDFKit.new(html, protocol: 'https').to_file
+```
+
### Using cookies in scraping
-If you want to pass a cookie to cookie to pdfkit to scrape a website, you can
+If you want to pass a cookie to cookie to pdfkit to scrape a website, you can
pass it in a hash:
```ruby
kit = PDFKit.new(url, cookie: {cookie_name: :cookie_value})
kit = PDFKit.new(url, [:cookie, :cookie_name1] => :cookie_val1, [:cookie, :cookie_name2] => :cookie_val2)
```
@@ -60,10 +74,11 @@
:page_size => 'Legal',
:print_media_type => true
}
# Use only if your external hostname is unavailable on the server.
config.root_url = "http://localhost"
+ config.protocol = 'http'
config.verbose = false
end
```
## Middleware
PDFKit comes with a middleware that allows users to get a PDF view of any page on your site by appending .pdf to the URL.
@@ -125,12 +140,12 @@
This is usually not an issue in a production environment. To get
around this issue you may want to run a server with multiple workers
like Passenger or try to embed your resources within your HTML to
avoid extra HTTP requests.
- Example solution (rails / bundler), add unicorn to the development
- group in your Gemfile `gem 'unicorn'` then run `bundle`. Next, add a
+ Example solution (rails / bundler), add unicorn to the development
+ group in your Gemfile `gem 'unicorn'` then run `bundle`. Next, add a
file `config/unicorn.conf` with
worker_processes 3
Then to run the app `unicorn_rails -c config/unicorn.conf` (from rails_root)
@@ -144,10 +159,10 @@
urls including the domain). In restrictive server environments the
root_url configuration may be what you are looking for change your
asset host.
* **Mangled output in the browser:** Be sure that your HTTP response
- headers specify "Content-Type: application/pdf"
+ headers specify "Content-Type: application/pdf"
## Note on Patches/Pull Requests
* Fork the project.
* Setup your development environment with: `gem install bundler`; `bundle install`