WPF RichTextBox does not show proper fonts - c#

I am creating a small tool like text editor. I am fetching fonts from system and applying to text written on editor.
string fontName = (string)Fonttype.SelectedItem;
RichTextControl.Selection.ApplyPropertyValue(
System.Windows.Controls.RichTextBox.FontFamilyProperty, fontName);
But font installed like STMSaradha.ttf(Bengali font) won't show properly on RichTextBox, some text will get combined and don't show properly. Any suggestions?
Screenshot:

Related

How to apply custom font icon shapes in UWP

I want to show some custom shapes through font icons in my UWP project. I have created my own .ttf file for custom shapes. But I don't know how to apply it programmatically.
TextBlock text = new TextBlock();
string font = "Assets/mycustomfont.webfont.ttf#MyCustomFont";
text.FontFamily= new Windows.UI.Xaml.Media.FontFamily(font);
this.grid1.Children.Add(text);
Anyone please help me on this.
The approach you are using is practically correct, but make sure to check the following:
The .ttf file must be included in the project and have Build Action set to Content in the Properties window
Start the path to the font with / to make sure it begins in root.
Ensure the # suffix actually matches the font metadata. A font viewer app like dp4 Font Viewer can help you with that. Use the Font Family name as the suffix.
I have written an article on my blog about using custom fonts in UWP so check it out to see if you haven't missed some of the steps there.

.Net Datagridview does not display emoji

My datagridview displays a string containing emoji that's blanked out:
However, when I cut and paste over to MS Word, it displays correctly:
I thought it's a font issue, but changing fonts to not avail. Any ideas?

How to strike out the texts in Paragraph?

I am developing an app for Windows 8.1
The App parses HTML codes, and displays the contents on RichTextBlock.
Anyway, I'm trying to display some texts with 'StrikeThrough' line. like shown below.
I searched through the web, but I just found that there is no native way to do that on WIndows 8.1
I tried the solution on 'StrikeThrough effect on a TextBlock', but I don't think this solution can display some texts which exceed the width of RichTextBlock (I need those texts to be displayed in new line.)
Also, I don't display texts on TextBlock directly,
In my app, texts are displayed like below
RichTextBlock - Paragraph - Run (Texts)
Is there any good solution for this problem?
(The easiest way to display 'Strikeout texts' on RichTextBlock)
Thanks in advance.
Add this to your text
TextBlock1.TextDecorations = TextDecorations.Strikethrough;

Get Images count and positions from Rtf using C#

I have some RTF text. Sometimes text contain some images. Images is displayed inside any rtf editor, but i cannot get images positions programmatically.
I have used RichTextBox control for RTF parsing, but is unable to detect image positions inside text in RichTextBox control
So, does anybody know how to parse RTF and get images positions inside text programmatically using C#?
You might take a look at http://www.codeproject.com/KB/string/nrtftree.aspx it is open source and able to extract images, so I hope this helps.

Replace text in PDF

I'm trying to replace a section of a PDF with different text. From research on all major PDF libraries for .NET, it seems this is complicated and not a trivial task. I think it may be easier to convert the PDF to an image, replace the text (always in the same place), then convert it back to a PDF (or leave it as an image if converting back isn't possible). Is it possible to extract an image from a PDF page with .NET?
If your text is in a known location, you can simply cover it with a rectangle filled with the background color, and then draw your text over top.
Note that the text will still be there, it simply won't be visible. Someone selecting text will still pick up the old stuff. If that's acceptable, it's quite trivial.
If the PDF was created from image, you can import it into Photoshop to edit it as an graphic. Or you can use screenshot program like "Snagit" to capture pdf page as image and use snagit's editor to erase old text and replace new one.
But this method may bring you problem is that the new added text may not the same font as text around it. Personally, I use pdf editor to replace text in pdf since the added text will be automatically fit with the original font and size.

Categories