Hi,
You can use “
PdfTextFinder” class to find text of checkbox and get position of the text, I put the relevant code below for your reference.
- Code: Select all
// Create a PdfDocument object
PdfDocument pdfDocument = new PdfDocument();
// Load the PDF document from file
pdfDocument.LoadFromFile(@"../../data/Spire_Pdf.pdf");
// Get the first page of the PDF document
PdfPageBase pdfPageBase = pdfDocument.Pages[0];
// Create a PdfTextFinder object to find text within the PDF page
PdfTextFinder pdfTextFinder = new PdfTextFinder(pdfPageBase);
// Find text fragments containing "Check Box 1"
List<PdfTextFragment> pdfTextFragments = pdfTextFinder.Find("Check Box 1");
// Iterate through the found text fragments
foreach (PdfTextFragment pdfTextFragment in pdfTextFragments)
{
// Get the position and size information of the text fragment
System.Drawing.RectangleF rectangleF = pdfTextFragment.Bounds[0];
// Output the X-coordinate of the text fragment
Console.WriteLine(rectangleF.X);
// Output the Y-coordinate of the text fragment
Console.WriteLine(rectangleF.Y);
}
Besides, after fixing the issue with SPIREXLS-5196, you can use “
pdfImageHelper” class to get image and the position of the image of checkbox.
- Code: Select all
// Create a PdfDocument object
PdfDocument pdfDocument = new PdfDocument();
// Load the PDF document from file
pdfDocument.LoadFromFile(@"../../data/Spire_Pdf.pdf");
// Get the first page of the PDF document
PdfPageBase pdfPageBase = pdfDocument.Pages[0];
// Create a PdfImageHelper object
PdfImageHelper pdfImageHelper = new PdfImageHelper();
// Use the GetImagesInfo method of the PdfImageHelper object to get the image information on the PDF page, and store the result in an array of PdfImageInfo
PdfImageInfo[] pdfImageInfos = pdfImageHelper.GetImagesInfo(pdfPageBase);
// Iterate through each element in the PdfImageInfo array
foreach (PdfImageInfo pdfImageInfo in pdfImageInfos)
{
// Output the X-coordinate of the current image
Console.WriteLine(pdfImageInfo.Bounds.X);
// Output the Y-coordinate of the current image
Console.WriteLine(pdfImageInfo.Bounds.Y);
}
Sincerely
Abel
E-iceblue support team