How use UTF-8 fonts with gem CombinePDF? - ruby-on-rails

I use gem combine_pdf for load existed pdf file and add some text (in French) to it.
But some specific charactets displaying poorly:
https://drive.google.com/file/d/1LAiK3JJTDjbVpgXrA9ITfCTeYSVws37x/view?usp=sharing
I try:
CombinePDF::Fonts.register_font(Rails.root.join('app/assets/fonts/slick.ttf'), font_metrics, Type: :Font)
font_metrics i take from Helvetica font from initiate_library function (CombinePDF::Fonts).
But it not work... What am I doing wrong?

I had the exact same problem with the combine_pdf gem. I did manage to fix it following the recommendations in the combine_pdf #137 issue.
I created a PDF file with all the characters needed with a font that includes those characters (basically the entire alphabet, including the special characters é à ê as well as € or ' characters).
Register the font as an available font in combine_pdf (e.g. your controller):
fonts = CombinePDF.new(Rails.root.join('lib', 'data','font_template.pdf').to_s).fonts(true)
CombinePDF.register_font_from_pdf_object :new_font, fonts[0]
Set the font setting in your texbox to the new font with font: :new_font (or set it globally in an initialiser).
You can see a full example here in the combine_pdf_demo
The biggest problem for me was to correctly embed the new font in the PDF template. You need to make sure the fonts are actually embedded in the PDF, as sometimes system-fonts don't get properly embedded. Also make sure to include all the characters needed in your text.

Related

Embed Fonts in TCPDF

I have read through previous threads on this topic, but all are old, unanswered, and/or about something more specific about creating custom fonts.
In TCPDF:
$pdf->SetFont('times', '', 10);
The pdfs I create look awesome. It is just that BarnesAndNoble says my submitted PDF does not contain "embedded fonts". Kindle says the same, but that they then embedded them for me. I'm trying LuLu next, but want to deal with BN.com first.
An example suggests:
$fontname = $pdf->addTTFfont('/fonts/arial.ttf', '', '', 32);
... but does not go on to say what to do with "$fontname". Nor what the "32" specifically stands for, or if there are better options for that "32". Or, if THAT does embed fonts!
My webhost says my fonts path is:
/usr/share/fonts/default/Type1
... maybe then (case sensitive??):
/usr/share/fonts/default/Type1/Helvetica
I need to properly embed my fonts!
TCPDF will just automatically embed fonts you've added on its own. I'm fairly certain it's presumed that most all OS's have Times, Helvetica and Courier already available and therefore TCPDF does not embed them. So in your case, if you add a TTF font TCPDF should recognize when it is used and embed the font definition automatically.
Also, you should only have to do $fontname = $pdf->addTTFfont('/fonts/arial.ttf', '', '', 32); once, so you could run your script once, and then comment that line out.
Direct From the documentation;
AddFont( $family, $style = '', $fontfile = '', $subset = 'default' )
Imports a TrueType, Type1, core, or CID0 font and makes it available. It is necessary to generate a font definition file first (read /fonts/utils/README.TXT). The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
Parameters
$family -
Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
$style - Font style. Possible values are (case insensitive):
empty string: regular (default)
B: bold
I: italic
BI or IB: bold italic
$fontfile - The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
$subset - if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
Returns - array containing the font data, or false in case of error.
Since
1.5
See
TCPDF::SetFont(), TCPDF::setFontSubsetting()
Public

Embedding ttf fonts doesn't work perfectly Obj C

I'm trying to embed the Open Sans font family (ttf files) into Obj c. I've added them to my info.plist and I'm able to use some of the fonts, but (for instance) the OpenSans-CondLight.ttf font doesn't show up when I check all the fonts embedded. Anyone got a possible explanation for this? There is nothing wrong with the ttf files.
Yes. Likely the name of the font file is different than the font name itself. I would look for the font name. You can get this by going to the TFF -> Right Clicking -> Get Info -> "Full Name" (See: How do I get the font name from an otf or ttf file?).

iOS ttf fonts only partially work

I need OpenSans in my app and so I imported the whole OpenSans bunch which includes Bold, ExtraBold, Italic, Regular, Light and more. I added them to Fontbook (to check the exact name I need to address them by when using them) on my Mac, to my project in the file structure and added them in Build phases to my project as well.
Now the weird thing; when I use them with UIFont, ONLY OpenSans-Bold works. The rest doesn't work. If I use OpenSans-Bold (exactly the identifier given by Fontbook), everything works fine. If I, however, change it to OpenSans-Regular or OpenSans-Light or something else in that family, I get the systemfont with UIFont and I get nothing when drawing with Quartz.
All fonts are in all lists and I checked all the identifiers from Fontbook (which was why I couldn't get OpenSans-Bold working), but now i'm at a loss. Any idea what I could be doing wrong?
OpenSans Regular is just OpenSans, semi-bold is OpenSans-Semibold, etc.
In Font Book.app select the font and choose Command + I which brings up the font info. In the "PostScript name" in the top you can see what the font is called and how you can call it in your code.
Also, just make sure the font has actually been added in your bundle and your plist :)
You Can check the fonts provided by the ttf file With the following lines of code..
this method is provided by the UIFont class.
(NSArray *)fontNamesForFamilyName:(NSString *)familyName
You need to add the files in the right locations, then in the plist file, then enumerate them all and print them to get the PDF names so you can access them. Most likely you're using the wrong names.
Fonts have three kinds of names:
The file name
The font name in Font Book
The PDF name - this is the one you use to access the font in code
See this answer:
Adding custom fonts to iOS app finding their real names

How to make UILabel contents non localizible when genetating string via ibtool?

I have some labels on my xib. Some of them are not need to be localized. When i generate strings file via ibtool all labels content included in result file.
How can i exclude some UI objects in IB from localization when generate strings?
Unfortunately there is no way to annotate the content of your nib/xib files so that ibtool's --export-strings-file command ignores certain strings.
You could instead opt to use the --export-xliff option and then edit the XLIFF file to lock segments that must not be translated (attribute translate="no") before sending them out to be localized in all your languages. That's probably only worth doing if the localizers use a XLIFF-compatible CAT tool though.

LaTeX: Specifying default document-wide font

For some fonts, it's easy to replace the default font with something like: \renewcommand{\rmdefault}{somefont}.
However, some fonts, like BrushScriptX
want you to use a special command like \bsifamily to use the font. In the
\bsifamily is defined in /usr/share/texmf-texlive/tex/latex/brushscr/pbsi.sty:
\DeclareRobustCommand\bsifamily{\fontencoding{T1}\fontfamily{pbsi}%
\fontseries{xl}\fontshape{n}\selectfont}
In this case, I have a document that uses a cls stylesheet that I am editing. I'm using the standard includes to use this font:
\usepackage[T1]{fontenc}
\usepackage{pbsi}
If I try to use \renewcommand{\rmdefault}{bpsi} in my document's template, it fails with the error: Font shape `T1/pbsi/m/n' undefined
What might be the best way to replace the default roman font with BrushScriptX in a template, like \renewcommand{\rmdefault}{otherfont} would?
If you look inside pbsi.sty you'll find
\DeclareRobustCommand\bsifamily{\fontencoding{T1}\fontfamily{pbsi}%
\fontseries{xl}\fontshape{n}\selectfont}
Therefore, to set this font as the default — ugh :) — you'll need to write
\renewcommand\rmdefault{pbsi}
\renewcommand\mddefault{xl}
(\mddefault is the default "non-bold" series used in running text.)

Resources