Project

General

Profile

How to use this addlink,setlink methods in pdf file

Added by Fathima L over 11 years ago

File

http://ruby-on-rails.r3dcode.com/files/redmine/1/2.1/vendor/plugins/rfpdf/lib/tcpdf.rb

#
1535 # Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />
1536 # The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
1537 # @since 1.5
1538 # @see Cell(), Write(), Image(), Link(), SetLink()
1539 #
1540 def AddLink()
1541 #Create a new internal link
1542 n=@links.length+1;
1543 @links[n]=[0,0];
1544 return n;
1545 end
1546 alias_method :add_link, :AddLink
1547
1548 #
1549 # Defines the page and position a link points to
1550 # @param int :link The link identifier returned by AddLink()
1551 # @param float :y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
1552 # @param int :page Number of target page; -1 indicates the current page. This is the default value
1553 # @since 1.5
1554 # @see AddLink()
1555 #
1556 def SetLink(link, y=0, page=-1)
1557 #Set destination of internal link
1558 if (y==-1)
1559 y=@y;
1560 end
1561 if (page==-1)
1562 page=@page;
1563 end
1564 @links[link] = [page, y]
1565 end
1566 alias_method :set_link, :SetLink
1567
1568 #
1569 # 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.
1570 # @param float :x Abscissa of the upper-left corner of the rectangle
1571 # @param float :y Ordinate of the upper-left corner of the rectangle
1572 # @param float :w Width of the rectangle
1573 # @param float :h Height of the rectangle
1574 # @param mixed :link URL or identifier returned by AddLink()
1575 # @since 1.5
1576 # @see AddLink(), Cell(), Write(), Image()
1577 #
1578 def Link(x, y, w, h, link)
1579 #Put a link on the page
1580 @page_links ||= Array.new
1581 @page_links[@page] ||= Array.new
1582 @page_links[@page].push([x * @k, @h_pt - y * @k, w * @k, h*@k, link]);
1583 end
1584 alias_method :link, :Link

How to use this methods of pdf pages.