简体   繁体   中英

Drawing on a rendered pdf - Swing

After being extremely annoyed at the lack of free software to draw directly onto pdfs, I've decided to write it myself.

I aim to achieve this by having some sort of canvas widget in a GUI with the contents of a pdf displayed underneath it, and record (and render) everything drawn onto the screen and when saving the file, save everything drawn as a .png (with a transparent background) and overlay it onto the .pdf.

I've already written the stuff for overlaying the pdf (using iText), but am not sure how to approach the GUI stuff. How should I proceed about rendering the pdf? I've seen an approach involving converting a page of the .pdf into an image (PDF-renderer) and chucking that in Swing, but I imagine this will have resolution issues (zooming).

Another idea I've had is to render the .pdf in a swing element using the Viewer widget from JPedal, but I'm not sure how I'd set up the canvas.

So, how should I approach this?
What should the general structure of my interface?
I've not tried either of these options (I'm still investigating their library interfaces). I wanted to seek advice early (since it's about the very base structure of the program).

Rendering PDFs is incredibly complicated. We develop ABCpdf and I would guess we have perhaps forty man years of investment just in the rendering side.

So if you want to do this you should start by limiting what you need to do. Either you need to ensure that your PDFs come from a uniform source that uses a restricted set of functionality, or you need to accept that many of your PDFs will not render correctly.

Next you need to decompress the page content stream(s) then break it into PDF operators. Then create a System.Drawing.Bitmap or similar and use each of the PDF drawing operators to draw on that drawing surface. You will find full details of the operators in the PDF Spec which is available on the Adobe web site.

Provided your PDF source is consistent, simple and uniform you will probably be able to get something sensible out within a few weeks. Happy coding :-)

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