gkhtmltopdf 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 074bccbef46db0aaa81947a06ea1a1d7022b75a4916dec8d76751b96bfbc607f
4
- data.tar.gz: bd007b02950a0e01a6cb1a0a68c30e3f5f16604f0489568bef0899f5f2d1e84d
3
+ metadata.gz: d19d8c78dff4c87b9c50ea25a94f606d4485313cc37e8a553f0f5188d344fe41
4
+ data.tar.gz: 0c5b0b8f586920efc3a42a03e8a1da264ea8a68305424aadbca9763bed9d785d
5
5
  SHA512:
6
- metadata.gz: e359baec50a11f2276bd1354269c59667091bbf12f9285d219616569b266f18a63c40be1349667ee7cefd5550109b93c9757705a8135dd15152762c6ab98c09c
7
- data.tar.gz: 2fe00c3971f0354310bbc946531eb6facb107c7649f0d191b0210ea2fd683a726cabe18613053d498ded52558eb92791a0c522bb87f16f7ad77220c72faf075b
6
+ metadata.gz: 9854a78ecf08c217f9d27ed5288f6fcbad15d53c16eeacb2a6a47603f1fd32e43f29aa799aafaa2612dc5279bf21ec92c90d24f97b00cd89d78721a1172dabe4
7
+ data.tar.gz: de4240fa2f30027a76d2acfb91a0fedfcc55a7c37b1fea4bce7ce7a18a5406766dd00bbd7986176e96cbcaf3819e3011364062682c5588e8ccd7f6e16461c717
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.10
1
+ 4.0.9
data/CHANGELOG.md CHANGED
@@ -2,15 +2,33 @@
2
2
 
3
3
  All noteworthy changes to this project will be documented in this file.
4
4
 
5
+ ## 1.2.1 / 2026-10-27
6
+
7
+ - No new features added.
8
+ - 機能追加なし
9
+ - Updated DevEnv to ruby4.
10
+ - 開発環境をruby4.0.9に
11
+ - Added dockerfiles.
12
+ - amazonlinux2023でのテストとか追加
13
+
14
+ ## 1.2.0 / 2026-07-31
15
+
16
+ - Added `pdf_binary` methods.
17
+ - PDFバイナリ取得メソッドの追加
18
+
5
19
  ## 1.1.1 / 2026-06-29
6
20
 
7
- - GeckodriverのSTDOUT/STDERR追加
21
+ - Added STDOUT/STDERR for geckodriver.
22
+ - GeckodriverのSTDOUT/STDERR追加
8
23
 
9
24
  ## 1.1.0 / 2026-06-29
10
25
 
11
- - UA設定機能の追加
12
- - mktmpdirの明示的な削除
13
- - ubuntuでの動かし方とか修正
26
+ - Added User-Agent setting.
27
+ - UA設定機能の追加
28
+ - Explicit deleted of `mktmpdir`.
29
+ - `mktmpdir` の明示的な削除
30
+ - Howto and docs updated.
31
+ - ubuntuでの動かし方とか修正
14
32
 
15
33
  ## 1.0.0 / 2026-03-19
16
34
 
