2

I am having trouble in trying to find the solution for the below described problem.

Annotate the PDF file when user clicks on specific location in pdf and then finaly save the pdf which in future opens at annotated location.

How to approach this?

What I have tried.

  • I have tried to find various libraries irrespective of programming language (since programing language is not the dependency)- found few libraries like minipdf in python, pdfbox in java to mention few relevant ones. Finally selected pdfbox since it seemed to be mature enough to provide the solution closeby.
  • There are various hurdles now how to get user the location clicked by the user? since after getting the location I can able to perform various actions like annotating at the clicked location and then saving the pdf on the same specific location.
  • It seems I have to write whole pdf javascript to approach it but again how to do so?
James Z
  • 12,209
  • 10
  • 24
  • 44
analyticalpicasso
  • 1,993
  • 8
  • 26
  • 45
  • Getting the location can be seen in the source code of PDFDebugger. See in `PagePage.mouseMoved()`, this translates a mouse location into a PDF location. This PDF location can be used for the annotation rectangle. The next thing would be to create an annotation, this can be seen in the `AddAnnotation.java` example in the examples in the source code download. There are many different types of annotations, so your question seems to be a bit broad. – Tilman Hausherr Sep 10 '19 at 11:04
  • @TilmanHausherr For Annotation part I only need to highlight the text. Mostly my requirement lies around that how to save the pdf with annotated content of the user. And then reopen at same location. I was not able to understand the `PagePage.mouseMoved()`. – analyticalpicasso Sep 10 '19 at 11:26
  • Oops, I meant `PagePane.mouseMoved()`, this implements the `MouseMotionListener`, which is a part of java awt. The highlight annotation is shown in the example I mentioned, search for `SUB_TYPE_HIGHLIGHT`. "Reopen at the same location" would be done with `document.getDocumentCatalog().setOpenAction()` combined with a `PDPageFitRectangleDestination`. – Tilman Hausherr Sep 10 '19 at 11:36
  • Alternatively, there is a product by a guy who sometimes hangs around at PDFBox, google for "Annotationeer". I think it is a javascript based solution on top of PDF.js (the viewer distributed with the firefox browser). – Tilman Hausherr Sep 11 '19 at 07:57
  • @TilmanHausherr Ok. I think it is paid product. But I am focussing on opensource libraries. – analyticalpicasso Sep 11 '19 at 08:28
  • @TilmanHausherr Is there any code example that can help me how to use PagePane mouse event for the provided pdf? – analyticalpicasso Sep 11 '19 at 12:26
  • 1
    Not really, PagePane is not API, this is part of PDFDebugger which is an application. You should take the source code and delete what isn't needed. There is also smaller example here on SO on how to display and get coordinates, see the answers to the questions of "John": https://stackoverflow.com/users/11849837/john – Tilman Hausherr Sep 11 '19 at 17:44

1 Answers1

-1

I had similar problem and have solved it the other way. In my case I am not opening PDF in Adobe reader, but in browser. So what I did is converted the pdf to html using python libraries (Let me know if you are interested, I will share different library names with their pros and cons).
Now that html can be edited easily. We can put hyperlinks, highlights everything there as source code is with us.
This workaround may be applicable to you if your front end is web based.


PS: Wanted to post this workaround as comment, but couldn't due to little less reputation count as of now. Hope, it won't be downmarked :)

Sandeep Bhutani
  • 589
  • 7
  • 23