Formatting Field values using itextsharp - itext

how can i have a string format "i am fine here" using itextsharp
fields.SetField("tgPara2", message2);
where message is "i am fine here" i want the fine word only to be bold.
Any help would be

iText has partial support for "rich text values" for text fields. You can get and set the rich values, but iText won't actually draw those values properly. You need to turn off SetGenerateAppearances, and open the PDF in Acrobat/Reader to see the rich text.
This means flattening isn't going to work (unless you open the PDF in Acrobat, then save it again... clunky).
You might want to check out the PDF Specification (Section 12..7.3.4 Rich Text Strings) for further information on what is and isn't legal. <b> is legal, as is the font-weight CSS style

Related

Copy formatted text to clipboard

A simple html page has FORMATTED text - not fancy - line breaks, and italic.
I want to have a button that takes this formatted text, and copies it to the clipboard, formatted (it is planned to be pasted into some LibreOffice document later).
Couldn't find how to do it.
I tried ZeroClipboard, and a suggestion to parse the text, replacing ""-s to "\r\n". That indeed does the trick for line breaks, but what about italic?... Any means to get this functionality?...
When you create an italic tag the responsible for formatting the document and showing the text properly is the browser. If you want to copy the text you should get the text already parse and render by the browser or parse yourself the text like you did with break lines. For italics when you find a ... tag you must create the adequate text. That is, text in italics, but that depends on the language you are using, but i'm sure it can be done.
OK,
Turns out that ZeroClipboard had this functionality (of rendering the HTML text upon paste), but have disabled it.
However, the version that supports it can be found at: https://github.com/botcheddevil/ZeroClipboard
Note:
You may find that in this version, creating the client, binding the flash to a component, and handling the events are rather different than the documentation of current version of ZeroClipboard (https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md

Formatting PHP code for Epub in MS Word

I'm trying to format the PHP code sections of a 700+ page book for Epub conversion. If I use soft returns at the end of the code lines, they get eaten. If I use hard returns (making each line a paragraph), I either get too much space between the lines, or not enough before and after the code section. If I add an empty line before and after the code section, it gets eaten.
There are thousands of lines of code in the book. Is there some way to handle this without manually editing the html file?
Is there some common format for these code section like being wrapped with PHP tags?
If they are PHP tags you can use this, which will wrap each tag set with a :
function fixPHPcode($matches)
{
return '<p class="php_code">' . $matches[0] . '</p>';
}
$data = preg_replace_callback('/<\?php(.|\s)+?\?>/i', 'fixPHPcode', $data);
I did try some fairly complex regex transforms, but I've found an easier method that actually works fairly well.
The secret is to create a style based on Word's "HTML Preformatted" style, or if you don't have that style, a style based on Normal that specifies Arial Unicode MS or Courier New as the font, with no proofing, left justified.
Indent with spaces and use soft returns (shift-enter) at the end of each line.
Calibre will produce acceptable Epub and Mobi versions of this. Courier is a crap font for code, but at least it's monospaced so the indents will line up, and people are used to seeing it as a code font.

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

Crystal Reports Formula to parse RTFtext based on font format ie Bold and Italic

I have a column of RTF data that looks like the following:
The terms or definitions to be used in this document are:
Daily Operator. Used when the user is.......etc..
Using crystal reports I would like to grab just the BOLD text using a formula or equivalent.
I keep getting the RTF markup instead of standard text. Here is an example that I used to grab first 10 characters.
DIM convertedText as String
convertedText = cstr({table.DefinitionRTF})
FORMULA = MID(convertedText, 1, 10).
Looking ahead a bit more, how would one determine where the bold or italic Starts. Can you check for crBOLD and return the characters index position?
Thanking all in advance.
No, Crystal does not have the built-in commands to parse RTF objects by font properties. The purpose of Crystal Reports is to present formatted reports (and it more or less does this job very well). Sorry, but it's definitely not made to be a RTF parser.
I recommend doing this with some other tool, for example, a VBA script in MS Access that imports the RTF and parses it using the MS Word API. Probably wouldn't be that difficult.

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]);