Missing character in custom font - itext

We are using iTextSharp to create PDF's using a custom font and I am running into an issue with the unicode character 2120 (SM, Service Mark). The problem is the glyph is not in the custom font. Is there a way I can specify a fallback font for a field in a PDF? We tried adding a text field with Verdana so that the form had the secondary font embedded in it but that didn't seem to help.

First you need to find a font (ttf, otf,...) that has the character you need. Then you can use the FontSelector class and add the different fonts you want to use to this selector (see the FontSelectionExample). Now you can process every string:
FontSelector selector = new FontSelector();
selector.addFont(f1);
selector.addFont(f2);
Phrase ph = selector.process(some_string);
The FontSelector will return a phrase that consists of Chunks with font f1 for all the glyphs that are available in the first font, and Chunks with font f2 for the glyphs that couldn't be font in f1, but that are present in f2.
If you want the C# port of this example, please consult chapter 11.
Update
Using a FontSelector also works in the context of forms (as long as we're talking about AcroForm technology). It's really easy: you just need to add substitutions fonts to the form:
AcroFields form = stamper.getAcroFields();
form.addSubstitutionFont(bf1);
form.addSubstitutionFont(bf2);
Now the font defined in the form has preference, but if that font can't show a specific glyph, it will look at bf1, then at bf2 and so on. You can find an example demonstrating this functionality here.
Note that there's a difference between the first and the second example. In the first example we use a Font object, in the second, we use a BaseFont object.

Related

Where can I get a Font-family to language pair map for Microsoft Word

I am programmatically generating a MSWord 2011 bilingual file(contains text from 2 languages) using docx4j. My plan is to set the font-family of text based on the language in the text. eg: When I have a Latin and Indian language passed, all text containing English will have 'Times New Roman' and Hindi as 'Devanagari' as their font type.
MS Word documentation doesn't have any information on this. Any help to find a list of all prominent languages MS-Word supports and their corresponding Font-Families appreciated.
The starting point is the rFonts element.
As it says:
This element specifies the fonts which shall be used to display the
text contents of this run. Within a single run, there may be up to
four types of content present which shall each be allowed to use a
unique font:
• ASCII
• High ANSI
• Complex Script
• East Asian
The use of each of these fonts shall be determined by the Unicode
character values of the run content, unless manually overridden via
use of the cs element
For further commentary and the actual algorithm used by docx4j (in its PDF output), which aims to mimic Word, see RunFontSelector
To simplify a bit, you need to work out which of the 4 attributes Word would use for your Hindi (from its Unicode character values), then set that attribute to the font you want.
You can set the attribute to an actual font name, or use a theme reference (see the RunFontSelector code for how that works).
If I were you, I'd create a docx in Word which is set up as you like, then look at its underlying XML. If it uses theme references in the font attributes, you can either use the docx you created as a template for your docx4j work, or you can manually 'resolve' the references and replace them with the actual font names.
If you want to programmatically reproduce what Word has created for you, you can upload your docx to the docx4j webapp to generate suitable code.
Finally, note that the fonts need to be available on the computer opening the docx. (Unless the fonts are embedded in the docx) If they aren't, another font may be substituted.

iText -- How do I identify a single font that can print all the characters in a string?

This is wrt iText 2.1.6.
I have a string containing characters from different languages, for which I'd like to pick a single font (among the registered fonts) that has glyphs for all these characters. I would like to avoid a situation where different substrings in the string are printed using different fonts, if I already have one font that can display all these glyphs.
If there's no such single font, I would still like to pick a minimal set of fonts that covers the characters in my string.
I'm aware of FontSelector, but it doesn't seem to try to find a minimal set of fonts for the given text. Correct? How do I do this?
iText 2.1.6 is obsolete. Please stop using it: http://itextpdf.com/salesfaq
I see two questions in one:
Is there a font that contains all characters for all languages?
Allow me to explain why this is impossible:
There are 1,114,112 code points in Unicode. Not all of these code points are used, but the possible number of different glyphs is huge.
A simple font only contains 256 characters (1 byte per font), a composite font uses CIDs from 0 to 65,535.
65,535 is much smaller that 1,114,112, which means that it is technically impossible to have a single font that contains all possible glyphs.
FontSelector doesn't find a minimal set of fonts!
FontSelector doesn't look for a minimal set of fonts. You have to tell FontSelector which fonts you want to use and in which order! Suppose that you have this code:
FontSelector selector = new FontSelector();
selector.addFont(font1);
selector.addFont(font2);
selector.addFont(font3);
In this case, FontSelector will first look at font1 for each specific glyph. If it's not there, it will look at font2, etc... Obviously font1, font2 and font3 will have different glyphs for the same character in common. For instance: a, a and a. Which glyph will be used depends on the order in which you added the font.
Bottom line:
Select a wide range of fonts that cover all the glyphs you need and add them to a FontSelector instance. Don't expect to find one single font that contains all the glyphs you need.

store and fetch bold/italic font from sqlite database

I tried by make Excel file & import as a csv file in sqlite. But it shows me in normal font rather than bold or italic font.
In my app, I uses the sqlite database and fetches data from it. I want to display some text in italic font,How can i do that??
Does Sqlite supports Italic?
yOu should store data with rules, as in case html we store it as <b>topic/b><i>this is topic</i> i mean by adding proper tagging before save.
I am not share about ios or xcode how but you should add some extra information to text before saving the text.
When you read bold text, you are interpreting a "strong" meaning. This strong meaning can be emphasized in a number of different ways (for instance, all caps: BOLD). Your text shouldn't contain information about how the information is presented (style), but it SHOULD contain information about the meaning (structure). Keeping these two separate gives you more flexibility to change how the text is presented if, say, you wanted to change your website template or application design. You could choose to display strong text as bold, all caps, all caps and underlined, etc. on a whim.
I recommend some subset of HTML, as it is structural by nature and very widely used. In HTML, the bold tag exists (<b>; however, it is stylistic, so the <strong> tag is recommended to encode the strong meaning instead).
Databases don't support encoding; however, you can encode the text yourself before sticking it in the database. Here is an example of an HTML-encoded string:
<p><strong>An HTML-encoded string</strong> inside a paragraph.</p>
When you extract it, you could choose to represent the strong text as bold:
An HTML-encoded string inside a paragraph.
Or as CAPS:
AN HTML-ENCODED STRING inside a paragraph.
Or even italic caps:
AN HTML-ENCODED STRING inside a paragraph.
There are many other ways to encode structure, including Mark Down (I believe that's what StackOverflow uses).
where you want to display it? in some label , textfiled or some other? change font type there where you want to display it
For example if you want to display it in UILable
then change the font type of UILabel
[<lblname> setFont:[UIFont boldSystemFontOfSize:<whatever_you_want>]];
It's your bad logic to fetch bold text from database.
Enjoy Programming

Eclipse BIRT Report Designer paragraph style different

Let's say I have a bunch of paragraphs coming from a Word file. These paragraphs have different styles applied to them (some are bold, some have smaller or bigger font size, some are italicized, different color, different font-family and so on). Is it possible to add all of these paragraphs into the same Text element in birt and apply the styles that correspond to each paragraph or do I really have to put each paragraph separately into its own Text element and then apply the style to each Text element in birt? Obviously the second approach is more tedious, I would love to find a solution similar to the first approach.
You can set the text element content as RTF and apply Paragraph Formatting Tags .
Take a look at this document for more information.

How to draw Thai text to PDF file by using libharu library

i am using free pdf library libharu to generate PDF file,
but i have a encoding problem, i can not draw Thai lanugage text on PDF file,
all the text shows "???.."
Somebody know how to fix it?
Thanks
I have succeeded in rendering hieroglyphic texts (not Thai, but Chinese and Japanese) using libharu. First of all, I used Unicode mode, please refer to HPDF_UseUTFEncodings() function documentation.
For C language, here is a sequence of libharu API calls needed to overcome your trouble:
HPDF_UseUTFEncodings(docHandle);
HPDF_SetCurrentEncoder(docHandle, "UTF-8");
Here docHandle is a valid HPDF_Doc object.
Next part is proper work with UTF fonts:
const char * libFontName = HPDF_LoadTTFontFromFile(docHandle, fontFileName.c_str(), font_embed::EmbedFonts);
HPDF_Font font = HPDF_GetFont(docHandle, libFontName, "UTF-8");
After these calls you may render unicode texts containing Thai characters. Also note about embedding flag (3rd param of LoadTTFontFromFile) - your PDF file may be unreadable due to external font references. If you are not crazy with output PDF size, you may just embed fonts.
I've tested couple of Thai .ttf fonts found in Google and they were rendered OK. Also (it may be important, but I'm not sure) I'm using fork of libharu https://github.com/kdeforche/libharu which is now merged into master branch.
When you write text to the PDF, use the correct font and encoding. In the libharu documentation you have all the possibilities: https://github.com/libharu/libharu/wiki/Fonts
In your case, you must use the ISO8859-11 Thai, TIS 620-2569 character set
An example (in spanish):
HPDF_Font fontEn = HPDF_GetFont(pdf, "Helvetica-Bold", "ISO8859-2");
HPDF_Page_TextOut(page1, 50.00, 750.00, [#"Código para correcta codificación en libharu" cStringUsingEncoding:NSISOLatin1StringEncoding]);