iTextPDF超链接未链接到正确的位置 [英] iTextPDF hyperlink not linking to the right place

查看:1179
本文介绍了iTextPDF超链接未链接到正确的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆PDF,我已经在代码中合并了这一点。在合并的PDF的开头,我有一个内容页面,分别链接到所述PDF。这些 pdfAction.gotoLocalPage 链接有时无法正常工作,而是跳转到页面底部和下一页之间,但PDF书签超链接总是很好。

I have a bunch of PDF's which I have merged by this point in the code. At the beginning of the merged PDF I have a contents page which links to said PDF's respectively. These pdfAction.gotoLocalPage links sometimes don't work correctly and instead jump to between the bottom of the page and the next, however the PDF bookmark hyperlinks always work fine.

书签的代码:

int pageToLinkTo=prevSectionPageCount+sectionPageCount+numberOfIndexPages+currentIndexPage+1;

document.put("Title", documentName);
document.put("Action", "GoTo");                 
document.put("Page",String.format("%d Fit", pageToLinkTo));

内容页面链接的代码:

PdfAction action = PdfAction.gotoLocalPage(pageToLinkTo, new PdfDestination(PdfDestination.FIT,-1,-1,0), stamper.getWriter());                              
chunk.setAction(action);

这两个评估到同一页面。源PDF文件可能有问题吗?有效的链接和跳转到错误位置的链接之间唯一值得注意的区别是,源PDF的页面大小略有不同(0.1英寸不同)。

Both of these evaluate to the same page. Could there be something wrong with the source PDF files? The only notable difference between the links which do work and the links that jump to the wrong place, is that the source PDF's have a slightly different page size (0.1 of an inch different).

任何帮助将不胜感激!

谢谢

推荐答案

我看到你创建了这样的目的地:

I see that you create your destination like this:

new PdfDestination(PdfDestination.FIT,-1,-1,0)

这是一种创建目的地的奇怪方式,以便显示页面以适合查看器窗口。请查看带有iText的PDF的ABC 。这本书尚未完成,但它是免费的,在表3.7中,您可以看到哪些目的地占用了多少参数。

This is a strange way to create a destination so that the page is displayed to fit the viewer window. Please take a look at The ABC of PDF with iText. The book isn't finished yet, but it's free and in table 3.7, you can see which destinations take how many parameters.

如果您希望页面适合观众窗口,你不需要任何额外的参数:

If you want the page to fit the viewer window, you don't need any extra parameters:

new PdfDestination(PdfDestination.FIT)

有一个目的地需要三个额外的参数:

There is a destination that takes three extra parameters:

new PdfDestination(PdfDestination.XYZ, x, y, z)

在这种情况下 x y 是坐标, z 是缩放系数。我认为您通过添加 x y z来混淆PDF查看器参数,只要你想让它适合查看器窗口中的页面。

In this case x and y are coordinates and z is the zoom factor. I think that you are confusing the PDF viewer by adding x, y and z parameters when all you want it to fit the page in the viewer window.

这篇关于iTextPDF超链接未链接到正确的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