How to preserve text formatting in RichTextBox like Bold, Italics, font color, font size, etc? - vb.net

I have created an application and for that application, I have designed a help file in Microsoft word. The help file is too long. So I decided to use the RichTextBox control in vb.net. I copied all the content from the word file. Now, I need to preserve the text formatting I have done in the actual file (like bold, italics, etc).
How can I preserve the text formatting?
Is there any other way I can display the help file in vb.net with properly formatted text?

RichTextBox supports rtf content, you can't directly paste the Word content in your RichTextBox .
You need to convert the word document into .rtf file. Best way is to
use the save As dialog in Microsoft Word.
Then you could deploy the document with your application and then load rtf content in your RichTextBox using LoadFile method.
RichTextBox1.LoadFile("Help-File.rtf")
Obviously, it supposes that basic formatting like mentioned in title (Bold, Italics, font color, font size, ...) are enough for this purpose, since the rft format does not support all MS Word features.
Otherwise you may have to implement your own parse/interpretation logic.

Here is how I did it:
I converted the word document int rtf format using the save as dialog box in microsoft word. Then copied the file named "help-file.rtf" into the executable folder (the executable is generally present within the debug or Release folder).
Copy the file in rtf format to the application executable folder and then use the following function:
RichTextBox1.LoadFile("Help-File.rtf")
Here, RichTextBox1 is the name of the RichTextBox control. Use the function above to load the file into the RichTextBox control.

Related

Using custom fonts (non-MS Office) for Word VBA

I have installed some custom Asian fonts in the Windows/Fonts folder. I am writing a code that reads some item names (just a plain string, ABC, but in Japanese) from MS-Excel cells, then pastes them in a text box in a new MS-Word document. The problem is that I can't use my custom fonts (these are TTF files) to format the text in MS-Word.
I tried to name the font with .ttf in the end, besides simply referring to its name as it appears in the drop-down menu in MS-Word.
Wrd_Doc.Shapes("shpTwo").TextFrame.TextRange.Font.Name = "ShigotoMemogaki Regular"
It refers to a text box named shpTwo. I pasted some text there and I want it to look like this custom font, named ShigotoMemogaki Regular. This font is saved in my Fonts folder, it works in MS-Word when I use it, but somehow the code does not recognize it, and instead, it uses the default Office Asian font, which is MSMincho.
So the text is clearly copied from MS-Excel, it is in the newly created text box in a new Word document, but it's not in the font I need.

Copy text from PDF with custom FONT

I am trying to copy some text from a PDF. But When I paste it in a word file, it is just some garbage. Something like മുഖവുര. The PDF is in Malayalam language. When I see File->Properties->Fonts, It says BRHMalayalam (Embedded Subset) as shown in the screenshot.
I installed various Malayalam fonts but still no luck. Can anyone please guide me?
The PDF I am trying to copy from is https://drive.google.com/open?id=0B3QCwY9Vanoza0tBdFJjd295WEE&authuser=0
Installing fonts won't help, since they are embedded in the document. The reader will use the ones in the document.
In fact it almost certainly must use the ones on the document, because it will probably have used character codes specific to each font subset.
Your PDF probably has character codes which are not Unicode values, and does not contain ToUnicode CMaps for the fonts in question (note the same font name embedded multiple times). There is no realistic way to copy the text.
The best you can do is OCR it.
After looking at the file, and confirming the answer already given by #KenS, the problem with this PDF document is in fact how it's constructed. Or rather how the font in the document has been embedded.
The document contains a number of Times and Arial fonts, for which the text can be copied successfully. Those fonts are embedded as a subset with a WinAnsi encoding. What is actually in the file is close enough to that, that the text seems to copy out well.
The problem font (BRHMalayalam) is also embedded as a subset, and its encoding is also set as WinAnsiEncoding, which completely doesn't make sense.
And because the font doesn't contain a ToUnicode mapping table, a PDF viewer has no other choice when copying and pasting to assume the characters in the PDF are indeed Win Ansi encoding which means you end up with (garbled) latin characters.
Just convert the pdf file to word file and then edit or copy or modify the text present in the file simple :)
and after completion go to file -> save as -> and change the format of doc to pdf ..hope u understood :)

How to bold a text in PDF?

I'm developing a new function to "my" program. This function is able to write PDF files by the simple way, making a simple text file with some codes of PDF standard.
I'm trying to understand how it works yet, but my first problem is about how to apply bold on some line of my document.
I've already downloaded the PDF REFERENCES GUIDE, but I've not found nothing about it.
Any idea?
PDF is not like HTML where you can apply formatting tags for emphasis. As you've read in the PDF reference, all that you do in PDF is to setup a graphics environment (colours used, fonts used, etc) and then put text on the page.
If you want to have something show in bold, use a font that is bold. If you want to have something show in italic, use a font that is italic.
Older software used dirty tricks to create "bold-alike" text, but the good (and easy) way to do it is to make sure you select the correct font before you start drawing text.

Creating RTF text for clipboard and sharing DataPackage in WinRT

I'm sure this is just a google search away, but I can't find the right search terms to find what I'm looking for.
I've created a DataPackage that has both HTML annd plain text content. I've used this in my copy and my sharing code and it works fine. I now want to create RTF output as some apps don't seem to accept HTML clipboard content.
I'm looking for a good guide to making RTF text that can be added to the DataPackage. I just need simple formatting including changing the font family, font size, font weight and adding newlines. The data comes from a list of objects taht I want to serialise as RTF, not from a text control on the screen.
WordPad outputs fairly clean RTF and some other text editors do as well. If that's not enough, you can download the RTF Specification 1.9.1 although like any specification that's probably overkill for what you're doing.
You can also use the SaveToStream method on the Document property of a RichEditBox from a Metro style app to share out as well.

Programmatically replace text in PDF

I have PDF files with text that should be replaced. More specificly, the text should be translated and replaced with the translated version.
It's important that the rest of the PDF structure stays intact. Note that the text is available in the PDFs and techniques like OCr are not needed. Also, it would be nice if font and other text attributes are kept.
Which libraries would you recommend for extracting the text to an easy to edit format (such as CSV) and put the new text back in again?
Assuming you are replacing text with a different language, you will have to choose a different font in most cases, and the font choice is non-trivial. I've used the Foxit libraries to change text or create PDFs with success.