2017-12-28 11 views
1

저는 PdfTron SDK를 사용하고 있습니다. 사용자가 확대 한 후에 주석을 그려야합니다. 주석은 책의 측면에 있어야합니다 (세 번째 그림) 그러나 우리가 확대 할 때 그것은 책의 중앙에 그림을 그립니다 (그림 1과 그림 2). 줌안드로이드 - PDFTron - 줌 모드에서 주석을 그려야합니다.

예 (잘못된 상태) : 줌없이

enter image description here

enter image description here

예 (오른쪽 상태) : 지금 내가 해요

enter image description here

기능을 사용하여 convPagePtToScreenPt하지만 사용자가 확대를하지 않는 것만으로 주석을 제대로 그릴 수 있습니다. 어떤 함수가 사용하고 있다고 생각하는 사람이 있습니까? 다음 코드는 모든 페이지 상단에서 1 인치의 오른쪽에 주석을 배치합니다

public synchronized void drawAnnotation(AnnotationData annotationData){ 

    if (annotationData == null) { 
     return; 
    } 


    AnnotationType annotationType = annotationData.getType(); 

    if (annotationType == null) { 
     return; 
    } 

    ToolManager.Tool tool = mToolManager.createTool(ToolManager.e_text_annot_create, null); 
     if (tool instanceof StickyNoteCreate) { 
      StickyNoteCreate annotStickyCreate = (StickyNoteCreate) tool; 
      Point point; 
      double[] pts; 
      double[] ptsForScreenSize = {0, 0}; 
      int orientation = mContext.getResources().getConfiguration().orientation; 
      if (mPDFView != null) { 
       if (orientation == Configuration.ORIENTATION_PORTRAIT) { 
        ptsForScreenSize = mPDFView.convScreenPtToPagePt((double) BookReader.SCREEN_WIDTH, (double) BookReader.SCREEN_HEIGHT, annotationData.getPage()); 
       } else { 
        ptsForScreenSize = mPDFView.convScreenPtToPagePt((double) BookReader.SCREEN_HEIGHT, (double) BookReader.SCREEN_WIDTH, annotationData.getPage()); 
        if (!TextUtils.isEmpty(annotationData.getStartLoc()) && !TextUtils.isEmpty(annotationData.getEndLoc()) && mPDFView != null) { 
         //if we have an annotation for text 
         pts = mPDFView.convPagePtToScreenPt(annotationData.getStartX(), annotationData.getStartY(), annotationData.getPage()); 
        } else { 
         //if we have an annotation for Page 
         pts = new double[]{0, 0}; 
        }     
        ptsForScreenSize = mPDFView.convPagePtToScreenPt(ptsForScreenSize[0] - INT_ANNO_PADDING, ptsForScreenSize[1], annotationData.getPage()); 
        final AnnotationData noteTextHighlight = new AnnotationData(annotationData); 
        //we don't need to set UniqueId for this highlight annotation 
        noteTextHighlight.setUniqueId(null); 
        highlightSelectedText(noteTextHighlight); 
        double marginY = BookReader.SCREEN_HEIGHT * 0.015; 
        point = new Point(ptsForScreenSize[0], pts[1] + marginY); 
        annotStickyCreate.createNoteIconOnPage(annotationData, point); 
       } 
      } 
    }  
} 


    public void createNoteIconOnPage(AnnotationData annotationData, Point noteIconPoint) { 
    KsLog.d("IsBookReaderAviliable","createNoteIconOnPage : " + BookReader.isBookReaderVisible()); 
    if(BookReader.isBookReaderVisible()){ 
     try { 
      mPDFView.docLock(true); 
      PDFDoc pdfDoc = mPDFView.getDoc(); 
      double[] pts = mPDFView.convScreenPtToPagePt(noteIconPoint.x, noteIconPoint.y, annotationData.getPage()); 
      Point p = new Point(pts[0], pts[1]); 
      com.pdftron.pdf.annots.Text text = com.pdftron.pdf.annots.Text.create(pdfDoc, p); 
      text.setUniqueID(annotationData.getUniqueId()); 
      //creating the annotation appearance - icon 

      // Let's create an appearance for the annotation using an image 
      ElementBuilder builder = new ElementBuilder(); 
      ElementWriter writer = new ElementWriter(); 
      writer.begin(pdfDoc); 

      Image image = Image.create(pdfDoc, annotationData.getDrawable()); 

      int w = image.getImageWidth(), h = image.getImageHeight(); 

      Element element = builder.createImage(image, 0, 0, w, h); 

      writer.writePlacedElement(element); 

      writer.writeElement(builder.createTextBegin(Font.create(pdfDoc, Font.e_times_roman), 12)); 

      writer.writeElement(element); 
      writer.writeElement(builder.createTextEnd()); 

      Obj appearance = writer.end(); 
      appearance.putRect("BBox", 0.1, 0.1, w, h); 
      text.setAppearance(appearance); 

     /* 
     The left icons spouse to be bigger the the regular icons 
     */ 
      if (annotationData.getType() == AnnotationData.AnnotationType.LINK && (annotationData.getShard() == AnnotationData.LEFT_LINK_A || annotationData.getShard() == AnnotationData.LEFT_LINK_B)) { 
       text.setRect(new Rect(pts[0], pts[1], pts[0] + 30, pts[1] + 30)); 
      } 

      if (annotationData.getType() == AnnotationData.AnnotationType.NOTE) { 
       text.setContents(AnnotationData.NOTE_TYPE_CONTENTS); 
      } else if (annotationData.getType() == AnnotationData.AnnotationType.LINK) { 
       text.setContents(AnnotationData.LINK_TYPE_CONTENTS); 
      } 

      KsLog.d("createNoteIconOnPage","getPage() " + annotationData.getPage()); 
      Page page = pdfDoc.getPage(annotationData.getPage()); 
      if (page != null) { 
       page.annotPushBack(text); 
      } 


      mAnnotPushedBack = true; 
      mAnnot = text; 
      mAnnotPageNum = annotationData.getPage(); 
      KsLog.d("createNoteIconOnPage","mDownPageNum " + mAnnotPageNum); 

      buildAnnotBBox(); 
      mPDFView.update(mAnnot, mAnnotPageNum); 
      raiseAnnotationAddedEvent(mAnnot, mAnnotPageNum); 

     } catch (Exception ex) { 
      Log.e(PDFTronReader.TAG, ex.toString()); 
      mNextToolMode = ToolManager.e_pan; 

     } finally { 
      mPDFView.docUnlock(); 

     } 
     mPDFView.waitForRendering(); 
    } 
} 
+0

주석을 페이지에 추가하는 데 사용할 코드를 게시 할 수 있습니까? 또한 오른쪽에 배치 할 x, y 값을 포함하십시오. 이 좌표는 어떻게 결정합니까? – Ryan

+0

안녕하세요. Ryan, 내 게시물을 편집합니다. 확인해주세요. –

+0

설명을 명확히하기 위해 주석을 처음 추가 할 때 페이지의 오른쪽에 있습니다. 원하는 위치에 있습니다. 그런데 확대하면 페이지 중앙으로 "이동"됩니까? 그때부터 항상 같은 위치에 있습니까? 아니면 도약을 계속합니까? 처음 두 스크린 샷에서 주석은 같은 위치에 있습니다. – Ryan

답변

0

:

이 내 코드입니다.

Matrix2D mtx = page.getDefaultMatrix(true).inverse(); 
double x1 = page.getPageWidth() - 25; // this is the width as the a user sees it (rotated). 20 is the width of a Text annotation 
double y1 = 72; // not clear how you decide the vertical placement. In this example, this 1 inch from the top as the user views the page. If you have the value from the bottom, switch the boolean value argument in GetDefaultMatrix 
mtx.mult(ref x1, ref y1); 
com.pdftron.pdf.Annots.Text txt = com.pdftron.pdf.Text.create(doc, new Point(x1, y1)); 
page.annotPushBack(txt); 

코드와 관련하여 화면 및 페이지 좌표에 혼란이있는 것으로 보입니다. 예를 들어, 한 줄의 ptsForScreenSizeConvScreenPtToPagePt의 결과를 전달하고 다른 줄에서 ConvPagePtToScreenPt의 결과를 전달합니다.

+0

내 대답을 시험해 볼 기회가 있었습니까? – Ryan

관련 문제