PDFBOX API中是否有任何函数可以使文本合理,或者我们必须手动执行?如果手动然后如何使用java(其背后的逻辑)证明文本
我正在使用iTextSharp从特定矩形内的pdf中获取数据
在高度的情况下获取的数据工作正常但在宽度的情况下,它返回整行而不是矩形中的单词.
我使用的代码如下:
PdfReader reader = new PdfReader(Home.currentInstance.Get_PDF_URL());
iTextSharp.text.Rectangle pageRectangle = reader.GetPageSize(currentPage);
float selection_x = ((float)(selectionRectangle.RenderTransform.Value.OffsetX) / (float)canvas.Width) * pageRectangle.Width;
float selection_y = pageRectangle.Height - (((float)(selectionRectangle.RenderTransform.Value.OffsetY) / (float)canvas.Height) * pageRectangle.Height);
float selection_height = ((float)(selectionRectangle.Height) / (float)canvas.Height) * pageRectangle.Height;
float selection_width = ((float)(selectionRectangle.Width) / (float)canvas.Width) * pageRectangle.Width;
selection_y -= selection_height;
RectangleJ rect = new RectangleJ(selection_x,selection_y,selection_width,selection_height);
RenderFilter[] filter = { new RegionTextRenderFilter(rect) };
ITextExtractionStrategy strategy;
strategy = new FilteredTextRenderListener(
new LocationTextExtractionStrategy(), filter
);
String pageText = PdfTextExtractor.GetTextFromPage(reader, currentPage, strategy);
Run Code Online (Sandbox Code Playgroud)
任何帮助将受到高度赞赏.
提前致谢
我试图使用此处的代码从PDF文件中提取文本.该代码使用zlib库.
AFAICT程序的工作原理是在pdf文件中找到文本"stream"和"endstream"的出现之间的内存块.然后通过zlib对这些块进行充气.
代码在一个示例pdf文档上完美地工作,但在另一个上,zlib的inflate()函数每次调用时都会返回-3(Z_DATA_ERROR).
我注意到,失败的pdf文件被设置为在Adobe Reader中打开时没有"复制"选项.这可能与inflate()错误有关吗?...如果是,是否有解决问题的办法?
下面的代码片段 - 请参阅注释
//Now use zlib to inflate:
z_stream zstrm; ZeroMemory(&zstrm, sizeof(zstrm));
zstrm.avail_in = streamend - streamstart + 1;
zstrm.avail_out = outsize;
zstrm.next_in = (Bytef*)(buffer + streamstart);
zstrm.next_out = (Bytef*)output;
int rsti = inflateInit(&zstrm);
if (rsti == Z_OK)
{
int rst2 = inflate (&zstrm, Z_FINISH); // HERE IT RETURNS -3
if (rst2 >= 0)
{
//Ok, got something, extract the text:
size_t totout = zstrm.total_out;
ProcessOutput(fileo, output, …Run Code Online (Sandbox Code Playgroud) 我已经通过Java和PDF论坛从pdf文件中的表中提取文本值,但除了JPedal(它不是开源和许可)之外找不到任何解决方案.
所以,我想知道任何开源API,如pdfbox,itext,以实现与JPedal相同的结果.
参考.例:
