1. 首页
  2. Foxit PDF SDK(安卓版)
  3. 如何在PDF文档中添加link注释?

如何在PDF文档中添加link注释?

为了将link注释添加到PDF文档,首先需要调用PDFPage.addAnnot将一个link注释添加到指定页面,然后调用Action.Create创建一个action,并将该action设置给刚添加的link注释。以下是在PDF首页添加一个URI link注释的示例代码:

private Link linkAnnot = null;
...
String path = "mnt/sdcard/input_files/sample.pdf";
try {

    // Initialize a PDFDoc object with the path to the PDF file.
    PDFDoc document = new PDFDoc(path);

    // Load the unencrypted document content.
    document.load(null);

    // Get the first page of the PDF file.
    PDFPage page = document.getPage(0);

    // Add a link annotation to the first page.
    linkAnnot = new Link (page.addAnnot(Annot.e_Link, new RectF(250, 650, 400, 750)));

    // Create a URI action and set the URI.
    URIAction uriAction = new URIAction(Action.create(document, Action.e_TypeURI));
    uriAction.setURI("www.foxitsoftware.com");

    // Set the action to link annotation.
    linkAnnot.setAction(uriAction);

    // Reset appearance stream.
    linkAnnot.resetAppearanceStream();

    // Save the document that has added the link annotation.
    document.saveAs("mnt/sdcard/input_files/sample_annot.pdf", PDFDoc.e_SaveFlagNormal);
    
} catch (Exception e) {
    e.printStackTrace();
}
更新于 2020年4月22日

这篇文章有用吗?

相关文章