gkhtmltopdf 1.1.1 → 1.2.0

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: 9b1e75b29bc038ca05956a13cecbd811f766f5ce5047b044348f707e18f5fdaf
4
+ data.tar.gz: 6f4880a82c257459133d3d63cb9eca5b6b538095ee9278b5846d965b53edda95
5
5
  SHA512:
6
- metadata.gz: e359baec50a11f2276bd1354269c59667091bbf12f9285d219616569b266f18a63c40be1349667ee7cefd5550109b93c9757705a8135dd15152762c6ab98c09c
7
- data.tar.gz: 2fe00c3971f0354310bbc946531eb6facb107c7649f0d191b0210ea2fd683a726cabe18613053d498ded52558eb92791a0c522bb87f16f7ad77220c72faf075b
6
+ metadata.gz: ec2c49f78a33d7be7257e09bc66508d14b65880ab88b48d636580de5052abbd31a34f2544d0c7c9acb1491ddda8fe74f09ff5d22c061ea465261170ca85388ae
7
+ data.tar.gz: 8e518a69a0183db0f3a4545d9fc20e8654cc189df79af68b1297b74b19f96a76ad74288fc12a107aaaab038903e678ab4102ea25983f2ae38e863d11c75907d8
data/CHANGELOG.md CHANGED
@@ -2,15 +2,24 @@
2
2
 
3
3
  All noteworthy changes to this project will be documented in this file.
4
4
 
5
+ ## 1.2.0 / 2026-07-31
6
+
7
+ - Added `pdf_binary` methods.
8
+ - PDFバイナリ取得メソッドの追加
9
+
5
10
  ## 1.1.1 / 2026-06-29
6
11
 
7
- - GeckodriverのSTDOUT/STDERR追加
12
+ - Added STDOUT/STDERR for geckodriver.
13
+ - GeckodriverのSTDOUT/STDERR追加
8
14
 
9
15
  ## 1.1.0 / 2026-06-29
10
16
 
11
- - UA設定機能の追加
12
- - mktmpdirの明示的な削除
13
- - ubuntuでの動かし方とか修正
17
+ - Added User-Agent setting.
18
+ - UA設定機能の追加
19
+ - Explicit deleted of `mktmpdir`.
20
+ - `mktmpdir` の明示的な削除
21
+ - Howto and docs updated.
22
+ - ubuntuでの動かし方とか修正
14
23
 
15
24
  ## 1.0.0 / 2026-03-19
16
25
 
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,44 @@
2
2
 
3
3
  ## Test
4
4
 
5
+ ### Docker build
6
+
5
7
  ```bash
6
8
  $ docker build -f ./dockerfiles/Dockerfile.debian13-ruby32 . -t gkhtmltopdf-d13r32
7
9
  $ docker build -f ./dockerfiles/Dockerfile.ubuntu24-ruby32 . -t gkhtmltopdf-u24r32
8
10
  $ docker build -f ./dockerfiles/Dockerfile.ubuntu26-ruby33 . -t gkhtmltopdf-u26r33
11
+ $ docker build -f ./dockerfiles/Dockerfile.debian13-ruby34 . -t gkhtmltopdf-d13r34
12
+ $ docker build -f ./dockerfiles/Dockerfile.debian13-ruby40 . -t gkhtmltopdf-d13r40
13
+ $ docker build -f ./dockerfiles/Dockerfile.amazonlinux2023-ruby32 . -t gkhtmltopdf-a23r32
14
+ ```
15
+
16
+ ### Docker run rspec
17
+
18
+ ```bash
9
19
  $ docker run --rm gkhtmltopdf-d13r32
10
20
  $ docker run --rm gkhtmltopdf-u24r32
11
21
  $ docker run --rm gkhtmltopdf-u26r33
22
+ $ docker run --rm gkhtmltopdf-d13r34
23
+ $ docker run --rm gkhtmltopdf-d13r40
24
+ $ docker run --rm gkhtmltopdf-a23r32
25
+ ```
26
+
27
+ ### Docker remove image
28
+
29
+ ```bash
12
30
  $ docker rmi gkhtmltopdf-d13r32
13
31
  $ docker rmi gkhtmltopdf-u24r32
14
32
  $ docker rmi gkhtmltopdf-u26r33
33
+ $ docker rmi gkhtmltopdf-d13r34
34
+ $ docker rmi gkhtmltopdf-d13r40
35
+ $ docker rmi gkhtmltopdf-a23r32
15
36
  ```
16
37
 
38
+ ---
39
+
17
40
  ## Build
18
41
 
19
42
  ```bash
20
43
  $ gem build gkhtmltopdf.gemspec
21
- $ gem push
44
+ $ gem push ~.gem
22
45
  ```
@@ -0,0 +1,13 @@
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
+ | Debian 13 |3.2.x| [Dockerfile](/dockerfiles/Dockerfile.debian13-ruby32) |
9
+ | Debian 13 |3.3.x| [Dockerfile](/dockerfiles/Dockerfile.debian13-ruby33) |
10
+ | Debian 13 |4.0.x| [Dockerfile](/dockerfiles/Dockerfile.debian13-ruby40) |
11
+ | Ubuntu 24.04 |3.2.x| [Dockerfile](/dockerfiles/Dockerfile.ubuntu24-ruby32) |
12
+ | Ubuntu 26.04 |3.3.x| [Dockerfile](/dockerfiles/Dockerfile.ubuntu26-ruby33) |
13
+ |AmazonLinux 2023|3.2.x| [Dockerfile](/dockerfiles/Dockerfile.amazonlinux2023-ruby32) |
@@ -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.0'
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.0
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