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.

Mon May 24, 2021 2:35 am

This code add a Rectangle to Text:

Code: Select all
   string strPDF = @"G:\PDF ExtractText\verticaltext.pdf";
            Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
            doc.LoadFromFile(strPDF);
            List<Spire.Pdf.General.Find.PdfTextFindCollection> collections = new List<Spire.Pdf.General.Find.PdfTextFindCollection>();
            foreach (PdfPageBase page in doc.Pages)
            {
                PdfTextFindCollection collection = page.FindAllText();
                collections.Add(collection);
            }
            PdfPageBase p = doc.Pages[0];

            foreach (PdfTextFindCollection collection in collections)
            {
                foreach (PdfTextFind find in collection.Finds)
                {

                    PointF point = find.Position;
                    SizeF sizeText = find.Size;
                    string str = find.MatchText;                 

                   
                    Spire.Pdf.Graphics.PdfGraphicsState state = p.Canvas.Save();
                    //draw rectangles
                    Spire.Pdf.Graphics.PdfPen pen = new Spire.Pdf.Graphics.PdfPen(Color.Red, 0.1f);
                    int w = (int)Math.Round(sizeText.Width);
                    int h = (int)Math.Round(sizeText.Height);
                    p.Canvas.DrawRectangle(pen, new System.Drawing.Rectangle(new System.Drawing.Point((int)Math.Round(point.X), (int)Math.Round(point.Y)), new Size(w, h)));

                    //restor graphics
                    p.Canvas.Restore(state);
                   
                }
            }
            doc.SaveToFile(strPDF + "_mark.pdf");
        }


Result:
spire_rect.PNG


Veritical Text can't mark correct.
How can get position of Veritical Text?

Data test:
verticaltext.zip

daitranthanhhoa
 
Posts: 51
Joined: Mon Sep 19, 2016 3:04 am

Mon May 24, 2021 8:17 am

Hello,

Thanks for your inquiry.
I tested your scenario and indeed observed the behavior that the rectangle to Vertical Text can't be marked correctly. I have posted it to our Dev team with the ticket SPIREPDF-4322 and they will investigate further. If there is any update, we will let you know. Apologize for the inconvenience caused.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Thu Jul 22, 2021 11:59 am

Hello,

Greetings from E-iceblue!
Glad to inform you that we just released Spire.PDF Pack(Hot Fix) Version:7.7.10 which fixes the issue SPIREPDF-4322, please download it from the following links to test on your side. Looking forward to your test result.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.PDF/7.7.10

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF