Programing

PDF 뷰어를 위해 Android에서 강조 표시, 취소 선, 밑줄, 그리기, 텍스트 추가 등과 같은 주석을 만드는 방법은 무엇입니까?

lottogame 2020. 11. 6. 07:48
반응형

PDF 뷰어를 위해 Android에서 강조 표시, 취소 선, 밑줄, 그리기, 텍스트 추가 등과 같은 주석을 만드는 방법은 무엇입니까?


  • Android 시장의 RepliGo, Aldiko, Mantano, ezPdf와 같은 많은 응용 프로그램은 아래 이미지에 표시된 PDF 뷰어에서 이러한 유형의 주석을 만듭니다.
  • 이 주석을 구현하기 위해 여러 가지 방법을 시도했지만 실패했습니다. 나는 안드로이드 용 pdf 뷰어와 선 그리기를 위해 iText를 사용하는 주석을위한 별도의 Java 코드가 있습니다.
  • 내 질문은 안드로이드에서 iText를 구현할 수 있습니까? 가능하다면 어떤 패키지를 가져와야합니까?
  • 또한 일부 응용 프로그램에서는 캔버스 방법이 선을 그리는 데 사용됩니다. 주석을 사용하는 대신 Android에이 캔버스 메서드를 포함 할 수 있습니까? 목표는 주석과 동일한 기능을 갖는 것입니다.
  • 아래 이미지 (RepliGo PDF Reader)에서 주석에 어떤 종류의 코드를 사용 했습니까? 여기에 이미지 설명 입력

귀하의 질문은 사용자가 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;
}

따라서 여기에 주석 표시 데이터 만 저장하고 파일과 해당 (직렬화 된) 주석 객체를로드 할 때 각 주석을 사용 하여 문서 startPos사이에 문자를 표시하는 방법에 영향을 줄 endPos수 있습니다.

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.


Pdf-annotation is an open source and good point to start with https://code.google.com/p/pdf-annotation/

참고URL : https://stackoverflow.com/questions/9156727/how-to-make-annotation-like-highlighting-strikethrough-underline-draw-add-te

반응형