Hiren Patel Hiren Patel - 4 months ago 45
Java Question

Create HyperLink in dynamic pdf using iText in android

I created a pdf dynamically, now I want to add the link in the pdf. Is it possible?

If so, and if you have any idea, than please let me know. Thanks.

Answer

try,below article link for explains for adding anchor in itext pdf

http://tutorials.jenkov.com/java-itext/anchor.html

and sample code from above article on link

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();
        }

      }
    }