I use Prawn to generate PDF.
When I use custom font (Arial CE with central/east european characters), the font is embedded into target PDF.
pdf.font_families.update(
"Arial" => {
:bold => "font/arialbd.ttf",
:italic => "font/ariali.ttf",
:bold_italic => "font/arialbi.ttf",
:normal => "font/arial.ttf"
}
)
pdf.font "Arial"
pdf.text "Účet", :size => 18
Problem is the size of PDF. Embedded font increases document size from 4kB to 80kB and I don't need to put font into every PDF because Arial CE is available on client machines.
Any suggestions how to use custom font without embedding it?
Unfortunately prawn has no way to turn off embedding of custom fonts.
You can use the build in fonts like Arial and Times New Roman, and they wont be embedded, but then you're not getting the look you're after.
Related
I am using scripts to fill Indesign document with text. There is standard unicode characters (emoji, cyrillic, maths, arabic) but sometimes they are are not in one font. I have to take it from different fonts.
Is there a solution like in browser CSS where i specify few fonts ordered by priority font-family: font1, font2, font3?
Definitively nothing like CSS font-styles enumeration but thanks to InDiScripts "IndyFont" a/o FontMixer from same Author to generate either a fully customized font or a composite font:
FontMixer : http://www.indiscripts.com/post/2013/07/fontmixer-extend-typefaces-in-indesign
InDyFont : http://www.indiscripts.com/category/projects/IndyFont
I have a problem when I try to change the default font.
The symbols in resulting PDF are changed by ??? symbols, so I tried to change the default font.
But when I try to change the default font in vendor/barryvdh/laravel-dompdf/config/dompdf.php "default_font" => "courier"
the font in the resulting PDF is not changed - Helvetica stays whatever I did.
I even tried to change the default font in the controller just before PDF generation:
PDF::setOptions(['dpi' => 150, 'defaultFont' => 'courier']);
but, it did not help also.
What could be the problem?
Thanks!
I have a QTextEdit in which I want to set some text (unicode) that has been generated by an ASCII Art text renderer. Everything works fine, except that the QTextEdit is distorting the text. The screenshot shows the same unicode text variable set in the QTextEdit via setText() and logged to the console, where it is displayed correctly.
It doesn't seem to matter if I use QTextEdit or QPlainTextEdit, or if I am setting the text via setText(ascii_art_text) or setPlainText(ascii_art_text). I'm using PySide here, however I suspect that isn't of too much interest in this case.
Any ideas how to fix that distortion?
From the looks of your example, it appears that your QTextEdit is not using a monospaced font which is what terminals and text editors typically use. Create a QFont using a monospaced font. E.g.,
# Specific Windows monospaced font.
font = QFont("Courier New")
According to Torsten Marek's answer in How to specify monospace fonts for cross platform Qt applications?, you can get a cross platform monospaced font with:
font = QFont("Monospace")
font.setStyleHint(QFont.TypeWriter)
Once you've determined your font, assign it to your QTextEdit:
text_edit.setCurrentFont(font)
I am trying to export jasper as pdf but It does not show the cyrillic values. When I export it as excel it does show and the output is fine, but when I try to export is as PDF it does not export the cyrillic values. The cyrillic values are not written in cyrillic font, they are written as cyrillic keyboard.
The code I use to export is:
JRExporter e = new JRPdfExporter();
e.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
e.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outStream);
e.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, NAME);
I even tried to specift the parameter below:
e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");
but did not succeed. Any suggestions?
Jasper report uses iText and always when a char is not rendered in pdf this should be the checklist:
Is my actual .tff supported (OpenType) and can the font actually render the character. Not all fonts render
all characters in UTF-8, see How can I test if my font is rendered correctly in pdf?
Do I pass correct encoding to iText. In doubts (or in general) use the encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.
Is my font embedded so that if I share the pdf also computers not having this font can display the content?
How can I ensure this is JasperReport?
The deprecated method was to set attributes on the textElement
<textElement>
<font pdfFontName="Helvetica" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single"/>
</textElement>
The current non deprecated method v 3-6, is to add Font Extensions and this is easily achieved by using tools like iReport or JasperSoft Studio that can generate a .jar of your font extension so that you can include it in your classpath directly.
How to generate font extension .jar using iReport or JasperSoft Studio.
EDIT: The problem of OP was 1 on checklist (.ttf font could not render), but surely he should consider both 2 and 3 using non deprecated method.
I have a small Ruby program where I'm printing some text out to a PDF using Prawn, but a small portion of the text is non-English characters. (Some of that text is Chinese, some is Greek, etc.). When I run my program, I of course get an error saying Your document includes text that's not compatible with the Windows-1252 character set. (Prawn::Errors::IncompatibleStringEncoding)
If you need full UTF-8 support, use TTF fonts instead of PDF's built-in fonts. I know that I need to use a TTF font, but how do I even go about that? Do I need to install it from online? If so, where would I save it to? I know that's probably a dumb question but I'm new to Ruby and Prawn. Thanks!
ttf is a common format, you can download fonts at Google font for instance, put the font in some directory in your project for instance under /assets/fonts/
You can then define a new font family like so:
Prawn::Document.generate("output.pdf") do
font_families.update("Arial" => {
:normal => "/assets/fonts/Arial.ttf",
:italic => "/assets/fonts/Arial Italic.ttf",
})
font "Arial"
end
You can then use the font throughout your document.
A quick and dirty work-around to prevent this error is to encode your text to windows-1252 before writing it to the pdf file.
text = text.encode("Windows-1252", invalid: :replace, undef: :replace, replace: '')
A drawback to this approach is that, if the character you are converting is invalid or undefined in Windows-1252 encoding, it will be replaced by an empty string ''
Depending on your original text, this solution may work fine, or you may end up missing a few characters in your PDF.
If you are using plain Ruby you could try this way:
require 'prawn'
Prawn::Document.generate("my_text.pdf") do
font('Helvetica', size: 50) do
formatted_text_box(
[{text: 'Whatever text you need to print'}],
at: [0, bounds.top],
width: 100,
height: 50,
overflow: :shrink_to_fit,
disable_wrap_by_char: true # <---- newly added in 1.2
)
end
end