我正在使用以下代碼將所有超鏈接的縮放級別更改爲繼承縮放,但無法更改。itext更改所有超鏈接的縮放級別以繼承放大現有的pdf
可能是我在PdfName.DEST和條件中犯了一些錯誤,因爲沒有第一頁的pdf格式的DEST數組(請查看屏幕快照)。
for (int count = 0; count < reader.getNumberOfPages(); count++) {
PdfDictionary page = reader.getPageN(count+1);
PdfArray annots = page.getAsArray(PdfName.ANNOTS);
if (annots != null) {
for (int i = 0; i < annots.size(); i++) {
PdfDictionary annotation = annots.getAsDict(i);
if (PdfName.LINK.equals(annotation.getAsName(PdfName.SUBTYPE))) {
if(annotation.get(PdfName.A)==null){
continue;
}
PdfArray d = annotation.getAsArray(PdfName.DEST);
if (d != null && d.size() == 5 && PdfName.XYZ.equals(d.getAsName(1)))
d.set(4, new PdfNumber(0));
}
}
}
}
我已經在第一頁創建鏈接到第二頁,檢查圖像中的結構。
我也嘗試使用下面的代碼...我有調試和檢查d的價值每
for (int count = 0; count < reader.getNumberOfPages(); count++) {
PdfDictionary page = reader.getPageN(count+1);
PdfArray annots = page.getAsArray(PdfName.ANNOTS);
if (annots != null) {
for (int i = 0; i < annots.size(); i++) {
PdfDictionary annotation = annots.getAsDict(i);
if (PdfName.LINK.equals(annotation.getAsName(PdfName.SUBTYPE))) {
PdfArray d = annotation.getAsArray(PdfName.DEST);
// d is null every time
}
}
}
}
其實我想將所有鏈接屬性更改爲繼承縮放。對不起,但我英文不好。 –
在此條件之前,我也會在d中獲得null。 –
這就是我用湯比喻的意思。你在你的問題中顯示答案,你沒有看到答案!這怎麼可能?我會更新我的問題。 –