data/README.md CHANGED
@@ -8,6 +8,7 @@ This gem converts HTML to PDF using Firefox's Geckodriver.
8
8
  [![Gem Version](https://badge.fury.io/rb/gkhtmltopdf.svg)](https://badge.fury.io/rb/gkhtmltopdf)
9
9
  ![Gem Total Downloads](https://img.shields.io/gem/dt/gkhtmltopdf)
10
10
  ![GitHub License](https://img.shields.io/github/license/fantasia-tech/gkhtmltopdf-rb)
11
+ ![Rspec](https://github.com/fantasia-tech/gkhtmltopdf-rb/actions/workflows/main.yml/badge.svg)
11
12
 
12
13
  ---
13
14
 
@@ -15,33 +16,19 @@ This gem converts HTML to PDF using Firefox's Geckodriver.
15
16
 
16
17
  ### 1. Install
17
18
 
18
- 1. [Firefox](https://www.firefox.com)
19
- - Ubuntu
20
- > The snap does not work correctly, so please install it from the [official source](https://support.mozilla.org/en-US/kb/install-firefox-linux).
21
- ```bash
22
- $ wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | sudo tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null
23
- $ echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null
24
- $ tee /etc/apt/preferences.d/mozilla > /dev/null << EOF
25
- Package: *
26
- Pin: origin packages.mozilla.org
27
- Pin-Priority: 1000
28
- EOF
29
- $ apt install -y firefox
30
- $ apt install -y fonts-noto # recommended
31
- ```
32
- - Debian
33
- ```bash
34
- $ apt install -y firefox-esr
35
- $ apt install -y fonts-noto # recommended
36
- ```
37
-
38
- 2. [geckodriver](https://github.com/mozilla/geckodriver)
39
- - Linux (Ubuntu / Debian)
40
- ```bash
41
- $ wget "https://github.com/mozilla/geckodriver/releases/download/v0.36.0/geckodriver-v0.36.0-linux64.tar.gz" -O /tmp/geckodriver.tar.gz
42
- $ tar -xzf /tmp/geckodriver.tar.gz -C /usr/local/bin
43
- ```
19
+ > The following is an example of the setup on Debian 13.
20
+ > For other operating systems (Ubuntu / Amazon Linux), please see [here](/docs/SupportList.md).
44
21
 
22
+ 1. [Firefox](https://www.firefox.com)
23
+ ```bash
24
+ $ apt install -y firefox-esr
25
+ $ apt install -y fonts-noto # recommended
26
+ ```
27
+ 2. [geckodriver](https://github.com/mozilla/geckodriver)
28
+ ```bash
29
+ $ wget "https://github.com/mozilla/geckodriver/releases/download/v0.36.0/geckodriver-v0.36.0-linux64.tar.gz" -O /tmp/geckodriver.tar.gz
30
+ $ tar -xzf /tmp/geckodriver.tar.gz -C /usr/local/bin
31
+ ```
45
32
  3. gem install
46
33
  - bundler
47
34
  ```bash
@@ -81,10 +68,18 @@ Gkhtmltopdf.open do |gkh2p|
81
68
  gkh2p.save_pdf('file:///foo/bar/test.html', 'local.pdf')
82
69
  gkh2p.save_pdf('https://f6a.net/oss/', 'with_bg.pdf', print_options: {background: true})
83
70
  end
84
- # set custom user-agent
71
+ # After version 1.1.0: set custom user-agent
85
72
  Gkhtmltopdf.open(user_agent: 'YOUR USER AGENT') do |gkh2p|
86
73
  gkh2p.save_pdf('https://f6a.net/oss/', 'ua.pdf')
87
74
  end
75
+ # After version 1.2.0: get PDF binary
76
+ Gkhtmltopdf.open do |gkh2p|
77
+ pdf_obj = gkh2p.pdf_binary('https://f6a.net/oss/', print_options: {background: true})
78
+ # for example, If the PDF size between 16KB and 1MB, write binary to a file.
79
+ max = 1 * 1000 * 1000
80
+ min = 16 * 1000
81
+ File.binwrite('binary.pdf', pdf_obj) if pdf_obj.bytesize.between?(min, max)
82
+ end
88
83
  ```
89
84
 
90
85
  #### Shell
data/TODO.md CHANGED
@@ -26,14 +26,14 @@
26
26
 
27
27
  - [x] GeckodriverのSTDOUT/STDERR追加
28
28
 
29
- ## つぎ v1.2.0
29
+ ## 完了 v1.2.0
30
30
 
31
- - [ ] 設定のStruct化?(default切り出し)
32
- - [ ] pdfをsaveせずバイナリを直接返却するメソッドの追加
33
- - [ ] 肥大化したconvert.rbの分割( `Gkhtmltopdf::PDF` とかつくるか)
31
+ - [x] pdfをsaveせずバイナリを直接返却するメソッドの追加
34
32
 
35
33
  ## 検討中
36
34
 
35
+ - [ ] 設定のStruct化?(default切り出し)
36
+ - [ ] 肥大化したconvert.rbの分割( `Gkhtmltopdf::PDF` とかつくるか)
37
37
  - [ ] ポート範囲設定?
38
38
  - [ ] YARD追加
39
39
  - [ ] FireFox timeout
@@ -0,0 +1,21 @@
1
+ # syntax=docker/dockerfile:1.7
2
+ FROM amazonlinux:2023
3
+ RUN yum check-update
4
+ RUN yum install -y wget tar git gzip ruby3.2 ruby3.2-devel libyaml-devel
5
+ RUN yum groupinstall -y "Development Tools"
6
+
7
+ # Install Noto Fonts
8
+ RUN yum install -y google-noto-cjk-fonts
9
+ RUN yum install -y google-noto-emoji-fonts
10
+
11
+ # Install Firefox
12
+ RUN yum install -y firefox
13
+
14
+ # Install Geckodriver
15
+ RUN wget "https://github.com/mozilla/geckodriver/releases/download/v0.36.0/geckodriver-v0.36.0-linux64.tar.gz" -O geckodriver.tar.gz
16
+ RUN tar -xzf geckodriver.tar.gz -C /usr/local/bin
17
+
18
+ COPY . /app
19
+ WORKDIR /app
20
+ RUN bundle install
21
+ CMD ["bundle", "exec", "rspec"]
@@ -0,0 +1,20 @@
1
+ # syntax=docker/dockerfile:1.7
2
+ FROM ruby:3.4-slim
3
+
4
+ RUN apt-get update
5
+ RUN apt-get install -y git wget xz-utils build-essential libyaml-dev
6
+
7
+ # Install Noto Fonts
8
+ RUN apt-get install -y fonts-noto
9
+
10
+ # Install Firefox
11
+ RUN apt-get install -y firefox-esr
12
+
13
+ # Install Geckodriver
14
+ RUN wget "https://github.com/mozilla/geckodriver/releases/download/v0.36.0/geckodriver-v0.36.0-linux64.tar.gz" -O geckodriver.tar.gz
15
+ RUN tar -xzf geckodriver.tar.gz -C /usr/local/bin
16
+
17
+ COPY . /app
18
+ WORKDIR /app
19
+ RUN bundle install
20
+ CMD ["bundle", "exec", "rspec"]
@@ -0,0 +1,20 @@
1
+ # syntax=docker/dockerfile:1.7
2
+ FROM ruby:4.0-slim
3
+
4
+ RUN apt-get update
5
+ RUN apt-get install -y git wget xz-utils build-essential libyaml-dev
6
+
7
+ # Install Noto Fonts
8
+ RUN apt-get install -y fonts-noto
9
+
10
+ # Install Firefox
11
+ RUN apt-get install -y firefox-esr
12
+
13
+ # Install Geckodriver
14
+ RUN wget "https://github.com/mozilla/geckodriver/releases/download/v0.36.0/geckodriver-v0.36.0-linux64.tar.gz" -O geckodriver.tar.gz
15
+ RUN tar -xzf geckodriver.tar.gz -C /usr/local/bin
16
+
17
+ COPY . /app
18
+ WORKDIR /app
19
+ RUN bundle install
20
+ CMD ["bundle", "exec", "rspec"]
data/docs/ForDeveloper.md CHANGED
@@ -2,21 +2,50 @@
2
2
 
3
3
  ## Test
4
4
 
5
+ ### Docker build
6
+
5
7
  ```bash
6
- $ docker build -f ./dockerfiles/Dockerfile.debian13-ruby32 . -t gkhtmltopdf-d13r32
7
8
  $ docker build -f ./dockerfiles/Dockerfile.ubuntu24-ruby32 . -t gkhtmltopdf-u24r32
8
9
  $ docker build -f ./dockerfiles/Dockerfile.ubuntu26-ruby33 . -t gkhtmltopdf-u26r33
9
- $ docker run --rm gkhtmltopdf-d13r32
10
+ $ docker build -f ./dockerfiles/Dockerfile.debian13-ruby32 . -t gkhtmltopdf-d13r32
11
+ $ docker build -f ./dockerfiles/Dockerfile.debian13-ruby33 . -t gkhtmltopdf-d13r33
12
+ $ docker build -f ./dockerfiles/Dockerfile.debian13-ruby34 . -t gkhtmltopdf-d13r34
13
+ $ docker build -f ./dockerfiles/Dockerfile.debian13-ruby40 . -t gkhtmltopdf-d13r40
14
+ $ docker build -f ./dockerfiles/Dockerfile.amazonlinux2023-ruby32 . -t gkhtmltopdf-a23r32
15
+ $ docker build -f ./dockerfiles/Dockerfile.amazonlinux2023-ruby40 . -t gkhtmltopdf-a23r40
16
+ ```
17
+
18
+ ### Docker run rspec
19
+
20
+ ```bash
10
21
  $ docker run --rm gkhtmltopdf-u24r32
11
22
  $ docker run --rm gkhtmltopdf-u26r33
12
- $ docker rmi gkhtmltopdf-d13r32
23
+ $ docker run --rm gkhtmltopdf-d13r32
24
+ $ docker run --rm gkhtmltopdf-d13r33
25
+ $ docker run --rm gkhtmltopdf-d13r34
26
+ $ docker run --rm gkhtmltopdf-d13r40
27
+ $ docker run --rm gkhtmltopdf-a23r32
28
+ $ docker run --rm gkhtmltopdf-a23r40
29
+ ```
30
+
31
+ ### Docker remove image
32
+
33
+ ```bash
13
34
  $ docker rmi gkhtmltopdf-u24r32
14
35
  $ docker rmi gkhtmltopdf-u26r33
36
+ $ docker rmi gkhtmltopdf-d13r32
37
+ $ docker rmi gkhtmltopdf-d13r33
38
+ $ docker rmi gkhtmltopdf-d13r34
39
+ $ docker rmi gkhtmltopdf-d13r40
40
+ $ docker rmi gkhtmltopdf-a23r32
41
+ $ docker rmi gkhtmltopdf-a23r40
15
42
  ```
16
43
 
17
- ## Build
44
+ ---
45
+
46
+ ## Build & Push
18
47
 
19
48
  ```bash
20
49
  $ gem build gkhtmltopdf.gemspec
21
- $ gem push
50
+ $ gem push ~.gem
22
51
  ```
@@ -0,0 +1,15 @@
1
+ # SupportList
2
+
3
+ Operation has been verified with the following OS and Ruby versions.
4
+ Please refer to the Dockerfile if you are unsure how to run the application.
5
+
6
+ | OS | Ruby| Link |
7
+ |----------------|-----|----------|
8
+ |AmazonLinux 2023|3.2.x| [Dockerfile](/dockerfiles/Dockerfile.amazonlinux2023-ruby32) |
9
+ |AmazonLinux 2023|4.0.x| [Dockerfile](/dockerfiles/Dockerfile.amazonlinux2023-ruby40) |
10
+ | Debian 13 |3.2.x| [Dockerfile](/dockerfiles/Dockerfile.debian13-ruby32) |
11
+ | Debian 13 |3.3.x| [Dockerfile](/dockerfiles/Dockerfile.debian13-ruby33) |
12
+ | Debian 13 |3.4.x| [Dockerfile](/dockerfiles/Dockerfile.debian13-ruby34) |
13
+ | Debian 13 |4.0.x| [Dockerfile](/dockerfiles/Dockerfile.debian13-ruby40) |
14
+ | Ubuntu 24.04 |3.2.x| [Dockerfile](/dockerfiles/Dockerfile.ubuntu24-ruby32) |
15
+ | Ubuntu 26.04 |3.3.x| [Dockerfile](/dockerfiles/Dockerfile.ubuntu26-ruby33) |
@@ -47,6 +47,13 @@ module Gkhtmltopdf
47
47
  File.binwrite(output_path, Base64.decode64(pdf_base64))
48
48
  end
49
49
 
50
+ def pdf_binary(url, print_options: {})
51
+ validate_url_scheme!(url)
52
+ navigate(url)
53
+ pdf_base64 = print_pdf(print_options)
54
+ Base64.decode64(pdf_base64)
55
+ end
56
+
50
57
  private
51
58
 
52
59
  def get_free_port
@@ -17,5 +17,9 @@ module Gkhtmltopdf
17
17
  def save_pdf(url, output_path, print_options: {})
18
18
  @converter.save_pdf(url, output_path, print_options: print_options)
19
19
  end
20
+
21
+ def pdf_binary(url, print_options: {})
22
+ @converter.pdf_binary(url, print_options: print_options)
23
+ end
20
24
  end
21
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gkhtmltopdf
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.1'
5
5
  end
@@ -29,6 +29,16 @@ RSpec.describe Gkhtmltopdf::Converter do
29
29
  expect(File.binread(output)).to include('/FontName')
30
30
  }
31
31
  end
32
+ describe '#pdf_binary' do
33
+ before { converter.open }
34
+ let(:url) { "file://#{file_fixture('test.html')}" }
35
+
36
+ subject { converter.pdf_binary(url) }
37
+
38
+ it {
39
+ is_expected.to include('/FontName')
40
+ }
41
+ end
32
42
  describe '#resolve_geckodriver_path!' do
33
43
  subject { converter.send(:resolve_geckodriver_path!, nil) }
34
44
  context 'geckodriver is not available' do
@@ -24,22 +24,41 @@ RSpec.describe Gkhtmltopdf do
24
24
  let(:url) { 'https://f6a.net/oss/' }
25
25
  let(:output_path) { Dir.mktmpdir }
26
26
  after { FileUtils.remove_entry_secure(output_path) }
27
+ describe '.save_pdf' do
28
+ subject do
29
+ Gkhtmltopdf.open do |gk|
30
+ (1..3).each { |n| gk.save_pdf("#{url}?test=#{n}", File.join(output_path, "#{n}.pdf")) }
31
+ end
32
+ end
27
33
 
28
- subject do
29
- Gkhtmltopdf.open do |gk|
30
- (1..3).each { |n| gk.save_pdf("#{url}?test=#{n}", File.join(output_path, "#{n}.pdf")) }
34
+ it 'successful conversion' do
35
+ expect { subject }.to change { Dir.glob(File.join(output_path, '*.pdf')).count }.from(0).to(3)
36
+ expect { subject }.not_to raise_error
31
37
  end
32
- end
33
38
 
34
- it 'successful conversion' do
35
- expect { subject }.to change { Dir.glob(File.join(output_path, '*.pdf')).count }.from(0).to(3)
36
- expect { subject }.not_to raise_error
39
+ context 'invalid URL' do
40
+ let(:url) { 'ftp://example.com' }
41
+ it 'raises an error' do
42
+ expect { subject }.to raise_error(Gkhtmltopdf::URLSchemeInvalid, 'Invalid URL scheme: (ftp)')
43
+ end
44
+ end
37
45
  end
38
-
39
- context 'invalid URL' do
40
- let(:url) { 'ftp://example.com' }
41
- it 'raises an error' do
42
- expect { subject }.to raise_error(Gkhtmltopdf::URLSchemeInvalid, 'Invalid URL scheme: (ftp)')
46
+ describe '.pdf_binary' do
47
+ subject do
48
+ Gkhtmltopdf.open do |gk|
49
+ pdf_binary = gk.pdf_binary("#{url}?test=binary")
50
+ pdf_binary.bytesize
51
+ end
52
+ end
53
+ it 'successful conversion' do
54
+ is_expected.to be > 1000
55
+ expect { subject }.not_to raise_error
56
+ end
57
+ context 'invalid URL' do
58
+ let(:url) { 'ftp://example.com' }
59
+ it 'raises an error' do
60
+ expect { subject }.to raise_error(Gkhtmltopdf::URLSchemeInvalid, 'Invalid URL scheme: (ftp)')
61
+ end
43
62
  end
44
63
  end
45
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gkhtmltopdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuki Sakane
@@ -82,10 +82,14 @@ files:
82
82
  - README.md
83
83
  - Rakefile
84
84
  - TODO.md
85
+ - dockerfiles/Dockerfile.amazonlinux2023-ruby32
85
86
  - dockerfiles/Dockerfile.debian13-ruby32
87
+ - dockerfiles/Dockerfile.debian13-ruby34
88
+ - dockerfiles/Dockerfile.debian13-ruby40
86
89
  - dockerfiles/Dockerfile.ubuntu24-ruby32
87
90
  - dockerfiles/Dockerfile.ubuntu26-ruby33
88
91
  - docs/ForDeveloper.md
92
+ - docs/SupportList.md
89
93
  - exe/gkhtmltopdf
90
94
  - lib/errors.rb
91
95
  - lib/gkhtmltopdf.rb
@@ -124,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
128
  requirements:
125
129
  - Firefox
126
130
  - Geckodriver
127
- rubygems_version: 4.0.8
131
+ rubygems_version: 4.0.20
128
132
  specification_version: 4
129
133
  summary: Gkhtmltopdf is mean Gecko HTML to PDF converter.
130
134
  test_files: []