简体   繁体   English

iText-将html转换为pdf并添加并链接到附件

[英]iText - transform html to pdf and add and link to attachment

I have successfully parsed a XML file into a XHTML file, and then finally into a PDF using iText. 我已经成功地将XML文件解析为XHTML文件,然后使用iText将其最终解析为PDF。

Now the next achievement would be to attach and link the Base64 embedded documents from the XML file into the PDF document. 现在的下一个成就是将Base64嵌入式文档从XML文件附加并链接到PDF文档。 Attaching these files (so they appear in the "attachments pane" in the PDF viewer) is working. 附加这些文件(使它们显示在PDF查看器的“附件窗格”中)正在工作。

Now my problem is that these attachments (.doc, .ppt, etc) should be opened by clicking on a text link or an image (icon). 现在我的问题是这些附件(.doc,.ppt等)应该通过单击文本链接或图像(图标)来打开。 The images (and document names eg "test.doc") are already in the PDF, but how can I link the right file to the right image or text link? 图像(和文档名称,例如“ test.doc”)已经在PDF中,但是如何将正确的文件链接到正确的图像或文本链接? Could some of you give me a hint where to start? 你们中的一些人可以给我提示从哪里开始吗?

What you could do is create a "mapping" of those files to the names, so they will have a unique identifier. 您可以做的是将这些文件与名称进行“映射”,以便它们具有唯一的标识符。 After that you just create an endpoint that will return required file with required mime type (check out Octet stream as well). 之后,您只需创建一个端点,该端点将返回具有必需的mime类型的必需文件(也请检出Octet流)。 In the PDF you just add the hyperlinks that will go to your endpoint and fetch the required document by name. 在PDF中,您只需添加将链接到端点并按名称获取所需文档的超链接。

EDIT: You could actually have more than one endpoint: you could need one for every mime type you use for more convenience. 编辑:实际上,您可能有多个端点:为方便起见,您可能需要为每个哑剧类型使用一个端点。

In order to create a link inside PDF, use Anchor from iText lib. 为了在PDF内创建链接,请使用iText lib中的Anchor

In order to create an endpoint - it is really up to you. 为了创建一个端点-取决于您。 You can use any way to create a webapp that would return a file from web interactively. 您可以使用任何方法来创建Web应用程序,以交互方式从Web返回文件。

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

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