foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.87k stars 1.15k forks source link

Garbled text in Illustrator and Corel Draw #335

Closed felixbuenemann closed 8 years ago

felixbuenemann commented 9 years ago

Opening a PDFkit created PDF with embedded TTF subset in Illustrator CS6, CC or Corel Draw X7 shows the raw bytes used for the subsetting instead of the proper characters.

The text Hello Wörld! is shown as !"##$%&'(#)*. This corresponds to the ASCII characters that would map to the bytes used by PDFkit for subsetting, beginning with 33 | 0x21 | !.

Displaying in Mac Preview or Adobe Acrobat X is fine.

The embedded font is a TTF of Univers by Linotype, but the Problem happens with all TTF fonts I tried.

The issue does not occur, if a similar PDF is created using Prawn.

Sample Code PDFkit:

var PDFDocument = require('pdfkit'),
    fs = require('fs'),
    doc = new PDFDocument()

doc.pipe(fs.createWriteStream('hello-pdfkit.pdf'))

doc.font('resources/assets/fonts/LT_21218.ttf')
   .fontSize(12)
   .text('Hello Wörld!', 25, 25)

doc.end()

Sample Code Prawn:

require "prawn"

Prawn::Document.generate("hello-prawn.pdf") do
  font "resources/assets/fonts/LT_21218.ttf" do
    text "Hello Wörld!"
  end
end

Comparing the Prawn and PDFkit PDFs I noticed that they do subsetting/charmaps differently and that the font embedded by prawn has additional headers (prep, fpgm, cvt).

devongovett commented 9 years ago

Interesting. Does this happen with all embedded fonts, or just that particular one? If it is just that font, can you send it to me privately for testing? My email is devongovett@gmail.com.

felixbuenemann commented 9 years ago

It happens with all TTF fonts I tested with: Univers, Droid Sans, The Sans. It also happens with the PDF from the PDFkit demo.

Screenshot: Screenshot from Illustrator CC 2014

denyskoch commented 9 years ago

@devongovett what are your plans about fixing it?

denyskoch commented 9 years ago

The root of this issue is the remapping of the glyphs to chars, since Illustrator use the installed font for editing and this font is not mapped the same way. I patched pdfkit not to remap the charMap, but now umlauts/compound glyphs not shown anymore. Any Ideas?

EDIT: it seems to be related to charCoder greater than 0x7F. If I change the encoding in subset.coffee to macroman, than it works.

devongovett commented 9 years ago

Sorry about the delayed response. I'm working on a new font engine that should launch soon, using CID fonts. Some of that work is in the fontkit branch. It's still experimental, but if you feel like trying that out to see if it fixes the problem, I'd appreciate it. I don't have access to Illustrator for testing, so it would be helpful. Thanks!

v-python commented 9 years ago

Are there instructions for installing the fontkit branch? I see the makefile, but I don't speak coffeescript or node, so it is not clear what dependencies I'd need to install to make it work.

denyskoch commented 9 years ago

@v-python just run npm install && make and it should work ;)

@devongovett code on fontkit branch seems to work and fixes the problem. Can you tell the release date?

v-python commented 9 years ago

@denyskoch Thanks for the response... "npm install" gives a usage message "npm install pdfkit" gives me the non-fontkit version so I'm still missing something newbie of what goes where.

denyskoch commented 9 years ago

@v-python you need to checkout pdfkit by your own, because in npm-registry is only the compiled master version.

$ git clone -b fontkit https://github.com/devongovett/pdfkit.git
$ npm install && make

background: in the packages.json are two(to be correct three) kinds of dependencies devDependencies and dependencies. devDependencies are only installed if you run npm install on the repository (if you checked out it) and dependencies are installed when you install the package from npm registry (e.g. with npm install pdfkit) see: http://stackoverflow.com/a/22004559

v-python commented 9 years ago

@denyskoch Thanks for the helpful looking reply. Too late to try it tonight, but hopefully soon.

WiLb00X commented 8 years ago

@devongovett have you find a solution? i really need it. :(

devongovett commented 8 years ago

fontkit was released in v0.8.0, and should fix this issue.