如何在android中为pdf查看器制作注释,如突出显示、删除线、下划线、绘制、添加文本等?
- Android 市场中的许多应用程序(如 RepliGo、Aldiko、Mantano、ezPdf)在其 pdf 查看器中都进行了此类注释,如下图所示。
- 我尝试了很多方法来实现这个注释,但都失败了。我有一个适用于 android 的 pdf 查看器和单独的 java 代码,用于使用 iText 绘制线条进行注释。
- 我的问题是我可以在 android 中实现 iText 吗?如果可以的话,我必须导入哪个包?
- 此外,在某些应用程序中,画布方法用于绘制线条。是否可以在android中包含这个canvas方法而不是使用注释?目标是拥有与注释相同的功能。
- 在下图中(RepliGo PDF Reader)他们使用哪种代码进行注释?
- Many applications like RepliGo, Aldiko, Mantano, ezPdf in android market make this type of annotation in their pdf viewer shown in the below image.
- I tried in many ways to implement this annotation but I failed. I have a pdf viewer for android and separate java code for annotations using iText for drawing lines.
- My question is can i able to implement iText in android. If it's possible, which package do I have to import?
- Also in some applications, a canvas method is used for drawing lines. Is it possible to include this canvas method in android instead of using an annotation?. The goal would be to have the same features that annotations have.
- In the below image (RepliGo PDF Reader) which kind of code did they use for annotations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题似乎是允许用户在 android/java 中对 PDF 文件进行注释的方法是什么,所以这里有一种适合您的方法,尽管它可能不是最好的解决方案。
我想指出的是,实际上并不需要仅仅为了允许用户添加和查看注释而编辑实际的 PDF 文件。您的应用程序可以单独存储注释数据,为每个文件存储这些注释,并在加载文件时加载它们。
这意味着它不会创建一个带有注释的新 PDF 文件,而只会存储加载到应用程序中的每个 PDF 文件的用户数据,并在用户再次加载 PDF 文件时显示该数据。 (所以它似乎被注释了)。
示例:
您的注释类可能看起来像这样:
因此,您只是在此处存储注释显示数据,当您加载文件及其各自的(序列化)Annotations 对象时,您可以使用每个注释来影响在文档中的
startPos
和endPos
。虽然我使用了
int
来表示两个位置startPos
和endPos
,但您也可以使用两个或多个变量来引用数组索引, SQLite 数据库表索引、简单文本文档的字符位置;无论您的实现是什么,您都可以更改它,以便您知道从哪里开始注释以及在哪里结束使用该 AnnotationType 的注释。此外,您可以设置属性更改侦听器,以便当注释属性更改时,它们会触发方法来更新您的显示/视图。
Your question seems to be what are methods to allow users to annotate over a PDF file in android/java, so here is one method for you, although it may not be the best solution.
I'd like to point out that it is not actually necessary to edit the actual PDF file just to allow users to add and view annotations. Your application could just store the data for annotations separately, store those annotations for each file, and load them when the file is loaded.
That means it won't create a new PDF file with those annotations placed it, but instead it will just store user-data for each PDF file which is loaded into your app, and display that when the user loads the PDF file again. (So it appears to be annotated).
Example:
Your annotation class might look something like this:
So you're just storing the annotation-display data here, and when you load the file and its respective (serialized) Annotations object, you can use each annotation to affect how you display characters between the
startPos
andendPos
in your document.Although i've used
int
s for the two positionsstartPos
andendPos
, you could also use two or more variables to refer to array indexes, SQLite database table indexes, char positions for simple text documents; whatever your implementation is you could just change that so that you know where to start annotating and where to end annotating with that AnnotationType.Also, you could set up property change listeners so that when the annotation properties are changed they fire off methods to update your display/view.
Pdf-annotation 是一个开源项目,最好从 https://code.google.com 入手/p/pdf-注释/
Pdf-annotation is an open source and good point to start with https://code.google.com/p/pdf-annotation/