/***** Code de MesExemples.com *******/
import java.io.FileOutputStream;import java.io.IOException;import com.itextpdf.text.Anchor;import com.itextpdf.text.Chunk;import com.itextpdf.text.Document;import com.itextpdf.text.DocumentException;import com.itextpdf.text.Paragraph;import com.itextpdf.text.html.HtmlWriter;import com.itextpdf.text.pdf.PdfWriter;import com.itextpdf.text.rtf.RtfWriter2;public class CreatingHyperLinkForHTML { public static void main(String[] args) { Document document = new Document(); try { HtmlWriter html = HtmlWriter.getInstance(document, new FileOutputStream("CreatingHyperLinkForHTML.html")); document.open(); document.add(new Paragraph("Some text")); Anchor pdfRef = new Anchor("http://www.java2s.com"); pdfRef.setReference("http://www.java2s.com"); Anchor rtfRef = new Anchor("a File"); rtfRef.setReference("./aFile.htm"); document.add(pdfRef); document.add(Chunk.NEWLINE); document.add(rtfRef); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }}
Java PDF: Exemple de création de lien hypertexte
Author: user/***** Code de MesExemples.com *******/
/***** Code de MesExemples.com *******/
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Anchor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.html.HtmlWriter;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.rtf.RtfWriter2;
public class CreatingHyperLinkForHTML
{
public static void main(String[] args)
{
Document document = new Document();
try
{
HtmlWriter html = HtmlWriter.getInstance(document, new FileOutputStream("CreatingHyperLinkForHTML.html"));
document.open();
document.add(new Paragraph("Some text"));
Anchor pdfRef = new Anchor("http://www.mesexemples.com");
pdfRef.setReference("http://www.mesexemples.com");
Anchor rtfRef = new Anchor("a File");
rtfRef.setReference("./aFile.htm");
document.add(pdfRef);
document.add(Chunk.NEWLINE);
document.add(rtfRef);
} catch (DocumentException de)
{
System.err.println(de.getMessage());
} catch (IOException ioe)
{
System.err.println(ioe.getMessage());
}
document.close();
}
}