나는 Flying Saucer에서 만든 패치를 찾아 링크를 클릭하여 무언가를 할 수있게했습니다. 이것은 아주 오래 전 이었기 때문에 이것이 도움이 될지 모르겠지만, iText를 사용하고있는 것 같습니다. P
private void processLink(RenderingContext c, Box box) {
Element elem = box.getElement();
if (elem != null) {
NamespaceHandler handler = _sharedContext.getNamespaceHandler();
String uri = handler.getLinkUri(elem);
if (uri != null) {
if (uri.length() > 1 && uri.charAt(0) == '#') {
String anchor = uri.substring(1);
Box target = _sharedContext.getBoxById(anchor);
if (target != null) {
PdfDestination dest = createDestination(c, target);
if (dest != null) {
PdfAction action = new PdfAction();
if (!"".equals(handler.getAttributeValue(elem, "onclick"))) {
action = PdfAction.javaScript(handler.getAttributeValue(elem, "onclick"), _writer);
} else {
action.put(PdfName.S, PdfName.GOTO);
action.put(PdfName.D, dest);
}
com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
if (targetArea == null) {
return;
}
targetArea.setBorder(0);
targetArea.setBorderWidth(0);
PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(),
targetArea.getRight(), targetArea.getTop(), action);
annot.put(PdfName.SUBTYPE, PdfName.LINK);
annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0));
annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0));
_writer.addAnnotation(annot);
}
}
} else if (uri.indexOf("://") != -1) {
PdfAction action = new PdfAction(uri);
com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
if (targetArea == null) {
return;
}
PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), targetArea.getRight(),
targetArea.getTop(), action);
annot.put(PdfName.SUBTYPE, PdfName.LINK);
annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0));
annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0));
_writer.addAnnotation(annot);
}
}
}
}
이것은 org.xhtmlrenderer.pdf.ITextOutputDevice에 : 여기에 내가 이것을 위해 쓴 생각 코드의 단편이다.
당신이 어떤 컨텍스트에서 작업하고 있는지 잘 모르겠습니다. 어떻게하는지 알아낼 수있는 충분한 정보입니까?
목차 부분의 표는 세부 것을 나에게 보인다 :
자바의 코드는 것 같습니다. 당신이 정말로 묻고있는 것은 이미 존재하는 PDF를 수정하는 것입니다. 나는 세부 사항을 손으로 흔드는 것을 알고 있지만 PDF를 읽고 PDF를 작성할 수 있다면 그 단계들 사이에 목차를 추가하면됩니다. 뭐가 문제 야? –
내 문제는 기존 페이지에 대한 링크를 만드는 방법입니다. pdf에 새 페이지를 추가하고 레이블을 추가 할 수 있지만 해당 레이블을 특정 페이지 번호로 가리키는 방법은 무엇입니까? –
아, 그게 내가 iText에서 어떻게 해야할지 모르겠지만, 나는 접시를 비행 접시 https://code.google.com/p/flying-saucer/에서 가능하게 만들었고 iText를 사용하기 때문에 가능해야한다는 것을 알고 있습니다. 비행 접시를 확인해야합니다. 그것은 당신을 위해 더 나은 API일지도 모른다. –