如何在android中为pdf查看器制作注释,如突出显示、删除线、下划线、绘制、添加文本等?

发布于 2025-01-02 09:22:38 字数 429 浏览 3 评论 0原文

  • 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?
    enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执笔绘流年 2025-01-09 09:22:39

您的问题似乎是允许用户在 android/java 中对 PDF 文件进行注释的方法是什么,所以这里有一种适合您的方法,尽管它可能不是最好的解决方案。

我想指出的是,实际上并不需要仅仅为了允许用户添加和查看注释而编辑实际的 PDF 文件。您的应用程序可以单独存储注释数据,为每个文件存储这些注释,并在加载文件时加载它们。

这意味着它不会创建一个带有注释的新 PDF 文件,而只会存储加载到应用程序中的每个 PDF 文件的用户数据,并在用户再次加载 PDF 文件时显示该数据。 (所以它似乎被注释了)。

示例:

  1. 读取 PDF 文件文本、文本格式设置和将图像导入您的应用程序
  2. 显示文档(如文字处理器)
  3. 允许用户编辑和编辑注释文档
  4. 保存更改并保存应用程序中的注释数据(不是 PDF 文件)
  5. 再次加载文件时,应用更改并添加注释。之前存储的注释。

您的注释类可能看起来像这样:

class Annotations implements Serializable {

    public Annotations() {
        annotations = new HashSet<Annotation>();
    }

    public ArrayList<Annotation> getAnnotations() {
        return new ArrayList<Annotation>(annotations);
    }

    public Annotation annotate(int starpos, int endpos) {
        Annotation a = new Annotation(startpos, endpos);
        annotations.add(a);
        return a;
    }

    public void unannotate(Annotation a) {
        annotations.remove(a);
    }

    static enum AnnotationTypes {
        HIGHLIGHT, UNDERLINE;
    }

    class Annotation {
        int startPos, endPos;
        AnnotationTypes type;
        Color color;
        Annotation(int start, int end) {
          startPos = start;
          endPos = end;
        }
        public void update(int start, int end) {
          startPos = start;
          endPos = end;
        }
        public void highlight(int red, int green, int blue) {
            type = AnnotationTypes.HIGHLIGHT;
            color = new Color(red, green, blue);
        }
        public void underline(int red, int green, int blue) {
            type = AnnotationTypes.UNDERLINE;
            color = new Color(red, green, blue);
        }
        // getters
        ...
    }

    private Set<Annotation> annotations;
}

因此,您只是在此处存储注释显示数据,当您加载文件及其各自的(序列化)Annotations 对象时,您可以使用每个注释来影响在文档中的 startPosendPos

虽然我使用了 int 来表示两个位置 startPosendPos,但您也可以使用两个或多个变量来引用数组索引, 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:

  1. Read PDF file text, text-formatting & images into your app
  2. Display a document (like a word-processor)
  3. Allow the user to edit & annotate the document
  4. Save changes & annotation-data in your app (not the PDF file)
  5. When loading the file again, apply changes & annotations previously stored.

Your annotation class might look something like this:

class Annotations implements Serializable {

    public Annotations() {
        annotations = new HashSet<Annotation>();
    }

    public ArrayList<Annotation> getAnnotations() {
        return new ArrayList<Annotation>(annotations);
    }

    public Annotation annotate(int starpos, int endpos) {
        Annotation a = new Annotation(startpos, endpos);
        annotations.add(a);
        return a;
    }

    public void unannotate(Annotation a) {
        annotations.remove(a);
    }

    static enum AnnotationTypes {
        HIGHLIGHT, UNDERLINE;
    }

    class Annotation {
        int startPos, endPos;
        AnnotationTypes type;
        Color color;
        Annotation(int start, int end) {
          startPos = start;
          endPos = end;
        }
        public void update(int start, int end) {
          startPos = start;
          endPos = end;
        }
        public void highlight(int red, int green, int blue) {
            type = AnnotationTypes.HIGHLIGHT;
            color = new Color(red, green, blue);
        }
        public void underline(int red, int green, int blue) {
            type = AnnotationTypes.UNDERLINE;
            color = new Color(red, green, blue);
        }
        // getters
        ...
    }

    private Set<Annotation> annotations;
}

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 and endPos in your document.

Although i've used ints for the two positions startPos and endPos, 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.

一影成城 2025-01-09 09:22:39

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文