简体   繁体   English

在渲染的pdf上绘图-Swing

[英]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. 对缺乏免费软件直接绘制到pdf感到非常恼火之后,我决定自己编写。

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. 我的目标是通过在GUI中放置某种画布小部件并在其下方显示pdf的内容,并记录(并渲染)绘制在屏幕上的所有内容,并在保存文件时将绘制的所有内容保存为.png( (具有透明背景)并将其覆盖到.pdf上。

I've already written the stuff for overlaying the pdf (using iText), but am not sure how to approach the GUI stuff. 我已经写了用于覆盖pdf的内容(使用iText),但是不确定如何处理GUI内容。 How should I proceed about rendering the pdf? 如何呈现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). 我已经看到了一种方法,其中涉及将.pdf的页面转换为图像(PDF渲染器)并在Swing中将其删除,但是我想这会带来分辨率问题(缩放)。

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. 我的另一个想法是使用JPedal的Viewer小部件在一个swing元素中呈现.pdf,但是我不确定如何设置画布。

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. 渲染PDF非常复杂。 We develop ABCpdf and I would guess we have perhaps forty man years of investment just in the rendering side. 我们开发了ABCpdf,我想我们可能仅在渲染方面就花了40个人年的时间。

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. 您需要确保您的PDF来自使用一组受限功能的统一来源,或者您需要接受许多PDF无法正确呈现的情况。

Next you need to decompress the page content stream(s) then break it into PDF operators. 接下来,您需要解压缩页面内容流,然后将其分解为PDF运算符。 Then create a System.Drawing.Bitmap or similar and use each of the PDF drawing operators to draw on that drawing surface. 然后创建一个System.Drawing.Bitmap或类似文件,并使用每个PDF绘图运算符在该绘图面上进行绘制。 You will find full details of the operators in the PDF Spec which is available on the Adobe web site. 您可以在Adobe网站上的PDF规范中找到运算符的完整详细信息。

Provided your PDF source is consistent, simple and uniform you will probably be able to get something sensible out within a few weeks. 只要您的PDF来源是一致,简单和统一的,您可能会在几周内得到一些明智的信息。 Happy coding :-) 快乐的编码:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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