带有xhtmlrenderer(iText)的书签 [英] Bookmarks with xhtmlrenderer (iText)
问题描述
我正在将xhtmlrenderer(也称为飞碟)与iText一起使用,以将HTML转换为PDF.我该如何创建书签?有人有一个小例子吗?
I'm using xhtmlrenderer (Also known as Flying Saucer) with iText to convert HTML to PDF. How would I create bookmarks with this? Does someone with have a small example?
谢谢.
推荐答案
似乎在R6中添加了书签,但是用户指南仅为它们提供了传递的参考.并向作者提供TODO,以便稍后添加示例.
It seems bookmarks were added in R6, but the user guide only gives them a passing reference. with a TODO to the author to add an example later.
在论坛上搜索,我发现此示例:
Searching the forums, I found this example:
<html>
<head>
<bookmarks>
<bookmark name="A bookmark" href="#bm" />
<bookmark name="A bookmark 2" href="#bm2" />
<bookmark name="A bookmark 3" href="#bm3" />
<bookmark name="A bookmark 4" href="#bm4" />
<bookmark name="A bookmark invalid" href="#bm99" />
</bookmarks>
</head>
<body>
<div style="line-height: 100%; font-size: 12pt; page-break-before: always;">
<a name="bm">some text</a>
</div>
<div style="line-height: 100%; font-size: 12pt; page-break-before: always;">
<a name="bm2">some text</a>
</div>
<div style="line-height: 100%; font-size: 12pt; page-break-before: always;">
<a name="bm3">some text</a>
</div>
<div style="line-height: 100%; font-size: 12pt; page-break-before: always;">
<p>some text</p> <p>some text</p> <p>some text</p> <p>some text</p> <p>some text</p> <p>some text</p>
<p><a name="bm4">and some more text</a></p>
</div>
</body>
</html>`
因此,添加书签似乎只不过是在<head>
中声明书签并将它们作为<body>
中的锚点而引用.
So it seems that adding bookmarks is no more than declaring the bookmarks in the <head>
and referencing them as anchors in the <body>
.
这应与您现有的XHTML-> PDF转换一起使用,而无需进行任何代码更改.
This should work will with your existing XHTML->PDF conversion without requiring any code changes.
这篇关于带有xhtmlrenderer(iText)的书签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!