RichEditBox loses formatting for empty text - xaml

I have something like a diagramming UWP application where each shape has an RichEditBox. The problem is, that I loose the formatting when the text is empty.
For Example:
Change the text to bold: EditBox.Document.Selection.CharacterFormat.Bold = FormatEffect.On.
Delete all text
Get the text via "EditBox.Document.GetText(GetTextFormat.FormatRtf, out text);
=> The result is just an empty string, not valid RTF document at all. This is a problem in my scenario. Is there an approach to solve it? I think RichEditBox should always provide a valid RTF document.

Related

Using formatted text from Word table to Publisher

I'm trying (and failing) to fill out a text box (TextFrame) in Publisher using a macro from content in a Word table. I'm trying to do something along the lines of:
With doc.Pages(1).shapes(1)
.GroupItems.Item(8).TextFrame.TextRange = table.Cell(2, 3).Range.FormattedText
End With
The source text from table has a bunch of font formatting that I need in the text box but it won't seem to be able to copy over the formatting and I just get the plain text. Any ideas on how to get this working properly?
Edit: It seems like TextFrame can't accept formatted text at all. Is there any way around this?
In Word TextFrame.TextRange returns a range which has a FormattedText property. The usage for that would be:
.GroupItems.Item(8).TextFrame.TextRange.FormattedText = table.Cell(2, 3).Range.FormattedText
In your code you haven't specified which property of the TextRange you want to assign the formatted text to. This means it will be assigned to the default property, Text, which is just a string and cannot contain any formatting.
Golden Rule: never rely on default properties, always specify the
property you want to use.
Given that you appear to be taking a value from Word into Publisher you should be looking at the documentation for VBA in Publisher which shows you that the TextRange object in Publisher does not have a FormattedText property, so you cannot take formatting across using this method.

How to get the text written in a Plain Text Content Control in Word via VBA

I still haven't understood how to use VBA in Word. I have a Plain Text Content Control, where our employees will write some text. This text will be added to an email. But how do I get this text? I would like something like this:
preparerText = ActiveDocument.ContentControls("PreparerText").Range.Text
But it doesn't work.
I have tried to Google how to do this, but cannot find an answer (or perhaps the answer is there, but I just don't understand how to use it in my context)
Information about the content control I want to get text from:
Provided your content controls have unique titles it can be as simple as:
preparerText = ActiveDocument.SelectContentControlsByTitle("PreparerText")(1).Range.Text

Libre Office Labels don't show up as "AcroFields" in iTextSharp?

so I've been trying to generate a report. I've tried quite a few things already but there always seems to be problems. I'm currently trying iTextSharp 4.1.6.
My current strategy is to use LibreOffice to create a document with editable pdf fields, or I guess they are called "AcroFields". I'm not sure since I can't find a definition. But anyways, I assume that all of these are "AcroFields":
But if I put all of those into a form and export as pdf only some of them show up as AcroFields:
var reader = new PdfReader(File.ReadAllBytes("abc.pdf"));
foreach(var field in reader.AcroFields.Fields)
{
Console.WriteLine(((DictionaryEntry)field).Key);
}
> Text Box 1
Check Box 1
Numeric Field 1
Formatted Field 1
Date Field 1
List Box 1
Combo Box 1
Push Button 1
Option Button 1
Notice how Label Field 1 is not present. If it were present then doing a text replace might be easy. Except it's not present so it's looking like even iText can't do a simple text replace in a pdf. Is this true? How would you replace text in a pdf document using iTextSharp?
Notice how Label Field 1 is not present.
As there is no AcroForm form field type "label", form labels usually are drawn as regular page content in PDF files.
If it were present then doing a text replace might be easy. Except it's not present so it's looking like even iText can't do a simple text replace in a pdf. Is this true?
Indeed, in general there is no simple text replacement in a PDF.
How would you replace text in a pdf document using iTextSharp?
I would determine the bounding box coordinates of the text to replace using the iText text extraction feature with some extension that returns text plus coordinates. Then I'd remove that text by redaction using iText's PdfCleanUp... classes. Finally I'd add the replacement text as new text in the bounding box determined at start.
Unfortunately for you, both good text extraction and redaction are not present in your version 4.1.6; for this approach you should update at least to 5.5.x.
Alternatively, though, as you've been trying to generate a report, I assume the template design is in your hands. In that case you can put your labels into read-only text fields which you can change (they are read-only only to GUI users).

How to retain Colors in my Richtextbox even after Replacing

I have Richtexbox with some texts and markup tags, i color it based on the Tags to different colors in form load, coloring of texts/tags works fine,
Problem now is when i tried to replace some Text inside My RTFbox, after coloring, the Color seems to vanish everywhere,
I want to retain all the coloring's i did even after any kind of replacements/Editing's in richtextbox, kindly help
When you delete the text during the replace, you also delete and formatting the text contained. The inserted text will default to whatever style is set for the area it's being inserted. If you want to retain the styling, you will have to get the current styling of the text and save it in memory, and then apply it to the new text you're inserting, something like this:
RichTextBox1.Select(0, 5)
Dim txtStyle As Font = RichTextBox1.SelectionFont
Then you can apply txtStyle to whatever text you're inserting/replacing the old stuff with

vb parse word from clipboard into html

I want to copy some word text with tables, links and images and paste it into a rich textbox in my vb project. Where I want to parse it to html.
The Questenion is, how can access the copied word in the clipboard. Using
My.Computer.Clipboard.GetText()
just returns text, without the structure for links, tables or images. But there have to be a way to access it, because my rich textbox seems to know the word format. When I paste it into it, tables, images and links are also displayed in there.
You can try to specify text format in GetText's parameter as follow :
Dim htmlText As String = Clipboard.GetText(TextDataFormat.Html)