prawn icon indicating copy to clipboard operation
prawn copied to clipboard

Font Embedding: Template Text is broken

Open MrSerth opened this issue 5 months ago • 4 comments

Since updating to prawn 2.5.0, we face issues with font embedding and changes to text provided on a template.

Reproduction example:

  1. This reproduction example assumes that the file Arial Unicode MS.TTF is present in the local working directory. While the font is shipped with Microsoft Office by default and can be licensed by Microsoft, it is also available on GitHub (for example here).
  2. This reproduction example further assumes that a file called template.pdf is present in the local working directory downloaded from this issue: template.pdf. The template text was created in Word and then exported to PDF. It contains two lines of text in two different fonts; namely "Source Sans Pro" and "Calibri". Both fonts are shipped with the template as embedded subset:
Bildschirmfoto 2024-09-18 um 20 57 22

With both files being available, a simple irb can be started and the following script can be executed:

require 'prawn'
require 'prawn/templates'

@pdf = Prawn::Document.new(
  template: 'template.pdf',
  page_size: 'A4',
  page_layout: :landscape,
  left_margin: 0,
  right_margin: 0,
  top_margin: 0,
  bottom_margin: 0
)

# Subsetting is disabled, so that https://github.com/prawnpdf/prawn/issues/1361 doesn't apply.
@pdf.font_families.update("ArialUnicodeMS" => {normal: {file: "Arial Unicode MS.TTF", subset: false}})

@pdf.font "ArialUnicodeMS", style: :normal
@pdf.text_rendering_mode :fill_stroke do
  @pdf.draw_text "Demo Text @ Draw Text", size: 22.0, style: :normal, text_anchor: "middle", at: [500, 500], offset: [0, 0]
end

@pdf.render_file('prawn.pdf')
puts "Done"

Issue noticed:

  • [ ] The "Template Text in Source Sans Pro" is not correctly encoded any longer after being processed by Prawn. Instead, the text is now displayed as "2=EHD9L=2=PLAF1GMJ;=19FK.JG".

We assume that this issue is not directly related to #1361, since subsetting is explicitly disabled for the font. However, since we are not fully aware of the inner workings of Prawn, both issues could be well related. In this case, we excuse for the duplicate reporting. Any help to fix the issue mentioned is very appreciated!

--

prawn: 2.5.0 Ruby: 3.3.5 Adobe Acrobat Pro: 2024.003.20121 Microsoft Word: Version 2408 Build 16.0.17928.20156

MrSerth avatar Sep 18 '24 19:09 MrSerth