如何在 c# .net 中使用 pdfbox 获取 pdf 中的特定位置词
How to get particular position words in pdf using pdfbox in c# .net
我在 pdfbox 中遇到了一些问题。
我无法在输入的位置输入特定的单词(例如 x=20,y=30,height=100,width=100
)
我如何从特定区域获取单词。
终于找到答案了。它工作正常。
public static void ReadCooridinates(string sourceFilePath)
{
using (PDDocument pDDocument = PDDocument.load(sourceFilePath))
{
PDPage page = new PDPage();
java.util.List allPages = pDDocument.getDocumentCatalog().getAllPages();
page = (PDPage)allPages.get(0);
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition(true);
Rectangle rect = new Rectangle(10, 200, 100, 30);
stripper.addRegion("class1", rect);
stripper.extractRegions(page);//Assign the page to read the coordinates
Console.WriteLine("\nText in the area:" + rect + "\n");
Console.WriteLine(stripper.getTextForRegion("class1"));
}
}
我在 pdfbox 中遇到了一些问题。
我无法在输入的位置输入特定的单词(例如 x=20,y=30,height=100,width=100
)
我如何从特定区域获取单词。
终于找到答案了。它工作正常。
public static void ReadCooridinates(string sourceFilePath)
{
using (PDDocument pDDocument = PDDocument.load(sourceFilePath))
{
PDPage page = new PDPage();
java.util.List allPages = pDDocument.getDocumentCatalog().getAllPages();
page = (PDPage)allPages.get(0);
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition(true);
Rectangle rect = new Rectangle(10, 200, 100, 30);
stripper.addRegion("class1", rect);
stripper.extractRegions(page);//Assign the page to read the coordinates
Console.WriteLine("\nText in the area:" + rect + "\n");
Console.WriteLine(stripper.getTextForRegion("class1"));
}
}