简体   繁体   中英

Editing PDF in browser and save it to server Java

I have PDF documents which needs to be displayed in browser. PDF contains blue print of a building. I achieved this using iText Java library. Now, I want to edit the PDFs while viewing in the browser. (Editing - drawing/deleting circles, lines in PDF). I need to save the edited PDF to server also.

I searched and all are saying examples for interactive FORM fields using iText. Is the above scenario possible in iText or please suggest some library to implement this feature.

Edited:

As per my understanding, PDFTron library allows to draw a circle/line and allows to delete the circle/line drawn on PDF in iOS/Android platforms.

Scenario:

1) First PDF will be shown to user 2) Users can able to draw a circle/line on PDF and that PDF will be saved in server 3) Next time, users can see the existing circle/line drawn and if user wants, he will be able to delete the already drawn circle/line on PDF. Final PDF needs to saved.

Could anyone please tell me how to support this feature in Browsers using iText.

[disclaimer: I work for PDFTron, and saw this question because of the PDFTron tag in the question, and mention of PDFTron in question itself.]

First, is it important to clarify difference between Content and Annotations, with regards to PDF. You can add lines and circles as either Content or Annotation. However, Content is very difficult to make interactive in any graphical user situation, and even the best PDF viewers provide very little in this regards. On the other hand Annotations are very easy to add/edit/delete.

I assume your blue print drawing has been added as "Content", and not as "Annotation".

So, if by

"Editing - drawing/deleting circles, lines in PDF"

you mean the existing blue print lines/circles in the PDF Contents, then this is very difficult to, and is covered by the comments to your question.

However, if you mean New lines/circles that are added as Annotations , then yes, you can do this (add/edit/delete) in any modern web browser using PDFTron WebViewer.

1) First PDF will be shown to user 2) Users can able to draw a circle/line on PDF and that PDF will be saved in server 3) Next time, users can see the existing circle/line drawn and if user wants, he will be able to delete the already drawn circle/line on PDF. Final PDF needs to saved.

Yes, with PDFTron WebViewer, all the above steps are easy to do.

I did a high level version of this. I used Kinetic JS to draw shapes and add text area. There are samples available on the internet. You can try it out.

I just extracted the image from the pdf and showed it in a pop up window where the users could add annotations and had a save button. When the user clicked on the save button, the image with the annotation was written back to the pdf.

What you're asking is not trivial. As I understand the problem there are 2 possible scenarios:

  1. You need to complete empty text fields in the PDF. If so, you must prepare the PDF content first and browser will be able to edit it, check here , .

  2. You want to draw in the PDF. You're not allowed to do that, but if you created the PDF or you can convert it in byte[] to create a copy I guess you can achieve the desired result using some workaround (but won't be easy!):

    • First you must show PDF in the browser . (I understand you already did that part)
    • When PDF is show, in client side, you must implement some drawing interface . I recommend you this example .
    • When draw is accepted you must save it, send to server side and merge PDF using drawed file as "watermark" . with PDFStamper .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM