Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Aug 30, 2022 6:16 am

Code: Select all
foreach (PdfTextFind find in docPage.Finds)
                    {

                        PdfTrueTypeFont font = new PdfTrueTypeFont(new Font(find.FontName, 8f, FontStyle.Bold));
                        PdfStringFormat stringFormat = new PdfStringFormat() { WordWrap = PdfWordWrapType.None, NoClip = true, };
                        PdfBrush brush = new PdfSolidBrush(Color.Black);
                        RectangleF rect = new RectangleF(find.Position.X,find.Position.Y,find.TextBounds.Max().Width,find.TextBounds.Max().Height+2);
                       
                        if (placeholder.TextFontColor != null)
                            font = new PdfTrueTypeFont(placeholder.TextFont);
                        if(placeholder.TextFontColor != null)
                            brush = new PdfSolidBrush(placeholder.TextFontColor);
                        if (placeholder.WordWrapEnabled)
                            stringFormat = new PdfStringFormat() { WordWrap = PdfWordWrapType.Word, NoClip = true, };

                        find.SearchPage.Canvas.DrawRectangle(PdfBrushes.White, rect);
                        find.SearchPage.Canvas.DrawString(item.Value, font, brush, rect.X,rect.Y, stringFormat, true);
                    }

[img]
Screenshot 2022-08-30 114157.png
[img]
How to resolve the text overlapping the line near to it? In the above image I have marked with red line
[code]/\|<|-|||_[/code]

akhiljksuyati
 
Posts: 3
Joined: Tue Aug 30, 2022 5:56 am

Tue Aug 30, 2022 10:07 am

Hi,

Thanks for your inquiry.
The reason why the text overlaps is that the width of the new text you drawn exceeds that of the original text. You could try to change the DrawString line as below, in which the parameters "rect.X,rect.Y" is changed to rect. It will lead to that the content beyond the rect area will not be drawn. If this can't meet your requirement, please provide your input PDF document for further investigation. You can attach your document here or send it to us via email (support@e-iceblue.com).
Code: Select all
find.SearchPage.Canvas.DrawString(item.Value, font, brush,rect, stringFormat, true);


Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Tue Nov 01, 2022 9:57 am

Hi,

Hope you are doing well!
Has your problem been effectively solved now? Could you give us some feedback at your convenience?

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.PDF