我有一个包含多个内部链接的pdf文件,所有链接操作属性值都是命名目的地
我需要为所有链接设置ZoomLevel = Inherit Zoom值
我尝试将链接操作属性从命名目标转换为页码,为所有链接设置ZoomLevel = InheritZoom。
链接操作属性已成功更改,但ZoomLevel设置为自定义,但我需要设置 InheritZoom
我使用下面的iText5示例代码来实现结果
PdfReader reader = new PdfReader(sourceFile);
reader.consolidateNamedDestinations();
public void LinkZoomLevel(PdfReader reader) {
try {
int totalPages = reader.getNumberOfPages();
for (int count = 0; count < totalPages; count++) {
PdfDictionary page = reader.getPageN(count + 1);
PdfArray annots = page.getAsArray(PdfName.ANNOTS);
if (annots != null) {
int annotationSize = annots.size();
for (int i = 0; i < annotationSize; i++) {
PdfDictionary annotation = annots.getAsDict(i);
if (PdfName.LINK.equals(annotation
.getAsName(PdfName.SUBTYPE))) {
if (annotation.get(PdfName.A) == null)
continue;
PdfDictionary action = annotation
.getAsDict(PdfName.A);
PdfArray destArray;
if (action != null) {
destArray = action.getAsArray(PdfName.D);
// destArray getting null for all links
if (destArray != null) {
if (PdfName.FITR.equals(destArray
.getAsName(1))) {
destArray.set(1, PdfName.XYZ);
destArray.set(2, destArray
.getAsNumber(2));
destArray.set(3, destArray
.getAsNumber(5));
destArray.set(4, new PdfNumber(0));
destArray.remove(5);
}
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
PdfDictionary annotation = annots.getAsDict(i);
annotation value is like-> {/Border=[0, 0, 0], /Type=/Annot, /F=4, /Dest=[170 0 R, /FitR, 0, 649, 573, 649], /Rect=[278.305, 161.745, 283.294, 171.723], /Subtype=/Link}
提前致谢