Closed catalin88 closed 7 months ago
Hello @catalin88,
What is the issue you're facing? What is the expected result and how actual is different?
I keep getting this error message:
raise Prawn::Errors::IncompatibleStringEncoding,
"Your document includes text that's not compatible with the Windows-1252 character set.\n" \
"If you need full UTF-8 support, use TTF fonts instead of PDF's built-in fonts\n."
So I have tried changing the font to a ttf font as adviced. Did it, as I described in my initial message, but I still get the same error. I simply don't know where the problem is and how to solve it...
@catalin88 Could you please provide a minimal (and complete) snippet of code that demonstrates your issue?
The one in the first message is incomplete.
@pointlessone well, actually Prawn is part of a gem I'm using for an e-commerce app to print Invoices. And this is the code that does it:
But all I'm looking to do is change the font for Prawn, so I'm not sure why the code provided by me is not sufficient...
@pointlessone And this is the configuration for the pdf file: https://github.com/spree-contrib/spree_print_invoice/blob/fa7502f6af6e315d788d4ecd9ba3ad6d3e5ad441/lib/spree/print_invoice_setting.rb
preference :font_face, :string, default: 'Helvetica'
def font_faces
::Prawn::Font::AFM::BUILT_INS.reject do |font|
font =~ /zapf|symbol|bold|italic|oblique/i
end
end
I've attempted to answer this on stack overflow
I am trying the same thing on Prawn Tables.
The issue is explained further in this ticket - https://github.com/prawnpdf/prawn/issues/1054
Can somebody please suggest a way out for using ttf fonts in Prawn Tables
Anand
With collecting some information, here is a workaround works for me:
Check #{Prawn::DATADIR}/fonts/
if the TrueType font file you want exists. If not, download it and put it into the folder. I have no idea why gkai00mp.ttf (font for simplified Hant letters) was not installed when I use bundle to install prawn. But you can find it here.
In the prawn pdf file
prawn_document do |pdf|
pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
pdf.text "你好,世界!"
end
Should works fine.
@fbukevin Your issue doesn't seem to be related to the one described in the top message.
We do not package fonts for a couple of reasons. The fonts in the repository are only used for testing.
You should not put any files into Prawn::DATADIR
as the dir will be gone when you upgrade gem or do a new install. You should distribute fonts with your application.
I get the same error. PDF's built-in fonts have very limited support for internationalized text. If you need full UTF-8 support, consider using a TTF font instead.
However, I didn't configures any fonts.
pdf_prawn = Prawn::Document.new(page_size: 'LETTER', margin: 0)
pdf_document_package(pdf_prawn, format_image)
data = pdf_prawn.render
How can I go about providing default fonts in instantiation or in other way to fix this issue?
gem 'prawn', '~> 2.2', '>= 2.2.2'
@theasteve Have a look at the http://prawnpdf.org/manual.pdf, pages 57 and 58.
I can not reproduce the issue and I don't know where to go with this with the limited information provided. I'm closing this issue. Feel free to reopen with a minimal script that demonstrates the issue.
So if you have a string:
"Com�e", we are getting this error:
Prawn::Errors::IncompatibleStringEncoding (Your document includes text that's not compatible with the Windows-1252 character set.)
It is asking for to use the external font. Is there a solution or a workaround? We are using 'prawn', '2.4.0' and 'prawn-table', '0.2.2'
@qisantanu Yes, there's a solution! Use an external font. Also read the manual.
It is working now as expected. Thanks @pointlessone , @gettalong
Prawn doesn't work with language specific characters. I think this is a known and addressed problem. But I simply can't solve this, I keep getting the same error over and over again.
This is what I have tried:
/models/prawn/change_font_decorator.rb
Any ideas why it doesn't work ?