We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Highlight Text for Portrait PDF

Thread ID:

Created:

Updated:

Platform:

Replies:

146455 Aug 2,2019 05:53 PM UTC Aug 5,2019 12:49 PM UTC WinForms 1
loading
Tags: PDF
Yogesh vasu
Asked On August 2, 2019 05:53 PM UTC

Hello all,

while highlighting the text in existing pdf using C# platform  i am facing issue of highlightion which highlights text vertically.

i have tried in all possible ways could you please anyone help me how to highlight text horizontally for portrait pdf




PdfLoadedDocument document = new PdfLoadedDocument(@"d:\LocalData\z015266\Desktop\OneDrive_1_30-07-2019\Updated\AA30-AC.PDF");
                PdfDocument pdfDoc = PdfDocument.Merge(null, document) as PdfDocument;
                
                //Gets the first page from the document
                
                float width = pdfDoc.Pages[0].Size.Width;
                float height = pdfDoc.Pages[0].Size.Height;
                if (pdfDoc.Pages[0].Rotation == PdfPageRotateAngle.RotateAngle90 ||
                    pdfDoc.Pages[0].Rotation == PdfPageRotateAngle.RotateAngle270)
                {
                    width = pdfDoc.Pages[0].Size.Height;
                    height = pdfDoc.Pages[0].Size.Width;
                }

                if (width > height)
                {
                    pdfDoc.Sections[0].PageSettings.Orientation = PdfPageOrientation.Portrait;
                }
                else
                {
                    pdfDoc.Sections[0].PageSettings.Orientation = PdfPageOrientation.Landscape;
                    pdfDoc.Sections[0].PageSettings.Size = new SizeF(width, height);
                }

                //Add a list to maintain extracted text information
                List<TextData> extractedText = new List<TextData>();
                //Extract text from first page
                pdfDoc.Sections[0].Pages[0].ExtractText(out extractedText);
                //for (var yu = 0; yu < arrvalues_smipp.Length; yu++)
                //{
                foreach (TextData textData in extractedText)
                {
                    if (textData.Text == "F261")
                    {
                        PdfGraphics graphics = pdfDoc.Pages[0].Graphics;
                        Font font = new Font("Calibri", 10, FontStyle.Bold);
                        PdfFont pdfFont = new PdfTrueTypeFont(font, false);
                        PdfSolidBrush brush = new PdfSolidBrush(Color.DarkGreen);
                        PdfPen pen = new PdfPen(PdfBrushes.DarkMagenta, 5f);
                        float x_coordiante = textData.Bounds.Location.X - 3;
                        float y_coordinate = textData.Bounds.Location.Y - 10;
                        float width1 = textData.Bounds.Size.Width;
                        float height1 = textData.Bounds.Size.Height;
                        RectangleF rectangle = new RectangleF(x_coordiante, y_coordinate, width1, height1);
                        PdfTextMarkupAnnotation textmarkup = new PdfTextMarkupAnnotation("", "", textData.Text, new PointF(x_coordiante, y_coordinate), pdfFont);
                        textmarkup.TextMarkupColor = new PdfColor(Color.LightPink);
                        textmarkup.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight;
                        textmarkup.Rotate = PdfAnnotationRotateAngle.RotateAngle180;
                        pdfDoc.Sections[0].Pages[0].Annotations.Add(textmarkup);



                    }
                }

                pdfDoc.Save("HighlightText.pdf");
                pdfDoc.Close(true);
                Process.Start("HighlightText.pdf");


Thanks and Regards,
Yogesh

highlights


Sowmiya Loganathan [Syncfusion]
Replied On August 5, 2019 12:49 PM UTC

Hi Yogesh, 

Thank you for contacting Syncfusion support.  

We have checked with the issue which you have mentioned with the provided code snippet, but in our end the text is highlighted as horizontal only. So we suspect that this to be a document specific issue, so could you please share the input PDF file which you have used in your end. It will helpful for us to provide the precise solution on this. 

Regards, 
Sowmiya L 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon