Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring up to speed with base #1

Open
wants to merge 86 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
4b5c5db
Introduce support of xvfb
dmeremyanin Feb 12, 2015
5291f38
Add failing spec to prove there are threadsafety issues.
danbernier Sep 8, 2016
688587b
Fix threadsafety issue.
danbernier Sep 8, 2016
d99ce74
Remove middleware spec that examines mutated state.
danbernier Sep 8, 2016
3e3b7b1
Fix typo
gitname Jan 12, 2017
5b131b8
Remove `config.protocol` from the README.
danbernier Feb 12, 2017
d333bca
Allow PDFKit middleware to receive javascript delay option through re…
abrom Mar 2, 2017
dca550e
Merge pull request #391 from abrom/master
serene Jan 22, 2019
a18b427
Missing version bump
Feb 15, 2019
0a00b01
Add Ruby 2.3 to travis
Feb 15, 2019
96ac06d
Merge pull request #432 from pdfkit/version_bump
serene Feb 15, 2019
c6e4412
Merge pull request #277 from dmeremyanin/xvfb
serene Feb 21, 2019
8414376
Merge pull request #389 from danbernier/remove-config-protocol-from-r…
serene Feb 21, 2019
df210d4
Remove support for Ruby < 2.2 (#429)
serene Feb 22, 2019
5e0f07a
Update activesupport, remove Ruby 1.9.2 compatibility
Feb 22, 2019
4a7bd44
Merge pull request #434 from pdfkit/update_dependencies
serene Feb 22, 2019
b611084
Merge branch 'master' into threadsafety
danbernier Feb 22, 2019
af9940e
Merge pull request #377 from danbernier/threadsafety
serene Feb 22, 2019
5bbda84
Version bump for bug fixes
Feb 22, 2019
4d06050
Merge pull request #435 from pdfkit/version_0.8.4.1
serene Feb 22, 2019
40e4b62
Merge pull request #386 from gitname/patch-1
serene Feb 24, 2019
b542f34
Subclass PDFkit errors
nikolai-b Feb 26, 2019
3fdb620
Raise custom error when command fails
nikolai-b Feb 26, 2019
99d27f0
Follow rubocop error raise style
nikolai-b Feb 26, 2019
e29b345
Condition of disposition to force attachment
dannnylo Mar 7, 2019
3ed25a6
Condition of disposition to force attachment
dannnylo Mar 7, 2019
4977107
Update README.md
andrelamontegomes Apr 16, 2019
33477b9
Don't break verbose when assigning default options [fixes #376]
sshaw May 26, 2019
de6157b
docs: fix typo
Jason-Cooke Jul 10, 2019
e03eba9
Update Travis CI config
gi Sep 5, 2019
4c93eb1
Merge pull request #451 from gi/issue-450-travis-ci
serene Sep 6, 2019
2239266
Merge pull request #436 from nikolai-b/master
serene Sep 6, 2019
c522354
Merge pull request #437 from dannnylo/middleware_disposition
serene Sep 6, 2019
6ee6e5e
Merge pull request #442 from sshaw/master
serene Sep 6, 2019
abe6932
Add support for Tempfile sources
gi Sep 5, 2019
bf993c8
Merge pull request #449 from gi/issue-448-tempfile
serene Sep 6, 2019
d6b32ef
Improve path detection fallback
jarthod Jan 22, 2020
d27fd8c
Add changelog entry
jarthod Jan 23, 2020
9a81594
remove comment
jarthod Jan 23, 2020
e3f5c03
Add github action to close stale issues
serene Jan 24, 2020
eca1932
Merge pull request #461 from pdfkit/action-stale-issues
serene Jan 24, 2020
842c74e
Update stale messages
serene Jan 27, 2020
8c4b9f9
Merge pull request #462 from pdfkit/update-stale-message
serene Feb 27, 2020
4b74eb6
Merge pull request #439 from gomesac/patch-1
serene Apr 1, 2020
b2b4a40
Merge pull request #444 from Jason-Cooke/patch-1
serene Apr 1, 2020
2246d3f
Merge pull request #460 from jarthod/improve-path-detection
serene Apr 1, 2020
bd5fddb
Version bump to v.0.8.4.2
serene Apr 1, 2020
fa54af4
Merge pull request #463 from pdfkit/0.8.4.2-bump
serene Apr 1, 2020
083d5d2
Update rake
serene Apr 1, 2020
8ae7484
only grab last line of bundle exec which output
maneyko Apr 1, 2020
84dc02c
Don't override request level content-disposition if it exists
bradleypriest Apr 9, 2020
7f8d654
Add missing require statements for tempfile
May 13, 2020
f38399f
Return 500 status when an exception is caught
steventux May 21, 2020
d594077
add spec to emulate docker environment without user HOME directory
maneyko Jun 11, 2020
24e6d7d
Merge pull request #466 from bradleypriest/fix-disposition
serene Jul 6, 2020
cf04582
Merge pull request #471 from pdfkit/update_rake
serene Jul 6, 2020
5678367
Merge pull request #467 from wconrad/require-tempfile
serene Jul 6, 2020
bbaac04
Merge pull request #464 from maneyko/path-detection-last-line
serene Jul 6, 2020
1f8abf9
Merge pull request #469 from steventux/master
serene Jul 6, 2020
19d55cd
Update download url for wkhtmltopdf (#473)
serene Jul 6, 2020
cc18abe
Version bump to 0.8.4.3 (#474)
serene Jul 6, 2020
b0170f8
Bump to version 0.8.4.3.1 (#475)
serene Jul 6, 2020
17f4efe
Scope middleware rescue block to PDF generation (#476)
steventux Jul 8, 2020
edd9faa
Add github action to automatically draft release notes (#479)
serene Aug 16, 2020
4150707
Fix release drafter github action (#481)
serene Aug 16, 2020
18f9fd4
Version bump to 0.8.4.3.2 (#480)
serene Aug 16, 2020
a3f6c47
Fix to render stylesheets as html safe string on Rails 6 (#483)
tricknotes Jan 24, 2021
898ecbe
Make `PDFKit::VERSION` public (#484)
tricknotes Jan 24, 2021
83a64fc
Version bump to 0.8.5 (#486)
serene Jan 24, 2021
4a9c9bc
Enable bundler caching for travis (#488)
Taher-Ghaleb May 3, 2021
ecd18e6
Enable tests on GitHub Actions (#502)
leonyip Apr 4, 2022
965c1bb
Update for new Ruby and Rails versions (#499)
BrianHawley Apr 11, 2022
3f4583a
Fix syntax error (#503)
leonyip Apr 11, 2022
46cdf53
Bump to 0.8.6 (#504)
serene Apr 11, 2022
41068fd
Lowercase the header names for rack 3 changes (#511)
serene Sep 28, 2022
54b4941
modify url_needs_escaping (#509)
KWkyle Oct 2, 2022
6d0a162
Fix typo (#510)
mdh Oct 2, 2022
6213317
Bump to 0.8.7 (#513)
serene Oct 2, 2022
089e5de
fix: support non-lower-case Content-Type header provided by app (#516)
vladimir-mencl-eresearch Oct 12, 2022
ceca488
Bump to 0.8.7.1 (#520)
serene Oct 17, 2022
79ec0c0
Call `IO.popen` with an Array of command arguments (#518). (#519)
postmodern Oct 18, 2022
404a5a4
Bump to 0.8.7.2 (#521)
serene Oct 18, 2022
29a3dd4
Allow passing a `Pathname` object to the `path` argument (#522)
yujideveloper Jan 11, 2023
2deebe3
Update repeatable options (#524)
mguidetti Feb 27, 2023
8f16704
V0.8.7.3 build failure fixes (#530)
Daniel-N-Huss May 29, 2023
762b366
Bump to v0.8.7.3 (#529)
serene May 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
# with:
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
# config-name: my-config.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Mark stale issues and pull requests

on:
schedule:
- cron: "0 0 * * *"

jobs:
stale:

runs-on: ubuntu-latest

steps:
- uses: actions/stale@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been marked as stale and will be automatically closed.'
stale-pr-message: 'This pull request has been marked as stale and will be automatically closed.'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'
71 changes: 71 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Test workflow

on: [push, pull_request]

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ruby:
- '2.5'
- '2.6'
- '2.7'
- '3.0'
- '3.1'
rails:
- '~> 4.1'
- '~> 5.2'
- '~> 6.0.0'
- '~> 6.1'
- '~> 7.0.0'
exclude:
- ruby: '2.5'
rails: '~> 7.0.0'
- ruby: '2.6'
rails: '~> 7.0.0'
- ruby: '2.7'
rails: '~> 4.1'
- ruby: '3.0'
rails: '~> 4.1'
- ruby: '3.0'
rails: '~> 5.2'
- ruby: '3.1'
rails: '~> 4.1'
- ruby: '3.1'
rails: '~> 5.2'
- ruby: '3.1'
rails: '~> 6.0.0'
runs-on: ${{ matrix.os }}
env:
RAILS_VERSION: ${{ matrix.rails }}
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
# rubygems-update's latest is no longer compatible with ruby 2.5, so conditionally run ruby-setup setting the
# rubygem version the most recent valid version for 2.5:
# https://rubygems.org/gems/rubygems-update/versions/3.3.26
if: ${{ matrix.ruby == '2.5' }}
with:
ruby-version: ${{ matrix.ruby }}
rubygems: 3.3.26
bundler: latest
bundler-cache: true
- uses: ruby/setup-ruby@v1
# otherwise, we can use rubygems latest
if: ${{ matrix.ruby != '2.5' }}
with:
ruby-version: ${{ matrix.ruby }}
rubygems: latest
bundler: latest
bundler-cache: true

- name: Setup wkhtmltopdf
run: |
sudo apt-get install -y xfonts-base xfonts-75dpi
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
sudo dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb

- name: Run tests
run: bundle exec rake
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.0.0
2.6.9
46 changes: 38 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
language: ruby

rvm:
- 1.9.2
- 1.9.3
- 2.0
- 2.1
- 2.5
- 2.6
- 2.7
- 3.0
- 3.1

env:
matrix:
- RAILS_VERSION="~> 4.1"
- RAILS_VERSION="~> 5.2"
- RAILS_VERSION="~> 6.0.0"
- RAILS_VERSION="~> 6.1"
- RAILS_VERSION="~> 7.0.0"

jobs:
exclude:
- rvm: 2.5
env: RAILS_VERSION="~> 7.0.0"
- rvm: 2.6
env: RAILS_VERSION="~> 7.0.0"
- rvm: 2.7
env: RAILS_VERSION="~> 4.1"
- rvm: 3.0
env: RAILS_VERSION="~> 4.1"
- rvm: 3.0
env: RAILS_VERSION="~> 5.2"
- rvm: 3.1
env: RAILS_VERSION="~> 4.1"
- rvm: 3.1
env: RAILS_VERSION="~> 5.2"
- rvm: 3.1
env: RAILS_VERSION="~> 6.0.0"

cache: bundler

before_install:
- gem update --system
- gem update bundler

before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- "sudo apt-get -qq -y install fontconfig libxrender1"
- "wget http://download.gna.org/wkhtmltopdf/0.12/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb"
- "sudo dpkg -i wkhtmltox-0.12.1_linux-precise-amd64.deb"
- "wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.xenial_amd64.deb"
- "sudo apt-get install ./wkhtmltox_0.12.5-1.xenial_amd64.deb"
69 changes: 69 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
2023-02-27
=================
* Bump to 0.8.7.3
* Allow passing a `Pathname` object to the `path` argument by @yujideveloper in https://github.com/pdfkit/pdfkit/pull/522
* Update repeatable options by @mguidetti in https://github.com/pdfkit/pdfkit/pull/524

2022-10-18
=================
* Bump to 0.8.7.2
* Call IO.popen with an Array of command arguments (#519)

2022-10-17
=================
* Bump to 0.8.7.1
* Support non-lower-case Content-Type header provided by app (#516)

2022-10-02
=================
* Bump to 0.8.7
* Lowercase the header names for rack 3 changes (#511)
* Partially escaped URLs should be escaped (#509)

2022-04-11
=================
* Bump to 0.8.6
* Update ruby and rails versions

2021-01-23
=================
* Bump to 0.8.5
* Make `PDFKit::VERSION` public (#484)
* Fix to render stylesheets as html safe string on Rails 6 (#483)
* Adds support for Rails 6

2020-08-16
=================
* Bump to 0.8.4.3.2
* Reduce scope of middleware exception handling (#476)

2020-07-05
=================
* Bump to 0.8.4.3.1
* Don't override request level Content-Disposition header if it exists (#466)
* Update rake (#471)
* Add missing require statements for tempfile (#467)
* Only grab last line of bundle exec which output (#464)
* Return 500 status when an exception is caught in middleware (#469)
* Update Travis CI URL for wkhtmltopf (#473)

2020-04-01
=================
* Bump to 0.8.4.2
* Improve path detection feedback (#460)
* Fix typos (#444)
* Update readme (#439)

2019-02-22
=================
* Bump to 0.8.4.1
* Make PDFkit threadsafe (#377)
* Update activesupport (#434)

2019-02-21
=================
* Bump to 0.8.4
* Removed support for Ruby < 2.2
* Xvfb support (#277)
* Remove 'config.protocol' from the README (#389)

2015-08-26
=================
* Bump to 0.8.2
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

group :test do
gem 'activesupport', '~> 3.0'
gem 'activesupport', ENV['RAILS_VERSION'] || '~> 4.1'
gem 'simplecov', require: false
end

29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,11 @@

Create PDFs using plain old HTML+CSS. Uses [wkhtmltopdf](http://github.com/antialize/wkhtmltopdf) on the back-end which renders HTML using Webkit.

## Supported versions

- Ruby 2.5, 2.6, 2.7, 3.0, 3.1
- Rails 4.2, 5.2, 6.0, 6.1, 7.0

## Install

### PDFKit
@@ -14,7 +19,7 @@ gem install pdfkit

<https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF>

2. Try using the `wkhtmltopdf-binary` gem (mac + linux i386)
2. Try using the `wkhtmltopdf-binary-edge` gem (mac + linux i386)
```
gem install wkhtmltopdf-binary
```
@@ -34,7 +39,7 @@ pdf = kit.to_pdf
file = kit.to_file('/path/to/save/pdf')

# PDFKit.new can optionally accept a URL or a File.
# Stylesheets can not be added when source is provided as a URL of File.
# Stylesheets can not be added when source is provided as a URL or File.
kit = PDFKit.new('http://google.com')
kit = PDFKit.new(File.new('/path/to/html'))

@@ -58,7 +63,7 @@ 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 pdfkit to scrape a website, you can
pass it in a hash:
```ruby
kit = PDFKit.new(url, cookie: {cookie_name: :cookie_value})
@@ -76,7 +81,6 @@ PDFKit.configure do |config|
}
# Use only if your external hostname is unavailable on the server.
config.root_url = "http://localhost"
config.protocol = 'http'
config.verbose = false
end
```
@@ -117,6 +121,13 @@ config.middleware.use PDFKit::Middleware, {}, :except => [%r[^/prawn], %r[^/secr
# conditions can be strings (either one or an array)
config.middleware.use PDFKit::Middleware, {}, :except => ['/secret']
```
**With conditions to force download**
```ruby
# force download with attachment disposition
config.middleware.use PDFKit::Middleware, {}, :disposition => 'attachment'
# conditions can force a filename
config.middleware.use PDFKit::Middleware, {}, :disposition => 'attachment; filename=report.pdf'
```
**Saving the generated .pdf to disk**

Setting the `PDFKit-save-pdf` header will cause PDFKit to write the generated .pdf to the file indicated by the value of the header.
@@ -126,7 +137,7 @@ For example:
headers['PDFKit-save-pdf'] = 'path/to/saved.pdf'
```

Will cause the .pdf to be saved to `path/to/saved.pdf` in addition to being sent back to the client. If the path is not writable/non-existant the write will fail silently. The `PDFKit-save-pdf` header is never sent back to the client.
Will cause the .pdf to be saved to `path/to/saved.pdf` in addition to being sent back to the client. If the path is not writable/non-existent the write will fail silently. The `PDFKit-save-pdf` header is never sent back to the client.

## Troubleshooting

@@ -141,13 +152,13 @@ Will cause the .pdf to be saved to `path/to/saved.pdf` in addition to being sent
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
file `config/unicorn.conf` with

worker_processes 3

Then to run the app `unicorn_rails -c config/unicorn.conf` (from rails_root)

* **Resources aren't included in the PDF:** Images, CSS, or JavaScript
@@ -161,7 +172,7 @@ Will cause the .pdf to be saved to `path/to/saved.pdf` in addition to being sent
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

3 changes: 3 additions & 0 deletions lib/pdfkit.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

require 'pdfkit/source'
require 'pdfkit/pdfkit'
require 'pdfkit/middleware'
require 'pdfkit/html_preprocessor'
require 'pdfkit/os'
require 'pdfkit/configuration'
require 'pdfkit/wkhtmltopdf'
require 'pdfkit/version'
Loading