- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人知道某种(免费)SDK 可以在 PDF 文档中超链接将您带到的位置(在同一 PDF 文档中)开始文本提取吗?这些链接最终会将我们带到特定页面上的特定点。
更具体地说,我们需要一个程序来解析包含测试问题和答案(以及每个问题/答案的相关注释)的 pdf 文档,并仅将我们需要的相关部分导出到文本文件。
基本上,PDF 文档在文档的开头有测试问题,每个问题中都有一个超链接,指向它的答案和 PDF 文档另一部分的相关注释。
附言- 使用以下语言之一:C++、Java、VB.net、C#.net、javascript附言- 仅限免费软件
最佳答案
这比听起来难 - 您可能需要重新考虑您的问题。文档内超链接通常是通过链接注释完成的,其中目标设置为“Goto View”操作。该 View 不一定包括边界甚至点。有时它只是一页(当前缩放)或一页(适合宽度)或一页(在顶部,特定缩放)。它甚至比这更复杂,因为链接目标可能是一棵按顺序执行的操作树,每个操作都是 18 种不同的可能操作类型之一,包括可用于驱动查看者前往特定目标的 javascript。
我想您也会遇到“链接指向您的地方”的问题。
您可以使用 Atalasoft dotAnnotate 和 PDF 文本提取插件在 C# 中完成很多此类任务(免责声明,我在 Atalasoft 工作,编写了 PDF->annotations 导入器,并且曾经在 Acrobat v 1 上为 Adobe 工作, 2, & 3).不,很抱歉,它不是免费软件。
这是我的做法(免责声明 - 这就在我的脑海中):
class PageAnnots : KeyValuePair<int, List<PdfLinkData>> { }
public PageAnnots GetPageLinkDestinations(Stream stm)
{
PdfAnnotationDataImporter importer = new PdfAnnotationDataImporter(stm);
List<PageAnnots> pageAnnots = new List<PageAnnots>();
try {
importer.Load();
// this gets all annotations on all pages. On long docs, this will be time consuming
AnnotationDataCollection allAnnots = importer.Import();
int pageNo = 0;
// allAnnots is a collection of LayerData, each LayerData object being a collection
// of annots for a page. The collection is empty if there are no annots
foreach (AnnotationData pageOfAnnots in allAnnots) {
List<PdfLinkData> linkAnnots = new List<PdfLinkData>();
LayerData pageLayer = pageOfAnnots as LayerData;
if (pageLayer != null) {
// filter out each annot that is a link
foreach (AnnotationData annot in pageLayer.Items) {
PdfLinkData link = annot as PdfLinkData;
if (link != null)
linkAnnots.Add(link);
}
}
if (linkAnnots.Count > 0) {
pageAnnots.Add(new PageAnnots(pageNo, linkAnnots));
}
pageNo++;
}
}
catch (Exception err) {
// keep it? drop it?
}
return pageAnnots;
}
此时,我们已将其简化为键值对的集合,每个键都是一个页码,每个值都是代表该页面上链接的 PdfLinkData 对象的非空列表。
从那里,您可以迭代这个集合并尝试像这样找出目的地:
private int PageFromDestination(PdfDestination dest)
{
PdfIndexedPageReference pageRef = dest.Page as PdfIndexedPageReference;
return pageRef == null ? -1 : pageRef.PageIndex;
}
public void FigureDestination(PdfLinkData link)
{
PdfActionList actions = link.ClickAction;
foreach (PdfAction action in actions) {
PdfGoToViewAction gotoView = action as PdfGoToViewAction;
if (action == null)
continue;
// this only pulls the page from the destination. The dest
// may also contain information about the view. I'm assuming you
// only want the page number
int page = PageFromDestination(gotoView.Destination);
if (page >= 0) {
// here's where you step in - the click action could be
// a long chain of things including several GoToView actions.
// it's up to you to decide what you want to do. Handle only
// action lists of length 1? Stop at first GoToView?
// aggregate them all?
}
}
}
当您查看这段代码时,您会想知道为什么在索引页面引用、操作类型和操作列表方面存在这种抽象级别?答案是 GoToView 操作也可以引用另一个文档 - 跨文档链接在 PDF 中有效。虽然 dotAnnotate 现在不支持它们,但它准备在未来支持它们。同样,该操作可能指示转到嵌入式 PDF 文档中的 View (是的,您可以在 PDF 中嵌入 PDF)。
您需要注意,dotAnnotate 为您提供了一组有限的相当高级的对象,并不要求您了解和理解 PDF 规范(太多)。过去,我们曾尝试将非常精细的 API 发布到 TIFF 之类的东西中,但发现我们的客户并不喜欢它们。因此,我们试图猜测我们的客户可能想要和需要什么,并创建更容易理解的 API。
iText 和 iTextSharp 为您提供了对 API 的非常精细的级别控制,但您需要了解 PDF 规范以获得您需要的内容。
例如,要进行注释提取,您必须打开文档,获取页面目录,遍历页面树,找到所有具有 Annots 键的页面字典,遍历 Annots 数组,搜索其中的每个字典对于具有值/Annot 的键/Type 和对于具有值/Link 的键/SubType,然后提取键/Dest 的值(如果存在)并且如果该值不为空则使用该值,否则查看键/A 和开始遍历操作树以查找键/Type 设置为/GoTo (IIRC) 的操作,然后从那里开始。
目的地可以是直接目的地,也可以是命名目的地。如果它是一个命名的目的地,你将不得不回到文档目录并拉出名称树并在命名的目的地中搜索名称,当你找到它时,拉出那里的信息。
是的,您可以使用 iText 或其他类似的 PDF 解析器,但您需要执行所有这些步骤,除非库创建者中的一位好心地为您完成了这些。
关于在超链接位置提取 PDF 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3992993/
我的代码有一些问题。我正在尝试遍历包含许多 PDF 的 Drive 文件夹,然后将它们合并为一个文件。当我使用我的代码时,它只是为 Drive 文件夹中的最后一个 PDF 创建一个 PDF,而不是按预
我从 PDF Specification 获取了 PDF 规范中的最小 PDF 示例。 ,将其复制到记事本,将文件重命名为扩展名为 .pdf。 我可以用其他 PDF 查看器(PDF-XChange、S
感谢您在以下方面的帮助: 我有 2 个部分可访问的 PDF(包含标签),我想使用一些命令行工具(如 PDFtk 或 Ghostscript,或任何 Perl 模块)将它们连接起来: 我已经尝试使用 P
我想使用 ghostscript 将矢量 pdf 转换为光栅 pdf(即光栅化矢量 pdf)。但是即使我添加了解析参数 -r300,我也找不到合适的参数来执行此操作。 我使用的代码是-dSAFER -
我无法在 FAQ 中找到这个功能是否存在于 API 中,尽管它在书中提到作为潜在可用的东西。有没有人有任何实现此功能的经验? 最佳答案 在 This thread (日期为 2007 年 6 月)Pa
我要放文件sample.pdf在我的网站上,并希望使用 pdf.js 显示它.我想要的是显示我自己的文件,如 demo ,带有工具栏,放大/缩小等。到目前为止,我还不能这样做。 我确实检查了 hell
我知道这可能不是严格意义上的编程问题(也许是,我不知道)但我在尝试转换常规 pdf(带有超链接、书签、图像、嵌入字体等)时遇到了严重问题.) 转换为 PDF/A-1 格式。 当我用 pdfaPilot
这是 PDF.js 网站 https://github.com/mozilla/pdf.js 我正在搜索和阅读很多文章,大多数编码都是将 pdf 导入 pdf.js 并在浏览器上显示,我不明白是不是
谁能建议我如何将扫描图像转换为可搜索图像或如何将扫描 pdf 转换为可搜索 pdf? 很长一段时间以来,我一直陷入这种情况。 我已经在 ubuntu 中尝试过 pdfocr 应用程序,但没有成功。 最
作为我对客户端/服务器 pdf 签名研究的一部分,我测试了 itext pdf 延迟签名示例。不幸的是,我生成的 pdf 即合并空签名 pdf 和哈希值的输出显示无效签名。 我的代码片段如下 cla
我想将一个 PDF 页面插入到另一个已缩放的 PDF 页面中。我想使用 iTextSharp 来实现此目的。 我有一个矢量绘图,可以导出为单页 PDF 文件。我想将此文件添加到其他 PDF 文档的页面
作为我对客户端/服务器 pdf 签名研究的一部分,我测试了 itext pdf 延迟签名示例。不幸的是,我生成的 pdf 即合并空签名 pdf 和哈希值的输出显示无效签名。 我的代码片段如下 cla
我想为 Kindle 转换电子书。我尝试使用 Calibre 将具有复杂格式样式和图像的基于两种语言的基于文本的大型 PDF 电子书转换为适用于 Kindle 的 AZW3 电子书,并且还尝试了亚马逊
我在 Google Chrome 中显示 pdf 时遇到问题。问题是 Chrome 将 pdf 的某些页面显示为黑色。 启用 Chrome PDF 查看器时会发生这种情况。如果我禁用此插件并使用 Ad
我确信这个问题无处不在,尽管我似乎找不到答案。我希望我的 PDF 文档在 PDF 阅读器中显示时没有空白页,但随后在封面后打印空白页,这样打印出来的文档在右侧甚至左侧都有奇数页。还有其他人遇到过这个问
我需要自动裁剪 pdf 文件(去除白边)。到目前为止,我尝试了两种并不完美的工具: pdf裁剪 问题:它不会裁剪某些 pdf。 pdf-crop-margins 问题:有时它裁剪得太多(精细的细节)。
This PDF由几个源文件组成。其中五个是包含 alpha channel 的 PNG。一种是没有 alpha channel 的 PNG。最后一 block 是带有透明效果的 Photoshop
我的团队将内部 wiki 页面用于各种内容。这些页面是使用 MediaWiki 创建的。我想知道是否有任何方法可以将 wiki 页面转换为 PDF 格式。我必须用它来将用户文档转换为 PDF 格式,以
我希望能够从我可能在数据库或 xml 或任何其他结构化形式中拥有的数据生成高度图形化(也包含大量文本内容)的 PDF 文件。 目前,我们的平面设计师在将内容作为 MS Word 文档后,在 Photo
我正在寻找可以帮助我找到重复 PDF 的实用程序。问题:我有 1000 个 PDF 文件。有些是重复的。由于不同的文件名和文件大小的微小差异,它们不容易被检测到。是否有实用程序/算法/库可以帮助我找到
我是一名优秀的程序员,十分优秀!