Skip to content

Commit

Permalink
Use UTF-8 encoding for Weasyprint (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldiekmeier authored May 23, 2024
1 parent 079618e commit 621685c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source 'https://rubygems.org'
gemspec

gem 'activemodel'
gem 'pdf-reader'
gem 'bundler'
gem 'pry-byebug'
gem 'rake'
Expand Down
2 changes: 1 addition & 1 deletion lib/pixelpress/renderers/weasyprint_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Pixelpress::WeasyPrintRenderer
def render(input)
output = Tempfile.new

system executable_path, input.path, output.path, exception: true
system executable_path, "--encoding", "utf-8", input.path, output.path, exception: true
return output
end

Expand Down
20 changes: 17 additions & 3 deletions spec/renderers/weasyprint_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@

describe Pixelpress::WeasyPrintRenderer do
let(:renderer) { Pixelpress::WeasyPrintRenderer.new }
let (:input) do
let (:input) do
file = Tempfile.new
file.write("<html><body><h1>hello</h1></body></html>")
file.write <<~HTML
<html>
<head>
<meta name=author content="Bärbel Garçon">
</head>
<body>
<h1>Hêllo Wörld</h1>
</body>
</html>
HTML
file.rewind
file
end

it "should render html to pdf" do
expect(renderer.render(input).read).to start_with("%PDF")
reader = PDF::Reader.new(renderer.render(input))

expect(reader.info[:Author]).to eq("Bärbel Garçon")
expect(reader.page_count).to eq(1)
page = reader.pages.sole
expect(page.text).to eq("Hêllo Wörld")
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'generators/pixelpress/printer/printer_generator'
require 'pathname'
require 'open3'
require 'pdf-reader'

RSpec.configure do |config|
config.example_status_persistence_file_path = '.rspec_status'
Expand Down

0 comments on commit 621685c

Please sign in to comment.