- 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:
Veritical Text can't mark correct.
How can get position of Veritical Text?
Data test: