2

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.

pmbthiru
  • 41
  • 1
  • 1
  • 6
  • Your question reveals a severe lack of understanding of the PDF format. There is no answer to your question because you are asking something that is impossible. – Bruno Lowagie Mar 23 '15 at 11:17
  • Maybe not *impossible* but indeed a task taking a professional team quite some time... – mkl Mar 23 '15 at 11:24
  • I guess will be hard, but with a bit of imagination and workaround I guess it can be achieved. – Jordi Castilla Mar 23 '15 at 11:28
  • You are talking about creating a whole new product, rendering the PDF as HTML 5 and making the HTML 5 content respond to user input. That's an enormous task. – Bruno Lowagie Mar 23 '15 at 11:30
  • Do you need edit *all* content of pdf or only newly added lines, circles? – user1516873 Mar 23 '15 at 11:30
  • @BrunoLowagie sure it will be a hard task, but if reallty needed, it can be achieved... What you think about my answer? I guess it's poosible... I would really appreciate your opinion... – Jordi Castilla Mar 23 '15 at 11:34
  • @JordiCastilla Option 1 should be removed. You can't draw lines in text fields. The link points to a question that has no useful answer in this context. Option 2 is not clear. You must render the PDF in the browser *as HTML5*. Showing it in a PDF viewer won't work. I know that IDR Solutions can convert PDF to HTML5, but that's the only solution I know. Implementing a drawing interface should be possible, but then you need to reconstruct the PDF on the server side. This is what the [Geomajas](http://www.geomajas.org/) project is doing, but they've spent many years building that solution. – Bruno Lowagie Mar 23 '15 at 11:42
  • Thanks Bruno! ;) option 1 is not to draw, is to clarify what EDIT means. what I guessed with option 2 is treating PDF as background for drawing interface (mantaining the `byte[]` independent in the server side). When you get the draws, pass them to server side and use it as watermark for the previously saved `PDF byte[]`, if you can achieve this, draw will be "virtually possible". But never EDITING the PDF as EDIT means... – Jordi Castilla Mar 23 '15 at 11:50
  • @pmbthiru if what you want is to draw, save, and after edit the draws, your desired answer become almost impossible... be happy if you achieve just drawing in the PDF... – Jordi Castilla Mar 23 '15 at 11:53
  • I have updated my question. Please view and suggest any solution – pmbthiru Mar 23 '15 at 11:54
  • It is unclear, why you are using pdf format? Why not svg or png? In case of png: you can show image as background, find library for drawing vector graphics and store vector info separatly. When need final result, merge vector and background. And even this will required many effort and time, so be prepare. – user1516873 Mar 23 '15 at 12:19

3 Answers3

3

[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.

Ryan
  • 2,473
  • 1
  • 11
  • 14
1

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.

Adit
  • 11
  • 1
0

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.
Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109