我动态创建了一个pdf,现在我想在pdf中添加链接。可能吗?
如果是这样,如果您有任何想法,请告诉我。谢谢。
试试,下面的文章链接解释了在 itext pdf 中添加锚点
http://tutorials.jenkov.com/java-itext/anchor.html
以及来自上述文章链接的示例代码
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class AnchorExample {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document,
new FileOutputStream("Anchor.pdf"));
document.open();
Paragraph paragraph = new Paragraph();
paragraph.add(new Phrase("You can find the IText tutorial at "));
Anchor anchor = new Anchor(
"http://tutorials.jenkov.com/java-itext/index.html");
anchor.setReference(
"http://tutorials.jenkov.com/java-itext/index.html");
paragraph.add(anchor);
document.add(paragraph);
document.close();
} catch (DocumentException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}