Bob*_*oid 69 java pdf android pdf-generation pdf-annotations
你的问题似乎是允许用户在android/java中注释PDF文件的方法,所以这里有一种方法,虽然它可能不是最好的解决方案.
我想指出,实际上不需要编辑实际的PDF文件只是为了允许用户添加和查看注释.您的应用程序可以单独存储注释的数据,存储每个文件的注释,并在加载文件时加载它们.
这意味着它不会创建带有这些注释的新PDF文件,而是只存储加载到应用程序中的每个PDF文件的用户数据,并在用户再次加载PDF文件时显示.(所以它似乎是注释的).
例:
您的注释类可能如下所示:
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;
}
Run Code Online (Sandbox Code Playgroud)
因此,您只需在此处存储注释显示数据,并在加载文件及其各自(序列化的)注释对象时,可以使用每个注释来影响在文档中startPos
和endPos
文档之间显示字符的方式.
虽然我用int
S表示两个位置startPos
和endPos
,您也可以使用两个或多个变量来引用数组索引,SQLite数据库表索引,简单的文本文件的字符位置; 无论您的实现是什么,您都可以更改它,以便您知道从哪里开始注释以及在何处结束使用该AnnotationType进行注释.
此外,您可以设置属性更改侦听器,以便在更改注释属性时触发更新显示/视图的方法.
归档时间: |
|
查看次数: |
8916 次 |
最近记录: |