This is a migrated thread and some comments may be shown as answers.

Underline and Strikethrough support for BLOCK

2 Answers 401 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
jaipal
Top achievements
Rank 1
jaipal asked on 20 Apr 2018, 07:26 PM

Greetings All,

Is there any way that the text that i am entrering into Block can be formated for Underline and Strikethrough .

 

I was able to achieve other properties like Bold , Italix with statements like 

block testblock =testCell.Blocks.AddBlock();

testblock. TextProperties.Font = FontsRepository.TimesItalic;

 

 

2 Answers, 1 is accepted

Sort by
0
Anna
Telerik team
answered on 24 Apr 2018, 12:58 PM
Hello,

You can add underline to the text using the TextProperties property like so:

block.TextProperties.UnderlinePattern = UnderlinePattern.Single;
block.TextProperties.UnderlineColor = new RgbColor(0, 0, 0);

Strikethrough is currently not supported, and I am going to add it to our backlog. You can find the item in our Feedback and Ideas Portal here, and you can upvote and subscribe to it, in order to receive notifications about any developments.

Regards,
Anna
Progress Telerik

0
Luk
Top achievements
Rank 1
Iron
answered on 06 Oct 2023, 01:15 PM | edited on 06 Oct 2023, 01:33 PM

Hello,

We also struggle with Strikethrough property, already voted up for PdfProcessing: Add support for strikethrough text property 

I have some temporary solution for all of you who have similar use case to us. We work on prepared docx template which we need to fill up and modify. Let say we have some choice to make in our document:

option1/option2*
* strikethrough unnecessary

Our solution is to wrtite in docx:

option1option1/option2option2* (I use underline here instead of strikethrough because this editor does not allow it)

And set the bookmarks (bkm1nost => bookmark 1 no strikethrough):

<bkm1nost>option1</bkm1nost><bkm1st>option1</bkm1st>/<bkm2nost>option2</bkm2nost><bkm2st>option2</bkm2st>*

Then you need function like this:

static void DecideAboutStrikethrough(RadFlowDocumentEditor editor, string bookmarkNameNotST, string bookmarkNameST, bool useStrikethrough, int runCount)
        {
            if (useStrikethrough)
            {
                BookmarkRangeStart bookmarkStart = editor.Document.EnumerateChildrenOfType<BookmarkRangeStart>().FirstOrDefault(rangeStart => rangeStart.Bookmark.Name == bookmarkNameNotST);

                if (bookmarkStart != null)
                {
                    Paragraph paragraph = bookmarkStart.Paragraph;
                    int bookmarkIndex = paragraph.Inlines.IndexOf(bookmarkStart);
                    for (int i = 1; i <= runCount; i++)
                    {
                        if (paragraph.Inlines[bookmarkIndex + i] is Run run)
                        {
                            run.Text = "";
                        }
                    }
                }
            }
            else
            {
                BookmarkRangeStart bookmarkStart = editor.Document.EnumerateChildrenOfType<BookmarkRangeStart>().FirstOrDefault(rangeStart => rangeStart.Bookmark.Name == bookmarkNameST);

                if (bookmarkStart != null)
                {
                    Paragraph paragraph = bookmarkStart.Paragraph;
                    int bookmarkIndex = paragraph.Inlines.IndexOf(bookmarkStart);
                    for (int i = 2; i <= runCount +1; i++)
                    {
                        if (paragraph.Inlines[bookmarkIndex + i] is Run run)
                        {
                            run.Text = "";
                        }
                    }
                }
            }
        }

And in our case if we want to strikethrough option1:

DecideAboutStrikethrough(editor, "bkm1nost", "bkm1st", true, 1);
DecideAboutStrikethrough(editor, "bkm2nost", "bkm2st", false, 1);

Some pieces of explain to DecideAboutStrikethrough function:
1. There is a for loop with runCount beacuse in our case we have "option1" like "some text with spaces" and we need to make blank more than one Run between bookmark start and bookmark end.

2. There is strange behave in such case <bkm1nost>option1</bkm1nost><bkm1st>option1</bkm1st>. The Inlines of paragraphs are in order:

1 bkm1nost start
2 run -> option1
3 bkm1st start
4 bkm1nost end
5 run -> option1 (with strikethrough)
6 bkm1st end

The start of 2nd bookmark is before 1st bookmark end. Because of that in else block of useStrikethrough we have shift by 1 in line:

for (int i = 2; i <= runCount +1; i++)

The solution may seem primitive, but it works. I can imagine another solution where we have strikethrough text with bookmark and we can use Run.Clone(document) of that strikethrough text. I think Run will keep its format so we can Clone it everywhere in our document, and make blank the original bookmark at the end. Correct me if I am wrong.

EDIT:
If Run does not keep the format, we can Clone parent object of this Run which does keep the format. I did not test such a solution, but I think it could work.

Yoan
Telerik team
commented on 11 Oct 2023, 08:49 AM

Hello Luk,

I followed the provided instructions, managed to replicate the described results, and can confirm that the solution indeed works and can be used as a workaround if the user sees fit.

Thank you for your time and effort. Your feedback is greatly appreciated and does not go unnoticed.

Regards,

Yoan

Tags
PdfProcessing
Asked by
jaipal
Top achievements
Rank 1
Answers by
Anna
Telerik team
Luk
Top achievements
Rank 1
Iron
Share this question
or