AddLink()

	
	int AddLink()

Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document. The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().

SetLink()

	
	SetLink(int link [, float y [, int page]])

Defines the page and position a link points to.

link

The link identifier returned by AddLink().

y

Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page).

page

Number of target page; -1 indicates the current page. This is the default value.

Link()

	
	Link(float x, float y, float w, float h, mixed link)

Puts a link on a rectangular area of the page. Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image.

x

Abscissa of the upper-left corner of the rectangle.

y

Ordinate of the upper-left corner of the rectangle.

w

Width of the rectangle.

h

Height of the rectangle.

link

URL or identifier returned by AddLink().

Link to a Page in the Document

Consider the following example -

		$pdf = new FPDF();

		// First Page --
		$pdf->AddPage();
		$pdf->SetFont('Arial','B',16);
		$str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do";
		$pdf->setTextColor(103, 58, 183);
		$linkNumber = $pdf->AddLink();
		$pdf->Write(10, $str, $linkNumber);


		// Second Page --
		$pdf->AddPage();
		$pdf->SetLink($linkNumber);
		$pdf->SetLeftMargin(45);
		$pdf->SetFontSize(14);
		$pdf->Write(10, "Hello, This is the Target of the Link !");

		$pdf->Output('helo.pdf', 'D');

In the first page, we have generated a link reference using AddLink() which returns an integer number. We will use this number later on to reference another page in the document. The generated link number is passed to the Write() method to make the text clickable.

In the second page, we used that generated link number and passed to the SetLink() method.

The SetLink() methods accepts the link number generated by AddLink() method, and create the current page as target page. So whenever the link is clicked it will take the user to the page where SetLink($linkNumber) was given.

If you click on the following text -

It will take you to the second page -

You can also make a Cell a link but you cannot make MultiCell text a link. There is no option for that.

Link to an External Link

To add an external link, instead of using generated link number, use string URL. Like this -


	$str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do";
	$pdf->Write(10, $str, "www.google.com");

Make an Image a Link

Consider the following example -


	$pdf->AddPage();
	$pdf->Image(URL::to('images/Santanu.jpg'),10,12,30,0,'','http://www.fpdf.org');

In this example, we are using an external link as the last argument. It's that simple. Just use string URL as the last argument and you are ready to go.

Make a part of the text as a Link

By default the whole text within the Cell() or Write() method become a link. Then how can you make a part of the text as a link? Well, how about you break your whole text to a multiple Write() small text and make a particular Write() method a link.

Consider the following Example -

		$pdf->AddPage();
		$pdf->SetTextColor(0);
		$pdf->Write(10, "Hello, this is a full text.");
		$pdf->setTextColor(103, 58, 183);
		$pdf->Write(10, "This is a link text ! ", "www.google.com");
		$pdf->setTextColor(0);
		$pdf->Write(10, "But this is not a Link !");