Class: TCPDF
- Inherits:
-
Object
- Object
- TCPDF
- Includes:
- ActionView::Helpers, Html_colors, RFPDF, Unicode_data
- Defined in:
- lib/tcpdf.rb
Overview
This is a Ruby class for generating PDF files on-the-fly without requiring external extensions.
-
This class is an extension and improvement of the FPDF class by Olivier Plathey (www.fpdf.org).
-
This version contains some changes: [porting to Ruby, support for UTF-8 Unicode, code style and formatting, php documentation (www.phpdoc.org), ISO page formats, minor improvements, image scale factor]
-
TCPDF project (www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (www.fpdf.org), but now is almost entirely rewritten.
-
To add your own TTF fonts please read /fonts/README.TXT
- @name
-
TCPDF
- @package
-
com.tecnick.tcpdf
- @@version
-
5.1.002
- @author
-
Nicola Asuni
- @link
- @license
-
www.gnu.org/copyleft/lesser.html LGPL 2.1
Constant Summary collapse
- @@version =
"5.1.002"
- @@fpdf_charwidths =
{}
- @@k_cell_height_ratio =
1.25
- @@k_blank_image =
""
- @@k_small_ratio =
2/3.0
- @@k_path_images =
""
- @@k_thai_topchars =
nil
Instance Attribute Summary collapse
-
#barcode ⇒ Object
Returns the value of attribute barcode.
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#cache_file_length ⇒ Object
Returns the value of attribute cache_file_length.
-
#color_flag ⇒ Object
Returns the value of attribute color_flag.
-
#default_font ⇒ Object
Returns the value of attribute default_font.
-
#default_table_columns ⇒ Object
Returns the value of attribute default_table_columns.
-
#diffs ⇒ Object
Returns the value of attribute diffs.
-
#diskcache ⇒ Object
Returns the value of attribute diskcache.
-
#draw_color ⇒ Object
Returns the value of attribute draw_color.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#fill_color ⇒ Object
Returns the value of attribute fill_color.
-
#font_family ⇒ Object
Returns the value of attribute font_family.
-
#font_files ⇒ Object
Returns the value of attribute font_files.
-
#font_size_pt ⇒ Object
Returns the value of attribute font_size_pt.
-
#font_style ⇒ Object
Returns the value of attribute font_style.
-
#fonts ⇒ Object
Returns the value of attribute fonts.
-
#header_logo ⇒ Object
Returns the value of attribute header_logo.
-
#header_logo_width ⇒ Object
Returns the value of attribute header_logo_width.
-
#header_string ⇒ Object
Returns the value of attribute header_string.
-
#header_title ⇒ Object
Returns the value of attribute header_title.
-
#header_width ⇒ Object
Returns the value of attribute header_width.
-
#images ⇒ Object
Returns the value of attribute images.
-
#img_scale ⇒ Object
Returns the value of attribute img_scale.
-
#in_footer ⇒ Object
Returns the value of attribute in_footer.
-
#is_unicode ⇒ Object
Returns the value of attribute is_unicode.
-
#lasth ⇒ Object
Returns the value of attribute lasth.
-
#links ⇒ Object
Returns the value of attribute links.
-
#lispacer ⇒ Object
Returns the value of attribute lispacer.
-
#listcount ⇒ Object
Returns the value of attribute listcount.
-
#listordered ⇒ Object
Returns the value of attribute listordered.
-
#n ⇒ Object
Returns the value of attribute n.
-
#offsets ⇒ Object
Returns the value of attribute offsets.
-
#page ⇒ Object
Returns the value of attribute page.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#pdf_version ⇒ Object
Returns the value of attribute pdf_version.
-
#prev_pages ⇒ Object
Returns the value of attribute prev_pages.
-
#print_footer ⇒ Object
Returns the value of attribute print_footer.
-
#print_header ⇒ Object
Returns the value of attribute print_header.
-
#state ⇒ Object
Returns the value of attribute state.
-
#text_color ⇒ Object
Returns the value of attribute text_color.
-
#underline ⇒ Object
Returns the value of attribute underline.
Instance Method Summary collapse
-
#AcceptPageBreak ⇒ Object
(also: #accept_page_break)
Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
-
#AddFont(family, style = '', fontfile = '') ⇒ Object
(also: #add_font)
Imports a TrueType, Type1, core, or CID0 font and makes it available.
-
#addHtmlLink(url, name, fill = 0, firstline = false, color = '', style = -1,, firstblock = false) ⇒ Object
(also: #add_html_link)
Output anchor link.
-
#addHTMLTOC(page = '', toc_name = 'TOC', templates = [], correct_align = true) ⇒ Object
(also: #add_html_toc)
Output a Table Of Content Index (TOC) using HTML templates.
-
#AddLink ⇒ Object
(also: #add_link)
Creates a new internal link and returns its identifier.
-
#AddPage(orientation = '', format = '', keepmargins = false, tocpage = false) ⇒ Object
(also: #add_page)
Adds a new page to the document.
-
#AddSpotColor(name, c, m, y, k) ⇒ Object
(also: #add_spot_color)
Defines a new spot color.
-
#addTOC(page = '', numbersfont = '', filler = '.', toc_name = 'TOC') ⇒ Object
(also: #add_toc)
Output a Table of Content Index (TOC).
-
#addTOCPage(orientation = '', format = '', keepmargins = false) ⇒ Object
(also: #add_toc_page)
Adds a new TOC (Table Of Content) page to the document.
-
#AliasNbPages(alias_nb = '{nb}') ⇒ Object
(also: #alias_nb_pages)
Defines an alias for the total number of pages.
-
#AliasNumPage(alias_num = '{pnb}') ⇒ Object
(also: #alias_num_page)
Defines an alias for the page number.
-
#Annotation(x, y, w, h, text, opt = {'Subtype'=>'Text'}, spaces = 0) ⇒ Object
(also: #annotation)
Puts a markup annotation on a rectangular area of the page.
-
#Arrow(x0, y0, x1, y1, head_style = 0, arm_size = 5, arm_angle = 15) ⇒ Object
(also: #arrow)
Draws a grahic arrow.
-
#Bookmark(txt, level = 0, y = -1,, page = nil) ⇒ Object
(also: #bookmark)
Adds a bookmark.
- #BreakThePage?(h) ⇒ Boolean (also: #break_the_page?)
-
#Cell(w, h = 0, txt = '', border = 0, ln = 0, align = '', fill = 0, link = nil, stretch = 0, ignore_min_height = false, calign = 'T', valign = 'M') ⇒ Object
(also: #cell)
Prints a cell (rectangular area) with optional borders, background color and character string.
-
#Circle(x0, y0, r, angstr = 0, angend = 360, style = '', line_style = nil, fill_color = nil, nc = 2) ⇒ Object
(also: #circle)
Draws a circle.
-
#Close ⇒ Object
Terminates the PDF document.
-
#commitTransaction ⇒ Object
(also: #commit_transaction)
Delete the copy of the current TCPDF object used for undo operation.
-
#convertHTMLColorToDec(color = "#FFFFFF") ⇒ Object
(also: #convert_html_color_to_dec)
Returns an associative array (keys: R,G,B) from an html color name or a six-digit or three-digit hexadecimal color representation (i.e. #3FE5AA or #7FF).
-
#Curve(x0, y0, x1, y1, x2, y2, x3, y3, style = '', line_style = nil, fill_color = nil) ⇒ Object
(also: #curve)
Draws a Bezier curve.
-
#deletePage(page) ⇒ Object
(also: #delete_page)
Remove the specified page.
-
#destroy(destroyall = false, preserve_objcopy = false) ⇒ Object
Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
-
#Ellipse(x0, y0, rx, ry = '', angle = 0, astart = 0, afinish = 360, style = '', line_style = nil, fill_color = nil, nc = 2) ⇒ Object
(also: #ellipse)
Draws an ellipse.
-
#empty_string(str) ⇒ Object
Determine whether a string is empty.
-
#endPage(tocpage = false) ⇒ Object
(also: #end_page)
Terminate the current page [@param boolean :tocpage] if true set the tocpage state to false (end the page used to display Table Of Content).
-
#endTOCPage ⇒ Object
(also: #end_toc_page)
Terminate the current TOC (Table Of Content) page [@access public] [@since 5.0.001 (2010-05-06)] [@see] AddPage(), startPage(), endPage(), addTOCPage().
-
#Error(msg) ⇒ Object
(also: #error)
This method is automatically called in case of fatal error; it simply outputs the message and halts the execution.
-
#Footer ⇒ Object
(also: #footer)
This method is used to render the page footer.
-
#GetAbsX ⇒ Object
(also: #get_abs_x)
Returns the absolute X value of current position.
-
#getAliasNbPages ⇒ Object
(also: #get_alias_nb_pages)
Returns the string alias used for the total number of pages.
-
#getAliasNumPage ⇒ Object
(also: #get_alias_num_page)
Returns the string alias used for the page number.
-
#GetArrStringWidth(sa, fontname = '', fontstyle = '', fontsize = 0, getarray = false) ⇒ Object
(also: #get_arr_string_width)
Returns the string length of an array of chars in user unit or an array of characters widths.
-
#getBreakMargin(pagenum = '') ⇒ Object
(also: #get_break_margin)
Returns the page break margin.
- #GetBreakMargin(pagenum = '') ⇒ Object
-
#getCellHeightRatio ⇒ Object
(also: #get_cell_height_ratio)
return the height of cell repect font height.
-
#GetCharWidth(char) ⇒ Object
(also: #get_char_width)
Returns the length of the char in user unit for the current font.
-
#getFontAscent(font, style = '', size = 0) ⇒ Object
(also: #get_font_ascent)
Return the font ascent value [@param string :font] font name [@param string :style] font style [@param float :size] The size (in points) [@return int] font ascent [@access public] [@since 4.9.003 (2010-03-30)].
-
#getFontDescent(font, style = '', size = 0) ⇒ Object
(also: #get_font_descent)
Return the font descent value [@param string :font] font name [@param string :style] font style [@param float :size] The size (in points) [@return int] font descent [@access public] [@since 4.9.003 (2010-03-30)].
-
#getFontFamily ⇒ Object
(also: #get_font_family)
Returns the current font family name.
-
#getFontSize ⇒ Object
(also: #get_font_size)
Returns the current font size.
-
#getFontSizePt ⇒ Object
(also: #get_font_size_pt)
Returns the current font size in points unit.
-
#getFontStyle ⇒ Object
(also: #get_font_style)
Returns the current font style.
-
#getFooterFont(font) ⇒ Object
(also: #get_footer_font)
Get Footer font.
-
#getFooterMargin ⇒ Object
(also: #get_footer_margin)
Returns footer margin in user units.
-
#getGroupPageNo ⇒ Object
(also: #get_group_page_no)
Return the current page in the group.
-
#getGroupPageNoFormatted ⇒ Object
(also: #get_group_page_no_formatted)
Returns the current group page number formatted as a string.
- #getHeaderData ⇒ Object (also: #get_header_data)
-
#getHeaderFont ⇒ Object
(also: #get_header_font)
Get header font.
-
#getHeaderMargin ⇒ Object
(also: #get_header_margin)
Returns header margin in user units.
-
#getHTMLUnitToUnits(htmlval, refsize = 1, defaultunit = 'px', points = false) ⇒ Object
(also: #get_html_unit_to_units)
convert HTML string containing value and unit of measure to user’s units or points.
-
#getImageFileType(imgfile, iminfo = {}) ⇒ Object
(also: #get_image_file_type)
Return the image type given the file name or array returned by getimagesize() function.
-
#getImageRBX ⇒ Object
(also: #get_image_rbx)
Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image [@return float] [@access public].
-
#getImageRBY ⇒ Object
(also: #get_image_rby)
Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image [@return float] [@access public].
- #GetImageScale ⇒ Object
-
#getImageScale ⇒ Object
(also: #get_image_scale)
Returns the adjusting factor to convert pixels to user units.
-
#getLastH ⇒ Object
(also: #get_last_h)
Get the last cell height.
-
#GetLineWidth ⇒ Object
(also: #get_line_width)
Returns the current the line width.
-
#GetNumChars(s) ⇒ Object
(also: #get_num_chars)
Returns the numbero of characters in a string.
-
#getNumPages ⇒ Object
(also: #get_num_pages)
Get the total number of insered pages.
- #getOriginalMargins ⇒ Object (also: #get_original_margins)
-
#getPage ⇒ Object
(also: #get_page)
Get current document page number.
-
#getPageDimensions(pagenum = '') ⇒ Object
(also: #get_page_dimensions)
Returns an array of page dimensions: @pagedim[‘w’] = page width in points @pagedim[‘h’] = height in points @pagedim[‘wk’] = page width in user units @pagedim[‘hk’] = page height in user units @pagedim[‘tm’] = top margin @pagedim[‘bm’] = bottom margin @pagedim[‘lm’] = left margin @pagedim[‘rm’] = right margin @pagedim[‘pb’] = auto page break @pagedim[‘or’] = page orientation @pagedim[‘olm’] = original left margin @pagedim[‘orm’] = original right margin @pagedim[‘Rotate’] = The number of degrees by which the page shall be rotated clockwise when displayed or printed.
-
#getPageGroupAlias ⇒ Object
(also: #get_page_group_alias)
Return the alias of the current page group If the current font is unicode type, the returned string is surrounded by additional curly braces.
- #GetPageHeight ⇒ Object
-
#getPageHeight ⇒ Object
(also: #get_page_height)
Returns the page height in units.
-
#getPageNumGroupAlias ⇒ Object
(also: #get_page_num_group_alias)
Return the alias for the page number on the current page group If the current font is unicode type, the returned string is surrounded by additional curly braces.
-
#getPageSizeFromFormat(format) ⇒ Object
(also: #get_page_size_from_format)
Get page dimensions from fromat name.
- #GetPageWidth ⇒ Object
-
#getPageWidth ⇒ Object
(also: #get_page_width)
Returns the page width in units.
-
#getPDFData ⇒ Object
(also: #get_pdf_data)
Returns the PDF data.
- #GetPDFData ⇒ Object
-
#getRTL ⇒ Object
(also: #get_rtl)
Return the RTL status [@return boolean] [@access public] [@since 4.0.012 (2008-07-24)].
-
#getScaleFactor ⇒ Object
(also: #get_scale_factor)
Returns the scale factor (number of points in user unit).
- #GetScaleFactor ⇒ Object
-
#GetStringWidth(s, fontname = '', fontstyle = '', fontsize = 0, getarray = false) ⇒ Object
(also: #get_string_width)
Returns the length of a string in user unit.
-
#GetX ⇒ Object
(also: #get_x)
Returns the relative X value of current position.
-
#GetY ⇒ Object
(also: #get_y)
Returns the ordinate of the current position.
-
#Header ⇒ Object
(also: #header)
This method is used to render the page header.
-
#Image(file, x = '', y = '', w = 0, h = 0, type = '', link = nil, align = '', resize = false, dpi = 300, palign = '', ismask = false, imgmask = false, border = 0, fitbox = false, hidden = false, fitonpage = false) ⇒ Object
(also: #image)
Puts an image in the page.
-
#initialize(orientation = 'P', unit = 'mm', format = 'A4', unicode = true, encoding = "UTF-8", diskcache = false) ⇒ TCPDF
constructor
This is the class constructor.
-
#intToRoman(number) ⇒ Object
(also: #int_to_roman)
Returns the Roman representation of an integer number [@param int :number] to convert [@return string] roman representation of the specified number [@access public] [@since 4.4.004 (2008-12-10)].
-
#isRTLTextDir ⇒ Object
(also: #is_rtl_text_dir)
Return the current temporary RTL status [@return boolean] [@access public] [@since 4.8.014 (2009-11-04)].
-
#lastPage(resetmargins = false) ⇒ Object
(also: #last_page)
Reset pointer to the last document page.
-
#Line(x1, y1, x2, y2, style = nil) ⇒ Object
(also: #line)
Draws a line between two points.
-
#Link(x, y, w, h, link, spaces = 0) ⇒ Object
(also: #link)
Puts a link on a rectangular area of the page.
-
#Ln(h = '', cell = false) ⇒ Object
(also: #ln)
Performs a line break.
- #logger ⇒ Object
-
#movePage(frompage, topage) ⇒ Object
(also: #move_page)
Move a page to a previous position.
-
#MultiCell(w, h, txt, border = 0, align = 'J', fill = 0, ln = 1, x = '', y = '', reseth = true, stretch = 0, ishtml = false, autopadding = true, maxh = 0) ⇒ Object
(also: #multi_cell)
This method allows printing text with line breaks.
-
#objclone(object) ⇒ Object
Creates a copy of a class object [@param object :object] class object to be cloned [@return] cloned object [@access public] [@since 4.5.029 (2009-03-19)].
-
#Open ⇒ Object
This method begins the generation of the PDF document.
-
#Output(name = '', dest = '') ⇒ Object
(also: #output)
Send the document to a given destination: string, local file or browser.
-
#PageNo ⇒ Object
(also: #page_no)
Returns the current page number.
-
#PageNoFormatted ⇒ Object
(also: #page_no_formatted)
Returns the current page number formatted as a string.
-
#PieSector(xc, yc, r, a, b, style = 'FD', cw = true, o = 90) ⇒ Object
(also: #pie_sector)
Draw the sector of a circle.
-
#PieSectorXY(xc, yc, rx, ry, a, b, style = 'FD', cw = false, o = 0, nc = 2) ⇒ Object
(also: #pie_sector_xy)
Draw the sector of an ellipse.
-
#pixelsToUnits(px) ⇒ Object
(also: #pixels_to_units)
Converts pixels to Units.
-
#Polygon(p, style = '', line_style = nil, fill_color = nil, closed = true) ⇒ Object
(also: #polygon)
Draws a polygon.
-
#PolyLine(p, style = '', line_style = nil, fill_color = nil) ⇒ Object
(also: #poly_line)
Draws a polygonal line [@param array :p] Points 0 to (:np - 1).
-
#Rect(x, y, w, h, style = '', border_style = {}, fill_color = {}) ⇒ Object
(also: #rect)
Draws a rectangle.
-
#RegularPolygon(x0, y0, r, ns, angle = 0, draw_circle = false, style = '', line_style = nil, fill_color = nil, circle_style = '', circle_outLine_style = nil, circle_fill_color = nil) ⇒ Object
(also: #regular_polygon)
Draws a regular polygon.
-
#removeSHY(txt = '') ⇒ Object
(also: #remove_shy)
Removes SHY characters from text.
-
#revstrpos(haystack, needle, offset = 0) ⇒ Object
Find position of last occurrence of a substring in a string [@param string :haystack] The string to search in.
-
#rollbackTransaction(this_self = false) ⇒ Object
(also: #rollback_transaction)
This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
-
#Rotate(angle, x = "", y = "") ⇒ Object
(also: #rotate)
Rotate object.
-
#RoundedRect(x, y, w, h, r, round_corner = '1111', style = '', border_style = nil, fill_color = nil) ⇒ Object
(also: #rounded_rect)
Draws a rounded rectangle.
-
#RoundedRectXY(x, y, w, h, rx, ry, round_corner = '1111', style = '', border_style = nil, fill_color = nil) ⇒ Object
(also: #rounded_rect_xy)
Draws a rounded rectangle.
-
#setAlpha(alpha, bm = 'Normal') ⇒ Object
(also: #set_alpha)
Set alpha for stroking (CA) and non-stroking (ca) operations.
-
#SetAuthor(author) ⇒ Object
(also: #set_author)
Defines the author of the document.
-
#SetAutoPageBreak(auto, margin = 0) ⇒ Object
(also: #set_auto_page_break)
Enables or disables the automatic page breaking mode.
-
#SetBooklet(booklet = true, inner = -1,, outer = -1)) ⇒ Object
(also: #set_booklet)
Set the booklet mode for double-sided pages.
-
#setCellHeightRatio(h) ⇒ Object
(also: #set_cell_height_ratio)
Set the height of cell repect font height.
-
#SetCellPadding(pad) ⇒ Object
(also: #set_cell_padding)
Set the internal Cell padding.
-
#SetCompression(compress) ⇒ Object
(also: #set_compression)
Activates or deactivates page compression.
-
#SetCreator(creator) ⇒ Object
(also: #set_creator)
Defines the creator of the document.
-
#SetDefaultMonospacedFont(font) ⇒ Object
(also: #set_default_monospaced_font)
Defines the default monospaced font.
-
#SetDisplayMode(zoom, layout = 'SinglePage', mode = 'UseNone') ⇒ Object
(also: #set_display_mode)
Defines the way the document is to be displayed by the viewer.
-
#SetDrawColor(col1 = 0, col2 = -1,, col3 = -1,, col4 = -1)) ⇒ Object
(also: #set_draw_color)
Defines the color used for all drawing operations (lines, rectangles and cell borders).
-
#SetDrawColorArray(color) ⇒ Object
(also: #set_draw_color_array)
Defines the color used for all drawing operations (lines, rectangles and cell borders).
-
#SetFillColor(col1 = 0, col2 = -1,, col3 = -1,, col4 = -1)) ⇒ Object
(also: #set_fill_color)
Defines the color used for all filling operations (filled rectangles and cell backgrounds).
-
#SetFillColorArray(color) ⇒ Object
(also: #set_fill_color_array)
Defines the color used for all filling operations (filled rectangles and cell backgrounds).
-
#SetFont(family, style = '', size = 0, fontfile = '') ⇒ Object
(also: #set_font)
Sets the font used to print character strings.
-
#SetFontSize(size) ⇒ Object
(also: #set_font_size)
Defines the size of the current font.
-
#setFooterFont(font) ⇒ Object
(also: #set_footer_font)
Set footer font.
- #SetFooterFont(font) ⇒ Object
-
#setFooterMargin(fm = 10) ⇒ Object
(also: #set_footer_margin)
Set footer margin.
- #SetFooterMargin(fm = 10) ⇒ Object
-
#setHeaderData(ln = "", lw = 0, ht = "", hs = "") ⇒ Object
(also: #set_header_data)
Set header data.
- #SetHeaderData(ln = "", lw = 0, ht = "", hs = "") ⇒ Object
- #SetHeaderFont(font) ⇒ Object
-
#setHeaderFont(font) ⇒ Object
(also: #set_header_font)
Set header font.
-
#setHeaderMargin(hm = 10) ⇒ Object
(also: #set_header_margin)
Set header margin.
- #SetHeaderMargin(hm = 10) ⇒ Object
-
#setHtmlVSpace(tagvs) ⇒ Object
(also: #set_html_v_space)
Set the vertical spaces for HTML tags.
-
#setImageScale(scale) ⇒ Object
(also: #set_image_scale)
Set the adjusting factor to convert pixels to user units.
- #SetImageScale(scale) ⇒ Object
-
#setJPEGQuality(quality) ⇒ Object
(also: #set_jpeg_quality)
Set the default JPEG compression quality (1-100) [@param int :quality] JPEG quality, integer between 1 and 100 [@access public] [@since 3.0.000 (2008-03-27)].
-
#SetKeywords(keywords) ⇒ Object
(also: #set_keywords)
Associates keywords with the document, generally in the form ‘keyword1 keyword2 …’.
- #SetLanguageArray(language) ⇒ Object
-
#setLanguageArray(language) ⇒ Object
(also: #set_language_array)
Set language array.
-
#setLastH(h) ⇒ Object
(also: #set_last_h)
Set the last cell height.
-
#SetLeftMargin(margin) ⇒ Object
(also: #set_left_margin)
Defines the left margin.
-
#SetLineStyle(style) ⇒ Object
(also: #set_line_style)
Set line style.
-
#SetLineWidth(width) ⇒ Object
(also: #set_line_width)
Defines the line width.
-
#SetLink(link, y = 0, page = -1)) ⇒ Object
(also: #set_link)
Defines the page and position a link points to [@param int :link] The link identifier returned by AddLink() [@param float :y] Ordinate of target position; -1 indicates the current position.
-
#SetMargins(left, top, right = -1,, keepmargins = false) ⇒ Object
(also: #set_margins)
Defines the left, top and right margins.
-
#setPage(pnum, resetmargins = false) ⇒ Object
(also: #set_page)
Move pointer at the specified document page and update page dimensions.
-
#setPageBoxes(page, type, llx, lly, urx, ury) ⇒ Object
(also: #set_page_boxes)
Set page boundaries.
-
#setPageMark ⇒ Object
(also: #set_page_mark)
Set start-writing mark on current page stream used to put borders and fills.
-
#setPageOrientation(orientation, autopagebreak = '', bottommargin = '') ⇒ Object
(also: #set_page_orientation)
Set page orientation.
-
#setPageUnit(unit) ⇒ Object
(also: #set_page_unit)
Set the units of measure for the document.
-
#setPDFVersion(version = '1.7') ⇒ Object
(also: #set_pdf_version)
Set the PDF version (check PDF reference for valid values).
-
#setPrintFooter(val = true) ⇒ Object
(also: #set_print_footer)
Set a flag to print page footer.
- #SetPrintFooter(val = true) ⇒ Object
- #SetPrintHeader(val = true) ⇒ Object
-
#setPrintHeader(val = true) ⇒ Object
(also: #set_print_header)
Set a flag to print page header.
-
#SetRightMargin(margin) ⇒ Object
(also: #set_right_margin)
Defines the right margin.
-
#setRTL(enable, resetx = true) ⇒ Object
(also: #set_rtl)
Enable or disable Right-To-Left language mode [@param Boolean :enable] if true enable Right-To-Left language mode.
-
#SetSubject(subject) ⇒ Object
(also: #set_subject)
Defines the subject of the document.
-
#setTempRTL(mode) ⇒ Object
(also: #set_temp_rtl)
Force temporary RTL language direction [@param mixed :mode] can be false, ‘L’ for LTR or ‘R’ for RTL [@access public] [@since 2.1.000 (2008-01-09)].
-
#SetTextColor(col1 = 0, col2 = -1,, col3 = -1,, col4 = -1)) ⇒ Object
(also: #set_text_color)
Defines the color used for text.
-
#SetTextColorArray(color) ⇒ Object
(also: #set_text_color_array)
Defines the color used for text.
-
#setTextRenderingMode(stroke = 0, fill = true, clip = false) ⇒ Object
(also: #set_text_rendering_mode)
Set Text rendering mode.
-
#SetTitle(title) ⇒ Object
(also: #set_title)
Defines the title of the document.
-
#SetTopMargin(margin) ⇒ Object
(also: #set_top_margin)
Defines the top margin.
-
#setViewerPreferences(preferences) ⇒ Object
(also: #set_viewer_preferences)
Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
-
#setVisibility(v) ⇒ Object
(also: #set_visibility)
Set the visibility of the successive elements.
-
#SetX(x, rtloff = false) ⇒ Object
(also: #set_x)
Defines the abscissa of the current position.
-
#SetXY(x, y, rtloff = false) ⇒ Object
(also: #set_xy)
Defines the abscissa and ordinate of the current position.
-
#SetY(y, resetx = true, rtloff = false) ⇒ Object
(also: #set_y)
Moves the current abscissa back to the left margin and sets the ordinate.
-
#StarPolygon(x0, y0, r, nv, ng, angle = 0, draw_circle = false, style = '', line_style = nil, fill_color = nil, circle_style = '', circle_outLine_style = nil, circle_fill_color = nil) ⇒ Object
(also: #star_polygon)
Draws a star polygon [@param float :x0] Abscissa of center point.
-
#startPage(orientation = '', format = '', tocpage = false) ⇒ Object
(also: #start_page)
Starts a new page to the document.
-
#startPageGroup(page = '') ⇒ Object
(also: #start_page_group)
Create a new page group.
-
#startTransaction ⇒ Object
(also: #start_transaction)
Stores a copy of the current TCPDF object used for undo operation.
-
#StartTransform ⇒ Object
(also: #start_transform)
Starts a 2D tranformation saving current graphic state.
-
#StopTransform ⇒ Object
(also: #stop_transform)
Stops a 2D tranformation restoring previous graphic state.
-
#Text(x, y, txt, fstroke = false, fclip = false, ffill = true, border = 0, ln = 0, align = '', fill = 0, link = '', stretch = 0, ignore_min_height = false, calign = 'T', valign = 'M', rtloff = false) ⇒ Object
(also: #text)
Prints a text cell at the specified position.
-
#unhtmlentities(string) ⇒ Object
Reverse function for htmlentities.
-
#UniArrSubString(uniarr, start = 0, last = uniarr.length) ⇒ Object
(also: #uni_arr_sub_string)
Extract a slice of the :uniarr array and return it as string.
-
#unichr(c) ⇒ Object
Returns the unicode caracter specified by UTF-8 value [@param int :c] UTF-8 value (UCS4) [@return] Returns the specified character.
-
#UTF8ArrayToUniArray(ta) ⇒ Object
(also: #utf8_array_to_uni_array)
Convert an array of UTF8 values to array of unicode characters [@param string :ta] The input array of UTF8 values.
-
#UTF8ArrSubString(strarr, start = 0, last = strarr.size) ⇒ Object
(also: #utf8_arr_sub_string)
Extract a slice of the :strarr array and return it as string.
-
#Write(h, txt, link = nil, fill = 0, align = '', ln = false, stretch = 0, firstline = false, firstblock = false, maxh = 0) ⇒ Object
(also: #write)
This method prints text from the current position.
-
#writeHTML(html, ln = true, fill = 0, reseth = false, cell = false, align = '') ⇒ Object
(also: #write_html)
Allows to preserve some HTML formatting (limited support).
-
#writeHTMLCell(w, h, x, y, html = '', border = 0, ln = 0, fill = 0, reseth = true, align = '', autopadding = true) ⇒ Object
(also: #write_html_cell)
Prints a cell (rectangular area) with optional borders, background color and html text string.
Methods included from RFPDF
Constructor Details
#initialize(orientation = 'P', unit = 'mm', format = 'A4', unicode = true, encoding = "UTF-8", diskcache = false) ⇒ TCPDF
This is the class constructor. It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
- @param string :orientation
-
page orientation. Possible values are (case insensitive):
-
P or Portrait (default)
-
L or Landscape
-
- @param string :unit
-
User measure unit. Possible values are:
-
pt: point
-
mm: millimeter (default)
-
cm: centimeter
-
in: inch
A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
-
- @param mixed :format
-
The format used for pages. It can be either: A string indicating the page format:
-
4A0,2A0,A0,A1,A2,A3,A4 (default),A5,A6,A7,A8,A9,A10
-
B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10
-
C0,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10
-
RA0,RA1,RA2,RA3,RA4
-
SRA0,SRA1,SRA2,SRA3,SRA4
-
LETTER,LEGAL,EXECUTIVE,FOLIO
An array containing page measures and advanced options: see setPageFormat()
-
- @param boolean :unicode
-
TRUE means that the input text is unicode (default = true)
- @param String :encoding
-
charset encoding; default is UTF-8
- @param boolean :diskcache
-
if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
- @access public
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/tcpdf.rb', line 233 def initialize(orientation = 'P', unit = 'mm', format = 'A4', unicode = true, encoding = "UTF-8", diskcache = false) # Set internal character encoding to ASCII# #FIXME 2007-05-25 (EJM) Level=0 - # if (respond_to?("mb_internal_encoding") and mb_internal_encoding()) # @internal_encoding = mb_internal_encoding(); # mb_internal_encoding("ASCII"); # } @@k_path_cache = Rails.root.join('tmp').to_s @@k_path_main = Rails.root.join('tmp').to_s @@k_path_url = Rails.root.join('tmp').to_s # set disk caching @diskcache = diskcache ? true : false # set language direction @rtl = false @tmprtl = false @x ||= 0 @y ||= 0 ####################### @offsets ||= [] @alias_nb_pages = '{nb}' @alias_num_page = '{pnb}' @img_scale ||= 1 @r_margin ||= 0 @l_margin ||= 0 @page_annots ||= [] @header_font ||= ['', '', 10] @footer_font ||= ['', '', 8] @l ||= {} @header_margin ||= 10 @footer_margin ||= 10 @barcode ||= false @print_header ||= true @print_footer ||= true @header_width ||= 0 @header_logo ||= "" @header_logo_width ||= 30 @header_title ||= "" @header_string ||= "" @default_table_columns ||= 4 @listordered ||= [] @listcount ||= [] @listindent ||= 0 @listindentlevel ||= 0 @lispacer ||= "" # bookmark @outlines ||= [] # --- javascript and form --- @javascript ||= '' @js_objects ||= [] @dpi = 72.0 @newpagegroup ||= [] @pagegroups ||= {} @visibility ||= 'all' @cell_height_ratio = @@k_cell_height_ratio @viewer_preferences ||= {} @intmrk ||= [] @cntmrk ||= [] @footerpos ||= [] @footerlen ||= [] @newline ||= true @endlinex ||= 0 @open_marked_content ||= false @htmlvspace ||= 0 @spot_colors ||= {} @lisymbol ||= '' @epsmarker ||= 'x#!#EPS#!#x' @transfmatrix ||= [] @transfmatrix_key ||= 0 @booklet ||= false @feps ||= 0.005 @tagvspaces ||= {} @customlistindent ||= -1 @opencell = true @embeddedfiles ||= {} @html_link_color_array ||= [0, 0, 255] @html_link_font_style ||= 'U' @numpages ||= 0 @pagelen ||= [] @numimages ||= 0 @imagekeys ||= [] @bufferlen ||= 0 @numfonts ||= 0 @fontkeys ||= [] @font_obj_ids ||= {} @pageopen ||= [] @default_monospaced_font = 'courier' @cache_file_length = {} @thead ||= '' @thead_margins ||= {} @cache_utf8_string_to_array = {} @cache_maxsize_utf8_string_to_array = 8 @cache_size_utf8_string_to_array = 0 @signature_data ||= {} @sig_annot_ref ||= '***SIGANNREF*** 0 R' @page_obj_id ||= [] @embedded_start_obj_id ||= 100000 @form_obj_id ||= [] @apxo_start_obj_id ||= 400000 @apxo_obj_id ||= 400000 @annotation_fonts ||= {} @radiobutton_groups ||= [] @radio_groups ||= [] @textindent ||= 0 @start_transaction_y ||= 0 @in_thead ||= false @columns ||= [] @num_columns ||= 0 @current_column ||= 0 @column_start_page ||= 0 # Text rendering mode: # 0 = Fill text; # 1 = Stroke text; # 2 = Fill, then stroke text; # 3 = Neither fill nor stroke text (invisible); # 4 = Fill text and add to path for clipping; # 5 = Stroke text and add to path for clipping; # 6 = Fill, then stroke text and add to path for clipping; # 7 = Add text to path for clipping. @textrendermode ||= 0 @textstrokewidth ||= 0 @pdfunit ||= 'mm' @tocpage ||= false ####################### #Some checks dochecks(); begin @@decoder = HTMLEntities.new rescue @@decoder = nil end #Initialization of properties @is_unicode = unicode @page ||= 0 @transfmrk ||= [] @pagedim ||= [] @n ||= 2 if @diskcache @buffer ||= nil else @buffer ||= '' end @pages ||= [] @prev_pages ||= [] @state ||= 0 @fonts ||= {} @font_files ||= {} @diffs ||= [] @images ||= {} @links ||= [] @gradients ||= [] @in_footer ||= false @lasth ||= 0 @font_family ||= 'helvetica' @font_style ||= '' @font_size_pt ||= 12 @underline ||= false @overline ||= false @linethrough ||= false @draw_color ||= '0 G' @fill_color ||= '0 g' @text_color ||= '0 g' @color_flag ||= false # encryption values @encrypted ||= false @last_enc_key ||= '' # Standard Unicode fonts @core_fonts = { 'courier'=>'Courier', 'courierB'=>'Courier-Bold', 'courierI'=>'Courier-Oblique', 'courierBI'=>'Courier-BoldOblique', 'helvetica'=>'Helvetica', 'helveticaB'=>'Helvetica-Bold', 'helveticaI'=>'Helvetica-Oblique', 'helveticaBI'=>'Helvetica-BoldOblique', 'times'=>'Times-Roman', 'timesB'=>'Times-Bold', 'timesI'=>'Times-Italic', 'timesBI'=>'Times-BoldItalic', 'symbol'=>'Symbol', 'zapfdingbats'=>'ZapfDingbats'} # Set scale factor setPageUnit(unit) # set page format and orientation setPageFormat(format, orientation) # Page margins (1 cm) margin = 28.35/@k SetMargins(margin, margin) #Interior cell margin (1 mm) @c_margin = margin / 10 #Line width (0.2 mm) @line_width = 0.57 / @k @linestyle_width ||= sprintf('%.2f w', (@line_width * @k)) @linestyle_cap ||= '0 J' @linestyle_join ||= '0 j' @linestyle_dash ||= '[] 0 d' #Automatic page break SetAutoPageBreak(true, 2 * margin) #Full width display mode SetDisplayMode('fullwidth') #Compression SetCompression(true) #Set default PDF version number @pdf_version ||= "1.7" @encoding = encoding @href ||= {} @fontlist ||= [] getFontsList() @fgcolor = ActiveSupport::OrderedHash.new @fgcolor['R'] = 0 @fgcolor['G'] = 0 @fgcolor['B'] = 0 @strokecolor = ActiveSupport::OrderedHash.new @strokecolor['R'] = 0 @strokecolor['G'] = 0 @strokecolor['B'] = 0 @bgcolor = ActiveSupport::OrderedHash.new @bgcolor['R'] = 255 @bgcolor['G'] = 255 @bgcolor['B'] = 255 @extgstates ||= [] # user's rights @sign ||= false @ur = false @ur_document = "/FullSave" @ur_annots = "/Create/Delete/Modify/Copy/Import/Export" @ur_form = "/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate" @ur_signature = "/Modify" # set default JPEG quality @jpeg_quality ||= 75 # initialize some settings # utf8Bidi([''], '') # set default font SetFont(@font_family, @font_style, @font_size_pt) @annots_start_obj_id ||= 200000 @annot_obj_id ||= @annots_start_obj_id @curr_annot_obj_id ||= @annots_start_obj_id @apxo_obj_id ||= @apxo_start_obj_id end |
Instance Attribute Details
#barcode ⇒ Object
Returns the value of attribute barcode.
119 120 121 |
# File 'lib/tcpdf.rb', line 119 def @barcode end |
#buffer ⇒ Object
Returns the value of attribute buffer.
121 122 123 |
# File 'lib/tcpdf.rb', line 121 def buffer @buffer end |
#cache_file_length ⇒ Object
Returns the value of attribute cache_file_length.
199 200 201 |
# File 'lib/tcpdf.rb', line 199 def cache_file_length @cache_file_length end |
#color_flag ⇒ Object
Returns the value of attribute color_flag.
125 126 127 |
# File 'lib/tcpdf.rb', line 125 def color_flag @color_flag end |
#default_font ⇒ Object
Returns the value of attribute default_font.
129 130 131 |
# File 'lib/tcpdf.rb', line 129 def default_font @default_font end |
#default_table_columns ⇒ Object
Returns the value of attribute default_table_columns.
127 128 129 |
# File 'lib/tcpdf.rb', line 127 def default_table_columns @default_table_columns end |
#diffs ⇒ Object
Returns the value of attribute diffs.
123 124 125 |
# File 'lib/tcpdf.rb', line 123 def diffs @diffs end |
#diskcache ⇒ Object
Returns the value of attribute diskcache.
197 198 199 |
# File 'lib/tcpdf.rb', line 197 def diskcache @diskcache end |
#draw_color ⇒ Object
Returns the value of attribute draw_color.
131 132 133 |
# File 'lib/tcpdf.rb', line 131 def draw_color @draw_color end |
#encoding ⇒ Object
Returns the value of attribute encoding.
133 134 135 |
# File 'lib/tcpdf.rb', line 133 def encoding @encoding end |
#fill_color ⇒ Object
Returns the value of attribute fill_color.
135 136 137 |
# File 'lib/tcpdf.rb', line 135 def fill_color @fill_color end |
#font_family ⇒ Object
Returns the value of attribute font_family.
139 140 141 |
# File 'lib/tcpdf.rb', line 139 def font_family @font_family end |
#font_files ⇒ Object
Returns the value of attribute font_files.
141 142 143 |
# File 'lib/tcpdf.rb', line 141 def font_files @font_files end |
#font_size_pt ⇒ Object
Returns the value of attribute font_size_pt.
147 148 149 |
# File 'lib/tcpdf.rb', line 147 def font_size_pt @font_size_pt end |
#font_style ⇒ Object
Returns the value of attribute font_style.
145 146 147 |
# File 'lib/tcpdf.rb', line 145 def font_style @font_style end |
#fonts ⇒ Object
Returns the value of attribute fonts.
137 138 139 |
# File 'lib/tcpdf.rb', line 137 def fonts @fonts end |
#header_logo ⇒ Object
Returns the value of attribute header_logo.
151 152 153 |
# File 'lib/tcpdf.rb', line 151 def header_logo @header_logo end |
#header_logo_width ⇒ Object
Returns the value of attribute header_logo_width.
153 154 155 |
# File 'lib/tcpdf.rb', line 153 def header_logo_width @header_logo_width end |
#header_string ⇒ Object
Returns the value of attribute header_string.
157 158 159 |
# File 'lib/tcpdf.rb', line 157 def header_string @header_string end |
#header_title ⇒ Object
Returns the value of attribute header_title.
155 156 157 |
# File 'lib/tcpdf.rb', line 155 def header_title @header_title end |
#header_width ⇒ Object
Returns the value of attribute header_width.
149 150 151 |
# File 'lib/tcpdf.rb', line 149 def header_width @header_width end |
#images ⇒ Object
Returns the value of attribute images.
159 160 161 |
# File 'lib/tcpdf.rb', line 159 def images @images end |
#img_scale ⇒ Object
Returns the value of attribute img_scale.
161 162 163 |
# File 'lib/tcpdf.rb', line 161 def img_scale @img_scale end |
#in_footer ⇒ Object
Returns the value of attribute in_footer.
163 164 165 |
# File 'lib/tcpdf.rb', line 163 def @in_footer end |
#is_unicode ⇒ Object
Returns the value of attribute is_unicode.
165 166 167 |
# File 'lib/tcpdf.rb', line 165 def is_unicode @is_unicode end |
#lasth ⇒ Object
Returns the value of attribute lasth.
167 168 169 |
# File 'lib/tcpdf.rb', line 167 def lasth @lasth end |
#links ⇒ Object
Returns the value of attribute links.
169 170 171 |
# File 'lib/tcpdf.rb', line 169 def links @links end |
#lispacer ⇒ Object
Returns the value of attribute lispacer.
175 176 177 |
# File 'lib/tcpdf.rb', line 175 def lispacer @lispacer end |
#listcount ⇒ Object
Returns the value of attribute listcount.
173 174 175 |
# File 'lib/tcpdf.rb', line 173 def listcount @listcount end |
#listordered ⇒ Object
Returns the value of attribute listordered.
171 172 173 |
# File 'lib/tcpdf.rb', line 171 def listordered @listordered end |
#n ⇒ Object
Returns the value of attribute n.
177 178 179 |
# File 'lib/tcpdf.rb', line 177 def n @n end |
#offsets ⇒ Object
Returns the value of attribute offsets.
179 180 181 |
# File 'lib/tcpdf.rb', line 179 def offsets @offsets end |
#page ⇒ Object
Returns the value of attribute page.
181 182 183 |
# File 'lib/tcpdf.rb', line 181 def page @page end |
#pages ⇒ Object
Returns the value of attribute pages.
183 184 185 |
# File 'lib/tcpdf.rb', line 183 def pages @pages end |
#pdf_version ⇒ Object
Returns the value of attribute pdf_version.
185 186 187 |
# File 'lib/tcpdf.rb', line 185 def pdf_version @pdf_version end |
#prev_pages ⇒ Object
Returns the value of attribute prev_pages.
201 202 203 |
# File 'lib/tcpdf.rb', line 201 def prev_pages @prev_pages end |
#print_footer ⇒ Object
Returns the value of attribute print_footer.
189 190 191 |
# File 'lib/tcpdf.rb', line 189 def @print_footer end |
#print_header ⇒ Object
Returns the value of attribute print_header.
187 188 189 |
# File 'lib/tcpdf.rb', line 187 def print_header @print_header end |
#state ⇒ Object
Returns the value of attribute state.
191 192 193 |
# File 'lib/tcpdf.rb', line 191 def state @state end |
#text_color ⇒ Object
Returns the value of attribute text_color.
193 194 195 |
# File 'lib/tcpdf.rb', line 193 def text_color @text_color end |
#underline ⇒ Object
Returns the value of attribute underline.
195 196 197 |
# File 'lib/tcpdf.rb', line 195 def underline @underline end |
Instance Method Details
#AcceptPageBreak ⇒ Object Also known as: accept_page_break
Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by SetAutoPageBreak(). This method is called automatically and should not be called directly by the application.
- @return boolean
- @access public
- @since 1.4
- @see
- @access public
-
SetAutoPageBreak()
3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 |
# File 'lib/tcpdf.rb', line 3131 def AcceptPageBreak() #if @num_columns > 1 # # multi column mode # if @current_column < (@num_columns - 1) # # go to next column # selectColumn(@current_column + 1) # else # # add a new page # AddPage() # # set first column # selectColumn(0) # end # # avoid page breaking from checkPageBreak() # return false #end return @auto_page_break; end |
#AddFont(family, style = '', fontfile = '') ⇒ Object Also known as: add_font
Imports a TrueType, Type1, core, or CID0 font and makes it available. It is necessary to generate a font definition file first with the makefont.rb utility. The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by FPDF_FONTPATH if the constant is defined. If it could not be found, the error “Could not include font definition file” is generated.
Example
:pdf.add_font('Comic','I')
# is equivalent to:
:pdf.add_font('Comic','I','comici.rb')
- @param string :family
-
Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
- @param string :style
-
Font style. Possible values are (case insensitive):
-
empty string: regular (default)
-
B: bold
-
I: italic
-
BI or IB: bold italic
-
- @param string :fontfile
-
The font definition file. By default, the name is built from the family and style, in lower case with no space.
- @return array
-
containing the font data, or false in case of error.
- @access public
- @since 1.5
- @see
- @since 1.5
-
SetFont()
2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 |
# File 'lib/tcpdf.rb', line 2555 def AddFont(family, style='', fontfile='') if empty_string(family) if !empty_string(@font_family) family = @font_family else Error('Empty font family') end end family = family.downcase if ((!@is_unicode) and (family == 'arial')) family = 'helvetica'; end if (family == "symbol") or (family == "zapfdingbats") style = '' end tempstyle = style.upcase style = '' # underline if tempstyle.index('U') != nil @underline = true else @underline = false end # line-through (deleted) if tempstyle.index('D') != nil @linethrough = true else @linethrough = false end # overline if tempstyle.index('O') != nil @overline = true else @overline = false end # bold if tempstyle.index('B') != nil style << 'B'; end # oblique if tempstyle.index('I') != nil style << 'I'; end bistyle = style fontkey = family + style; font_style = style + (@underline ? 'U' : '') + (@linethrough ? 'D' : '') + (@overline ? 'O' : '') fontdata = {'fontkey' => fontkey, 'family' => family, 'style' => font_style} # check if the font has been already added if getFontBuffer(fontkey) != false return fontdata end # get specified font directory (if any) fontdir = false if !empty_string(fontfile) fontdir = File.dirname(fontfile) if empty_string(fontdir) or (fontdir == '.') fontdir = '' else fontdir << '/' end end # search and include font file if empty_string(fontfile) # build a standard filenames for specified font fontfile1 = family.gsub(' ', '') + style.downcase + '.rb' fontfile2 = family.gsub(' ', '') + '.rb' # search files on various directories if (fontdir != false) and File.exists?(fontdir + fontfile1) fontfile = fontdir + fontfile1 fontname = fontfile1 elsif fontfile = getfontpath(fontfile1) fontname = fontfile1 elsif File.exists?(fontfile1) fontfile = fontfile1 fontname = fontfile1 elsif (fontdir != false) and File.exists?(fontdir + fontfile2) fontfile = fontdir + fontfile2 fontname = fontfile2 elsif fontfile = getfontpath(fontfile2) fontname = fontfile2 else fontfile = fontfile2 fontname = fontfile2 end end # include font file if File.exists?(fontfile) require(fontfile) else Error('Could not include font definition file: ' + family + '') end font_desc = TCPDFFontDescriptor.font(fontname) if font_desc[:desc].nil? desc = {} else desc = font_desc[:desc].dup end # check font parameters if font_desc[:type].nil? or font_desc[:cw].nil? Error('The font definition file has a bad format: ' + fontfile + '') end # SET default parameters font_desc[:file] ||= '' font_desc[:enc] ||= '' if font_desc[:cidinfo].nil? font_desc[:cidinfo] = {'Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0} font_desc[:cidinfo]['uni2cid'] = {} end font_desc[:ctg] ||= '' font_desc[:up] ||= -100 font_desc[:ut] ||= 50 font_desc[:cw] ||= {} if empty_string(font_desc[:dw]) # set default width if !desc['MissingWidth'].nil? and (desc['MissingWidth'] > 0) font_desc[:dw] = desc['MissingWidth'] elsif font_desc[:cw][32] font_desc[:dw] = font_desc[:cw][32] else font_desc[:dw] = 600 end end @numfonts += 1 if font_desc[:type] == 'cidfont0' # register CID font (all styles at once) styles = {'' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic'} sname = font_desc[:name] + styles[bistyle] # artificial bold if bistyle.index('B') != nil if desc['StemV'] desc['StemV'] *= 2 else desc['StemV'] = 120 end end # artificial italic if bistyle.index('I') != nil if desc['ItalicAngle'] desc['ItalicAngle'] -= 11 else desc['ItalicAngle'] = -11 end end setFontBuffer(fontkey, {'i' => @numfonts, 'type' => font_desc[:type], 'name' => sname, 'desc' => desc, 'cidinfo' => font_desc[:cidinfo], 'up' => font_desc[:up], 'ut' => font_desc[:ut], 'cw' => font_desc[:cw], 'dw' => font_desc[:dw], 'enc' => font_desc[:enc]}) elsif font_desc[:type] == 'core' font_desc[:name] = @core_fonts[fontkey] elsif (font_desc[:type] == 'TrueType') or (font_desc[:type] == 'Type1') # ... elsif font_desc[:type] == 'TrueTypeUnicode' font_desc[:enc] = 'Identity-H' else Error('Unknow font type: ' + type + '') end setFontBuffer(fontkey, {'i' => @numfonts, 'type' => font_desc[:type], 'name' => font_desc[:name], 'desc' => desc, 'up' => font_desc[:up], 'ut' => font_desc[:ut], 'cw' => font_desc[:cw], 'dw' => font_desc[:dw], 'enc' => font_desc[:enc], 'cidinfo' => font_desc[:cidinfo], 'file' => font_desc[:file], 'ctg' => font_desc[:ctg]}) if (!font_desc[:diff].nil? and (!font_desc[:diff].empty?)) #Search existing encodings d=0; nb=@diffs.length; 1.upto(nb) do |i| if (@diffs[i]== font_desc[:diff]) d = i; break; end end if (d==0) d = nb+1; @diffs[d] = font_desc[:diff]; end setFontSubBuffer(fontkey, 'diff', d) end if !empty_string(font_desc[:file]) if (font_desc[:type] == 'TrueType') or (font_desc[:type] == 'TrueTypeUnicode') @font_files[font_desc[:file]] = {'length1' => font_desc[:originalsize], 'fontdir' => fontdir} elsif font_desc[:type] != 'core' @font_files[font_desc[:file]] = {'length1' => font_desc[:size1], 'length2' => font_desc[:size2], 'fontdir' => fontdir} end end return fontdata end |
#addHtmlLink(url, name, fill = 0, firstline = false, color = '', style = -1,, firstblock = false) ⇒ Object Also known as: add_html_link
Output anchor link.
- @param string :url
-
link URL or internal link (i.e.: <a href=“#23”>link to page 23</a>)
- @param string :name
-
link name
- @param int :fill
-
Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
- @param boolean :firstline
-
if true prints only the first line and return the remaining string.
- @param array :color
-
array of RGB text color
- @param string :style
-
font style (U, D, B, I)
- @param boolean :firstblock
-
if true the string is the starting of a line.
- @return
-
the number of cells used or the remaining text if :firstline = true
- @access public
7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 |
# File 'lib/tcpdf.rb', line 7638 def addHtmlLink(url, name, fill=0, firstline=false, color='', style=-1, firstblock=false) if !empty_string(url) and (url[0, 1] == '#') # convert url to internal link page = url.sub(/^#/, "").to_i url = AddLink() SetLink(url, 0, page) end # store current settings prevcolor = @fgcolor prevstyle = @font_style if color.empty? SetTextColorArray(@html_link_color_array) else SetTextColorArray(color) end if style == -1 SetFont('', @font_style + @html_link_font_style) else SetFont('', @font_style + style) end ret = Write(@lasth, name, url, fill, '', false, 0, firstline, firstblock, 0) # restore settings SetFont('', prevstyle) SetTextColorArray(prevcolor) return ret end |
#addHTMLTOC(page = '', toc_name = 'TOC', templates = [], correct_align = true) ⇒ Object Also known as: add_html_toc
Output a Table Of Content Index (TOC) using HTML templates. Before calling this method you have to open the page using the addTOCPage() method. After calling this method you have to call endTOCPage() to close the TOC page.
- @param int :page
-
page number where this TOC should be inserted (leave empty for current page).
- @param string :toc_name
-
name to use for TOC bookmark.
- @param array :templates
-
array of html templates. Use: #TOC_DESCRIPTION# for bookmark title, #TOC_PAGE_NUMBER# for page number.
- @parma boolean :correct_align
-
if true correct the number alignment (numbers must be in monospaced font like courier and right aligned on LTR, or left aligned on RTL)
- @access public
- @author
-
Nicola Asuni
- @since 5.0.001 (2010-05-06)
- @see
-
addTOCPage(), endTOCPage(), addTOC()
13847 13848 13849 13850 13851 13852 13853 13854 13855 13856 13857 13858 13859 13860 13861 13862 13863 13864 13865 13866 13867 13868 13869 13870 13871 13872 13873 13874 13875 13876 13877 13878 13879 13880 13881 13882 13883 13884 13885 13886 13887 13888 13889 13890 13891 13892 13893 13894 13895 13896 13897 13898 13899 13900 13901 13902 13903 13904 13905 13906 13907 13908 13909 13910 13911 13912 13913 13914 13915 13916 13917 13918 13919 13920 13921 13922 13923 13924 13925 13926 13927 13928 13929 13930 13931 13932 13933 13934 13935 |
# File 'lib/tcpdf.rb', line 13847 def addHTMLTOC(page='', toc_name='TOC', templates=[], correct_align=true) prev_htmlLinkColorArray = @html_link_color_array prev_htmlLinkFontStyle = @html_link_font_style # set new style for link @html_link_color_array = [] @html_link_font_style = '' page_first = getPage() @outlines.each_with_index do |outline, key| if empty_string(page) pagenum = outline[:p].to_s else # placemark to be replaced with the correct number pagenum = '{#' + outline[:p].to_s + '}' if (@current_font['type'] == 'TrueTypeUnicode') or (@current_font['type'] == 'cidfont0') pagenum = '{' + pagenum + '}' end end # get HTML template row = templates[outline[:l]] # replace templates with current values row = row.gsub('#TOC_DESCRIPTION#', outline[:t]) row = row.gsub('#TOC_PAGE_NUMBER#', pagenum) # add link to page row = '<a href="#' + outline[:p].to_s + '">' + row + '</a>' # write bookmark entry writeHTML(row, false, false, true, false, '') end # restore link styles @html_link_color_array = prev_htmlLinkColorArray @html_link_font_style = prev_htmlLinkFontStyle # move TOC page and replace numbers page_last = getPage() numpages = page_last - page_first + 1 if !empty_string(page) page_first.upto(page_last) do |p| # get page data temppage = getPageBuffer(p) 1.upto(@numpages) do |n| # update page numbers k = '{#' + n.to_s + '}' ku = '{' + k + '}' alias_a = escape(k) alias_au = escape('{' + k + '}') if @is_unicode alias_b = escape(UTF8ToLatin1(k)) alias_bu = escape(UTF8ToLatin1(ku)) alias_c = escape(utf8StrRev(k, false, @tmprtl)) alias_cu = escape(utf8StrRev(ku, false, @tmprtl)) end if n >= page np = n + numpages else np = n end ns = formatTOCPageNumber(np) nu = ns if correct_align sdiff = k.length - ns.length sdiffu = ku.length - ns.length sfill = ' ' * sdiff sfillu = ' ' * sdiffu if @rtl ns = ns + sfill nu = nu + sfillu else ns = sfill + ns nu = sfillu + nu end end nu = UTF8ToUTF16BE(nu, false) temppage = temppage.gsub(alias_au, nu) if @is_unicode temppage = temppage.gsub(alias_bu, nu) temppage = temppage.gsub(alias_cu, nu) temppage = temppage.gsub(alias_b, ns) temppage = temppage.gsub(alias_c, ns) end temppage = temppage.gsub(alias_a, ns) end # save changes setPageBuffer(p, temppage) end # move pages Bookmark(toc_name, 0, 0, page_first) 0.upto(numpages - 1) do |i| movePage(page_last, page) end end end |
#AddLink ⇒ Object Also known as: add_link
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().
- @access public
- @since 1.5
- @see
- @since 1.5
-
Cell(), Write(), Image(), Link(), SetLink()
2893 2894 2895 2896 2897 2898 |
# File 'lib/tcpdf.rb', line 2893 def AddLink() #Create a new internal link n=@links.length+1; @links[n]=[0,0]; return n; end |
#AddPage(orientation = '', format = '', keepmargins = false, tocpage = false) ⇒ Object Also known as: add_page
Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer (if enabled). Then the page is added, the current position set to the top-left corner according to the left and top margins (or top-right if in RTL mode), and Header() is called to display the header (if enabled). The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
- @param string :orientation
-
page orientation. Possible values are (case insensitive):
-
P or PORTRAIT (default)
-
L or LANDSCAPE
-
- @param mixed :format
-
The format used for pages. It can be either: A string indicating the page format:
-
4A0,2A0,A0,A1,A2,A3,A4 (default),A5,A6,A7,A8,A9,A10
-
B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10
-
C0,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10
-
RA0,RA1,RA2,RA3,RA4
-
SRA0,SRA1,SRA2,SRA3,SRA4
-
LETTER,LEGAL,EXECUTIVE,FOLIO
An array containing page measures and advanced options: see setPageFormat()
-
- @param boolean :keepmargins
-
if true overwrites the default page margins with the current margin
- @param boolean :tocpage
-
if true set the tocpage state to true (the added page will be used to display Table Of Content).
- @access public
- @since 1.0
- @see
- @since 1.0
-
startPage, endPage(), addTOCPage(), endTOCPage()
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 |
# File 'lib/tcpdf.rb', line 1632 def AddPage(orientation='', format='', keepmargins=false, tocpage=false) if @original_l_margin.nil? or keepmargins @original_l_margin = @l_margin end if @original_r_margin.nil? or keepmargins @original_r_margin = @r_margin end # terminate previous page endPage() # start new page startPage(orientation, format, tocpage) end |
#AddSpotColor(name, c, m, y, k) ⇒ Object Also known as: add_spot_color
Defines a new spot color. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
- @param int :c
-
Cyan color for CMYK. Value between 0 and 255
- @param int :m
-
Magenta color for CMYK. Value between 0 and 255
- @param int :y
-
Yellow color for CMYK. Value between 0 and 255
- @param int :k
-
Key (Black) color for CMYK. Value between 0 and 255
- @access public
- @since 4.0.024 (2008-09-12)
- @see
- @since 4.0.024 (2008-09-12)
-
SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
2148 2149 2150 2151 2152 2153 |
# File 'lib/tcpdf.rb', line 2148 def AddSpotColor(name, c, m, y, k) if @spot_colors[name].nil? i = 1 + @spot_colors.length @spot_colors[name] = {'i' => i, 'c' => c, 'm' => m, 'y' => y, 'k' => k} end end |
#addTOC(page = '', numbersfont = '', filler = '.', toc_name = 'TOC') ⇒ Object Also known as: add_toc
Output a Table of Content Index (TOC). Before calling this method you have to open the page using the addTOCPage() method. After calling this method you have to call endTOCPage() to close the TOC page. You can override this method to achieve different styles.
- @param int :page
-
page number where this TOC should be inserted (leave empty for current page).
- @param string :numbersfont
-
set the font for page numbers (please use monospaced font for better alignment).
- @param string :filler
-
string used to fill the space between text and page number.
- @param string :toc_name
-
name to use for TOC bookmark.
- @access public
- @author
-
Nicola Asuni
- @since 4.5.000 (2009-01-02)
- @see
-
addTOCPage(), endTOCPage(), addHTMLTOC()
13696 13697 13698 13699 13700 13701 13702 13703 13704 13705 13706 13707 13708 13709 13710 13711 13712 13713 13714 13715 13716 13717 13718 13719 13720 13721 13722 13723 13724 13725 13726 13727 13728 13729 13730 13731 13732 13733 13734 13735 13736 13737 13738 13739 13740 13741 13742 13743 13744 13745 13746 13747 13748 13749 13750 13751 13752 13753 13754 13755 13756 13757 13758 13759 13760 13761 13762 13763 13764 13765 13766 13767 13768 13769 13770 13771 13772 13773 13774 13775 13776 13777 13778 13779 13780 13781 13782 13783 13784 13785 13786 13787 13788 13789 13790 13791 13792 13793 13794 13795 13796 13797 13798 13799 13800 13801 13802 13803 13804 13805 13806 13807 13808 13809 13810 13811 13812 13813 13814 13815 13816 13817 13818 13819 13820 13821 13822 13823 13824 13825 13826 13827 13828 13829 13830 13831 |
# File 'lib/tcpdf.rb', line 13696 def addTOC(page='', numbersfont='', filler='.', toc_name='TOC') fontsize = @font_size_pt fontfamily = @font_family fontstyle = @font_style w = @w - @l_margin - @r_margin spacer = GetStringWidth(32.chr) * 4 page_first = getPage() lmargin = @l_margin rmargin = @r_margin x_start = GetX() if empty_string(numbersfont) numbersfont = @default_monospaced_font end if empty_string(filler) filler = ' ' end if empty_string(page) gap = ' ' else gap = '' end @outlines.each_with_index do |outline, key| if @rtl aligntext = 'R' alignnum = 'L' else aligntext = 'L' alignnum = 'R' end if outline[:l] == 0 SetFont(fontfamily, fontstyle + 'B', fontsize) else SetFont(fontfamily, fontstyle, fontsize - outline[:l]) end indent = spacer * outline[:l] if @rtl @r_margin += indent @x -= indent else @l_margin += indent @x += indent end link = AddLink() SetLink(link, 0, outline[:p]) # write the text Write(0, outline[:t], link, 0, aligntext, false, 0, false, false, 0) SetFont(numbersfont, fontstyle, fontsize) if empty_string(page) pagenum = outline[:p] else # placemark to be replaced with the correct number pagenum = '{#' + outline[:p].to_s + '}' if (@current_font['type'] == 'TrueTypeUnicode') or (@current_font['type'] == 'cidfont0') pagenum = '{' + pagenum + '}' end end numwidth = GetStringWidth(pagenum) if @rtl tw = @x - @l_margin else tw = @w - @r_margin - @x end fw = tw - numwidth - GetStringWidth(32.chr) numfills = (fw / GetStringWidth(filler)).floor if numfills > 0 rowfill = filler * numfills else rowfill = '' end if @rtl pagenum = pagenum + gap + rowfill + ' ' else pagenum = ' ' + rowfill + gap + pagenum end # write the number Cell(tw, 0, pagenum, 0, 1, alignnum, 0, link, 0) SetX(x_start) @l_margin = lmargin @r_margin = rmargin end page_last = getPage() numpages = page_last - page_first + 1 if !empty_string(page) page_first.upto(page_last) do |p| # get page data temppage = getPageBuffer(p) 1.upto(@numpages) do |n| # update page numbers k = '{#' + n.to_s + '}' ku = '{' + k + '}' alias_a = escape(k) alias_au = escape('{' + k + '}') if @is_unicode alias_b = escape(UTF8ToLatin1(k)) alias_bu = escape(UTF8ToLatin1(ku)) alias_c = escape(utf8StrRev(k, false, @tmprtl)) alias_cu = escape(utf8StrRev(ku, false, @tmprtl)) end if n >= page np = n + numpages else np = n end ns = formatTOCPageNumber(np) nu = ns sdiff = k.length - ns.length - 1 sdiffu = ku.length - ns.length - 1 sfill = filler * sdiff sfillu = filler * sdiffu if @rtl ns = ns + ' ' + sfill nu = nu + ' ' + sfillu else ns = sfill + ' ' + ns nu = sfillu + ' ' + nu end nu = UTF8ToUTF16BE(nu, false) temppage = temppage.gsub(alias_au, nu) if @is_unicode temppage = temppage.gsub(alias_bu, nu) temppage = temppage.gsub(alias_cu, nu) temppage = temppage.gsub(alias_b, ns) temppage = temppage.gsub(alias_c, ns) end temppage = temppage.gsub(alias_a, ns) end # save changes setPageBuffer(p, temppage) end # move pages Bookmark(toc_name, 0, 0, page_first) 0.upto(numpages - 1) do |i| movePage(page_last, page) end end end |
#addTOCPage(orientation = '', format = '', keepmargins = false) ⇒ Object Also known as: add_toc_page
Adds a new TOC (Table Of Content) page to the document.
- @param string :orientation
-
page orientation.
- @param boolean :keepmargins
-
if true overwrites the default page margins with the current margins
- @access public
- @since 5.0.001 (2010-05-06)
- @see
- @since 5.0.001 (2010-05-06)
-
AddPage(), startPage(), endPage(), endTOCPage()
1594 1595 1596 |
# File 'lib/tcpdf.rb', line 1594 def addTOCPage(orientation='', format='', keepmargins=false) AddPage(orientation, format, keepmargins, true) end |
#AliasNbPages(alias_nb = '{nb}') ⇒ Object Also known as: alias_nb_pages
Defines an alias for the total number of pages. It will be substituted as the document is closed.
- @param string :alias
-
The alias.
- @access public
- @since 1.4
- @see
- @since 1.4
-
getAliasNbPages(), PageNo(), Footer()
9431 9432 9433 |
# File 'lib/tcpdf.rb', line 9431 def AliasNbPages(alias_nb ='{nb}') @alias_nb_pages = alias_nb end |
#AliasNumPage(alias_num = '{pnb}') ⇒ Object Also known as: alias_num_page
Defines an alias for the page number. It will be substituted as the document is closed.
- @param string :alias
-
The alias.
- @access public
- @since 4.5.000 (2009-01-02)
- @see
- @since 4.5.000 (2009-01-02)
-
getAliasNbPages(), PageNo(), Footer()
9460 9461 9462 9463 |
# File 'lib/tcpdf.rb', line 9460 def AliasNumPage(alias_num='{pnb}') # Define an alias for total number of pages @alias_num_page = alias_num end |
#Annotation(x, y, w, h, text, opt = {'Subtype'=>'Text'}, spaces = 0) ⇒ Object Also known as: annotation
Puts a markup annotation on a rectangular area of the page.
-
!!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
- @param float :x
-
Abscissa of the upper-left corner of the rectangle
- @param float :y
-
Ordinate of the upper-left corner of the rectangle
- @param float :w
-
Width of the rectangle
- @param float :h
-
Height of the rectangle
- @param mixed :text
-
annotation text or alternate content
- @param array :opt
-
array of options (see section 8.4 of PDF reference 1.7).
- @param int :spaces
-
number of spaces on the text to link
- @access public
- @since 4.0.018 (2008-08-06)
2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 |
# File 'lib/tcpdf.rb', line 2952 def Annotation(x, y, w, h, text, opt={'Subtype'=>'Text'}, spaces=0) x = @x if x == '' y = @y if y == '' # recalculate coordinates to account for graphic transformations if !@transfmatrix.nil? @transfmatrix_key.downto(1) do |i| maxid = @transfmatrix[i].length - 1 maxid.downto(0) do |j| ctm = @transfmatrix[i][j] if !ctm['a'].nil? x = x * @k y = (@h - y) * @k w = w * @k h = h * @k # top left xt = x yt = y x1 = (ctm['a'] * xt) + (ctm['c'] * yt) + ctm['e'] y1 = (ctm['b'] * xt) + (ctm['d'] * yt) + ctm['f'] # top right xt = x + w yt = y x2 = (ctm['a'] * xt) + (ctm['c'] * yt) + ctm['e'] y2 = (ctm['b'] * xt) + (ctm['d'] * yt) + ctm['f'] # bottom left xt = x yt = y - h x3 = (ctm['a'] * xt) + (ctm['c'] * yt) + ctm['e'] y3 = (ctm['b'] * xt) + (ctm['d'] * yt) + ctm['f'] # bottom right xt = x + w yt = y - h x4 = (ctm['a'] * xt) + (ctm['c'] * yt) + ctm['e'] y4 = (ctm['b'] * xt) + (ctm['d'] * yt) + ctm['f'] # new coordinates (rectangle area) x = [x1, x2, x3, x4].min y = [y1, y2, y3, y4].max w = ([x1, x2, x3, x4].max - x) / @k h = (y - [y1, y2, y3, y4].min) / @k x = x / @k y = @h - (y / @k) end end end end if @page <= 0 page = 1 else page = @page end @page_annots[page] ||= [] @page_annots[page].push 'x' => x, 'y' => y, 'w' => w, 'h' => h, 'txt' => text, 'opt' => opt, 'numspaces' => spaces if ((opt['Subtype'] == 'FileAttachment') or (opt['Subtype'] == 'Sound')) and !empty_string(opt['FS']) and File.exist?(opt['FS']) and @embeddedfiles[File.basename(opt['FS'])].nil? @embeddedfiles[File.basename(opt['FS'])] = {'file' => opt['FS'], 'n' => (@embeddedfiles.length + @embedded_start_obj_id)} end # Add widgets annotation's icons if opt['mk'] and opt['mk']['i'] and File.exist?(opt['mk']['i']) Image(opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true) end if opt['mk'] and opt['mk']['ri'] and File.exist?(opt['mk']['ri']) Image(opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true) end if opt['mk'] and opt['mk']['ix'] and File.exist?(opt['mk']['ix']) Image(opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true) end @annot_obj_id += 1 end |
#Arrow(x0, y0, x1, y1, head_style = 0, arm_size = 5, arm_angle = 15) ⇒ Object Also known as: arrow
Draws a grahic arrow.
- @parameter float :x0
-
Abscissa of first point.
- @parameter float :y0
-
Ordinate of first point.
- @parameter float :x0
-
Abscissa of second point.
- @parameter float :y1
-
Ordinate of second point.
- @parameter int :head_style
-
(0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
- @parameter float :arm_size
-
length of arrowhead arms
- @parameter int :arm_angle
-
angle between an arm and the shaft
- @author
-
Piotr Galecki, Nicola Asuni, Andy Meier
- @access public
- @since 4.6.018 (2009-07-10)
8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 |
# File 'lib/tcpdf.rb', line 8651 def Arrow(x0, y0, x1, y1, head_style=0, arm_size=5, arm_angle=15) # getting arrow direction angle # 0 deg angle is when both arms go along X axis. angle grows clockwise. dir_angle = ::Math.atan2(y0 - y1, x0 - x1) if dir_angle < 0 dir_angle += 2 * ::Math::PI end arm_angle = arm_angle * ::Math::PI / 180 # deg2rad sx1 = x1 sy1 = y1 if head_style > 0 # calculate the stopping point for the arrow shaft sx1 = x1 + (arm_size - @line_width) * ::Math.cos(dir_angle) sy1 = y1 + (arm_size - @line_width) * ::Math.sin(dir_angle) end # main arrow line / shaft Line(x0, y0, sx1, sy1) # left arrowhead arm tip x2L = x1 + (arm_size * ::Math.cos(dir_angle + arm_angle)) y2L = y1 + (arm_size * ::Math.sin(dir_angle + arm_angle)) # right arrowhead arm tip x2R = x1 + (arm_size * ::Math.cos(dir_angle - arm_angle)) y2R = y1 + (arm_size * ::Math.sin(dir_angle - arm_angle)) mode = 'D' style = [] case head_style when 0 # draw only arrowhead arms mode = 'D' style = [1, 1, 0] when 1 # draw closed arrowhead, but no fill mode = 'D' when 2 # closed and filled arrowhead mode = 'DF' when 3 # filled arrowhead mode = 'F' end Polygon([x2L, y2L, x1, y1, x2R, y2R], mode, style, nil) end |
#Bookmark(txt, level = 0, y = -1,, page = nil) ⇒ Object Also known as: bookmark
Adds a bookmark.
- @param string :txt
-
bookmark description.
- @param int :level
-
bookmark level.
- @param float :y
-
Ordinate of the boorkmark position (default = -1 = current position).
- @param int :page
-
target page number (leave empty for current page).
- @access public
- @author
-
Olivier Plathey, Nicola Asuni
- @since 2.1.002 (2008-02-12)
9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 |
# File 'lib/tcpdf.rb', line 9317 def Bookmark(txt, level=0, y=-1, page=nil) if level < 0 level = 0 end if @outlines[0] lastoutline = @outlines[-1] maxlevel = lastoutline[:l] + 1 else maxlevel = 0 end if level > maxlevel level = maxlevel end if y == -1 y = GetY() end if page.nil? page = PageNo() end @outlines.push :t => txt, :l => level, :y => y, :p => page end |
#BreakThePage?(h) ⇒ Boolean Also known as: break_the_page?
3196 3197 3198 3199 3200 3201 3202 3203 |
# File 'lib/tcpdf.rb', line 3196 def BreakThePage?(h) warn "[DEPRECATION] 'BreakThePage/break_the_page' is deprecated. Please don't Use." if ((@y + h) > @page_break_trigger and !@in_footer and AcceptPageBreak()) true else false end end |
#Cell(w, h = 0, txt = '', border = 0, ln = 0, align = '', fill = 0, link = nil, stretch = 0, ignore_min_height = false, calign = 'T', valign = 'M') ⇒ Object Also known as: cell
Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text. If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
- @param float :w
-
Cell width. If 0, the cell extends up to the right margin.
- @param float :h
-
Cell height. Default value: 0.
- @param string :txt
-
String to print. Default value: empty string.
- @param mixed :border
-
Indicates if borders must be drawn around the cell. The value can be either a number:
-
0: no border (default)
-
1: frame
or a string containing some or all of the following characters (in any order):
-
L: left
-
T: top
-
R: right
-
B: bottom
-
- @param int :ln
-
Indicates where the current position should go after the call. Possible values are:
-
0: to the right
-
1: to the beginning of the next line
-
2: below
Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
-
- @param string :align
-
Allows to center or align the text. Possible values are:
-
L or empty string: left align (default value)
-
C: center
-
R: right align
-
- @param int :fill
-
Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
- @param mixed :link
-
URL or identifier returned by AddLink().
- @param int :stretch
-
stretch carachter mode:
-
0 = disabled
-
1 = horizontal scaling only if necessary
-
2 = forced horizontal scaling
-
3 = character spacing only if necessary
-
4 = forced character spacing
-
- @param boolean :ignore_min_height
-
if true ignore automatic minimum height value.
- @param string :calign
-
cell vertical alignment relative to the specified Y value. Possible values are:
-
T : cell top
-
C : center
-
B : cell bottom
-
A : font top
-
L : font baseline
-
D : font bottom
-
- @param string :valign
-
text vertical alignment inside the cell. Possible values are:
-
T : top
-
M : middle
-
B : bottom
-
- @access public
- @since 1.0
- @see
- @since 1.0
-
SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 |
# File 'lib/tcpdf.rb', line 3259 def Cell(w, h=0, txt='', border=0, ln=0, align='', fill=0, link=nil, stretch=0, ignore_min_height=false, calign='T', valign='M') if !ignore_min_height min_cell_height = @font_size * @cell_height_ratio if h < min_cell_height h = min_cell_height end end checkPageBreak(h) out(getCellCode(w, h, txt, border, ln, align, fill, link, stretch, ignore_min_height, calign, valign)) end |
#Circle(x0, y0, r, angstr = 0, angend = 360, style = '', line_style = nil, fill_color = nil, nc = 2) ⇒ Object Also known as: circle
Draws a circle. A circle is formed from n Bezier curves.
- @param float :x0
-
Abscissa of center point.
- @param float :y0
-
Ordinate of center point.
- @param float :r
-
Radius.
- @param float :angstr
-
Angle start of draw line. Default value: 0.
- @param float :angend
-
Angle finish of draw line. Default value: 360.
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param array :line_style
-
Line style of circle. Array like for SetLineStyle SetLineStyle. Default value: default line style (empty array).
- @param array :fill_color
-
Fill color. Format: array(red, green, blue). Default value: default color (empty array).
- @param integer :nc
-
Number of curves used to draw a 90 degrees portion of circle.
- @access public
- @since 2.1.000 (2008-01-08)
8329 8330 8331 |
# File 'lib/tcpdf.rb', line 8329 def Circle(x0, y0, r, angstr=0, angend=360, style='', line_style=nil, fill_color=nil, nc=2) Ellipse(x0, y0, r, r, 0, angstr, angend, style, line_style, fill_color, nc) end |
#Close ⇒ Object
Terminates the PDF document. It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page, AddPage() is called to prevent from getting an invalid document.
- @since 1.0
- @see
-
Open(), Output()
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 |
# File 'lib/tcpdf.rb', line 1470 def Close() #Terminate document if (@state==3) return; end if (@page==0) AddPage(); end # close page endPage() lastPage() @state = 2 SetAutoPageBreak(false) @y = @h - (1 / @k) @r_margin = 0 out('q') setVisibility('screen') SetFont('helvetica', '', 1) SetTextColor(127,127,127) setAlpha(0) msg = "\x50\x6f\x77\x65\x72\x65\x64\x20\x62\x79\x20\x54\x43\x50\x44\x46\x20\x28\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29" lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67" Cell(0, 0, msg, 0, 0, 'R', 0, lnk, 0, false, 'D', 'B') out('Q') setVisibility('all') @state = 1 # close document enddoc(); end |
#commitTransaction ⇒ Object Also known as: commit_transaction
Delete the copy of the current TCPDF object used for undo operation.
- @access public
- @since 4.5.029 (2009-03-19)
13961 13962 13963 13964 13965 13966 13967 13968 13969 13970 13971 13972 13973 |
# File 'lib/tcpdf.rb', line 13961 def commitTransaction() if @objcopy if @objcopy.diskcache @prev_pages.compact.each do |file| File.delete(file.path) end @prev_pages = [] end @objcopy.destroy(true, true) @objcopy = nil end end |
#convertHTMLColorToDec(color = "#FFFFFF") ⇒ Object Also known as: convert_html_color_to_dec
Returns an associative array (keys: R,G,B) from an html color name or a six-digit or three-digit hexadecimal color representation (i.e. #3FE5AA or #7FF).
- @param string :color
-
html color
- @return array
-
RGB color or empty array in case of error.
- @access public
7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 |
# File 'lib/tcpdf.rb', line 7672 def convertHTMLColorToDec(color = "#FFFFFF") color = color.gsub(/[\s]*/, '') # remove extra spaces color = color.downcase if !(dotpos = color.index('.')).nil? # remove class parent (i.e.: color.red) color = color[(dotpos + 1)..-1] end if color.length == 0 return [] end returncolor = ActiveSupport::OrderedHash.new # RGB ARRAY if color[0,3] == 'rgb' codes = color.sub(/^rgb\(/, '') codes = codes.gsub(')', '') returncolor = codes.split(',', 3) returncolor[0] = returncolor[0].to_i returncolor[1] = returncolor[1].to_i returncolor[2] = returncolor[2].to_i return returncolor end # CMYK ARRAY if color[0,4] == 'cmyk' codes = color.sub(/^cmyk\(/, '') codes = codes.gsub(')', '') returncolor[0] = returncolor[0].to_i returncolor[1] = returncolor[1].to_i returncolor[2] = returncolor[2].to_i returncolor[3] = returncolor[3].to_i return returncolor end # COLOR NAME if color[0].chr != "#" # decode color name if @@webcolor[color] color_code = @@webcolor[color] else return [] end else color_code = color.sub(/^#/, "") end # RGB VALUE case color_code.length when 3 # three-digit hexadecimal representation r = color_code[0] g = color_code[1] b = color_code[2] returncolor['R'] = (r + r).hex returncolor['G'] = (g + g).hex returncolor['B'] = (b + b).hex when 6 # six-digit hexadecimal representation returncolor['R'] = color_code[0,2].hex returncolor['G'] = color_code[2,2].hex returncolor['B'] = color_code[4,2].hex else returncolor = [] end return returncolor end |
#Curve(x0, y0, x1, y1, x2, y2, x3, y3, style = '', line_style = nil, fill_color = nil) ⇒ Object Also known as: curve
Draws a Bezier curve. The Bezier curve is a tangent to the line between the control points at either end of the curve.
- @param float :x0
-
Abscissa of start point.
- @param float :y0
-
Ordinate of start point.
- @param float :x1
-
Abscissa of control point 1.
- @param float :y1
-
Ordinate of control point 1.
- @param float :x2
-
Abscissa of control point 2.
- @param float :y2
-
Ordinate of control point 2.
- @param float :x3
-
Abscissa of end point.
- @param float :y3
-
Ordinate of end point.
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param array :line_style
-
Line style of curve. Array like for SetLineStyle SetLineStyle. Default value: default line style (empty array).
- @param array :fill_color
-
Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
- @access public
- @see
-
SetLineStyle()
- @since 2.1.000 (2008-01-08)
8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 |
# File 'lib/tcpdf.rb', line 8163 def Curve(x0, y0, x1, y1, x2, y2, x3, y3, style='', line_style=nil, fill_color=nil) if style and (style.index('F') != nil) and fill_color SetFillColorArray(fill_color) end op = getPathPaintOperator(style) if line_style SetLineStyle(line_style) end outPoint(x0, y0) outCurve(x1, y1, x2, y2, x3, y3) out(op) end |
#deletePage(page) ⇒ Object Also known as: delete_page
Remove the specified page.
- @param int :page
-
page to remove
- @return
-
true in case of success, false in case of error.
- @access public
- @since 4.6.004 (2009-04-23)
13550 13551 13552 13553 13554 13555 13556 13557 13558 13559 13560 13561 13562 13563 13564 13565 13566 13567 13568 13569 13570 13571 13572 13573 13574 13575 13576 13577 13578 13579 13580 13581 13582 13583 13584 13585 13586 13587 13588 13589 13590 13591 13592 13593 13594 13595 13596 13597 13598 13599 13600 13601 13602 13603 13604 13605 13606 13607 13608 13609 13610 13611 13612 13613 13614 13615 13616 13617 13618 13619 13620 13621 13622 13623 13624 13625 13626 13627 13628 13629 13630 13631 13632 13633 13634 13635 13636 13637 13638 13639 13640 13641 13642 13643 13644 13645 13646 13647 13648 13649 13650 13651 13652 13653 13654 13655 13656 13657 13658 13659 13660 13661 13662 13663 13664 13665 13666 13667 13668 13669 13670 13671 13672 13673 13674 13675 13676 13677 13678 13679 |
# File 'lib/tcpdf.rb', line 13550 def deletePage(page) if page > @numpages return false end # delete current page @pages[page] = nil @pagedim[page] = nil @pagelen[page] = nil @intmrk[page] = nil if @footerpos[page] @footerpos[page] = nil end if @footerlen[page] @footerlen[page] = nil end if @transfmrk[page] @transfmrk[page] = nil end if @page_annots[page] @page_annots[page] = nil end if @newpagegroup[page] @newpagegroup[page] = nil end if @pageopen[page] @pageopen[page] = nil end # update remaining pages page.upto(@numpages - 1) do |i| j = i + 1 # shift pages @pages[i] = @pages[j] @pagedim[i] = @pagedim[j] @pagelen[i] = @pagelen[j] @intmrk[i] = @intmrk[j] if @footerpos[j] @footerpos[i] = @footerpos[j] elsif @footerpos[i] @footerpos[i] = nil end if @footerlen[j] @footerlen[i] = @footerlen[j] elsif @footerlen[i] @footerlen[i] = nil end if @transfmrk[j] @transfmrk[i] = @transfmrk[j] elsif @transfmrk[i] @transfmrk[i] = nil end if @page_annots[j] @page_annots[i] = page_annots[j] elsif @page_annots[i] @page_annots[i] = nil end if @newpagegroup[j] @newpagegroup[i] = @newpagegroup[j] elsif @newpagegroup[i] @newpagegroup[i] = nil end if @pageopen[j] @pageopen[i] = @pageopen[j] elsif @pageopen[i] @pageopen[i] = nil end end # remove last page @pages[@numpages] = nil @pagedim[@numpages] = nil @pagelen[@numpages] = nil @intmrk[@numpages] = nil if @footerpos[@numpages] @footerpos[@numpages] = nil end if @footerlen[@numpages] @footerlen[@numpages] = nil end if @transfmrk[@numpages] @transfmrk[@numpages] = nil end if @page_annots[@numpages] @page_annots[@numpages] = nil end if @newpagegroup[@numpages] @newpagegroup[@numpages] = nil end if @pageopen[@numpages] @pageopen[@numpages] = nil end @numpages -= 1 @page = @numpages # adjust outlines tmpoutlines = @outlines tmpoutlines.each_with_index do |outline, key| if outline[:p] > page @outlines[key][:p] = outline[:p] - 1 elsif outline[:p] == page @outlines[key] = nil end end # adjust links tmplinks = @links tmplinks.each_with_index do |link, key| if link[0] > page @links[key][0] = link[0] - 1 elsif link[0] == page @links[key] = nil end end #### PDF javascript code does not implement, yet. ### # adjust javascript #tmpjavascript = @javascript #jpage = page #tmpjavascript =~ /this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/ #pagenum = $3.to_i + 1 #if pagenum >= jpage # newpage = pagenum - 1 #elsif pagenum == jpage # newpage = 1 #else # newpage = pagenum #end #newpage -= 1 #@javascript = "this.addField(\'" + $1 + "\',\'" + $2 + "\'," + newpage + "" # return to last page lastPage(true) return true end |
#destroy(destroyall = false, preserve_objcopy = false) ⇒ Object
Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
- @param boolean :destroyall
-
if true destroys all class variables, otherwise preserves critical variables.
- @param boolean :preserve_objcopy
-
if true preserves the objcopy variable
- @access public
5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 |
# File 'lib/tcpdf.rb', line 5241 def destroy(destroyall=false, preserve_objcopy=false) if destroyall and @diskcache and !preserve_objcopy and !empty_string(@buffer.path) # remove buffer file from cache File.delete(@buffer.path) end self.instance_variables.each { |val| if destroyall or ((val != '@internal_encoding') and (val != '@state') and (val != '@bufferlen') and (val != '@buffer') and (val != '@diskcache') and (val != '@sign') and (val != '@signature_data') and (val != '@signature_max_length') and (val != '@byterange_string')) if (!preserve_objcopy or (val.to_s != '@objcopy')) and @val eval("#{val} = nil") end end } end |
#Ellipse(x0, y0, rx, ry = '', angle = 0, astart = 0, afinish = 360, style = '', line_style = nil, fill_color = nil, nc = 2) ⇒ Object Also known as: ellipse
Draws an ellipse. An ellipse is formed from n Bezier curves.
- @param float :x0
-
Abscissa of center point.
- @param float :y0
-
Ordinate of center point.
- @param float :rx
-
Horizontal radius.
- @param float :ry
-
Vertical radius (if ry = 0 then is a circle, see Circle Circle). Default value: 0.
- @param float :angle
-
Angle oriented (anti-clockwise). Default value: 0.
- @param float :astart
-
Angle start of draw line. Default value: 0.
- @param float :afinish
-
Angle finish of draw line. Default value: 360.
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param array :line_style
-
Line style of ellipse. Array like for SetLineStyle SetLineStyle. Default value: default line style (empty array).
- @param array :fill_color
-
Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
- @param integer :nc
-
Number of curves used to draw a 90 degrees portion of ellipse.
- @author
-
Nicola Asuni
- @access public
- @since 2.1.000 (2008-01-08)
8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 |
# File 'lib/tcpdf.rb', line 8195 def Ellipse(x0, y0, rx, ry='', angle=0, astart=0, afinish=360, style='', line_style=nil, fill_color=nil, nc=2) style = '' if style.nil? if empty_string(ry) or (ry == 0) ry = rx end if (nil != style.index('F')) and fill_color SetFillColorArray(fill_color) end op = getPathPaintOperator(style) if op == 'f' line_style = nil end if line_style and !line_style.empty? SetLineStyle(line_style) end outellipticalarc(x0, y0, rx, ry, angle, astart, afinish, false, nc) out(op) end |
#empty_string(str) ⇒ Object
Determine whether a string is empty.
- @param string :str
-
string to be checked
- @return boolean
-
true if string is empty
- @access public
- @since 4.5.044 (2009-04-16)
14038 14039 14040 |
# File 'lib/tcpdf.rb', line 14038 def empty_string(str) return (str.nil? or (str.is_a?(String) and (str.length == 0))) end |
#endPage(tocpage = false) ⇒ Object Also known as: end_page
Terminate the current page
- @param boolean :tocpage
-
if true set the tocpage state to false (end the page used to display Table Of Content).
- @access public
- @since 4.2.010 (2008-11-14)
- @see
- @since 4.2.010 (2008-11-14)
-
AddPage(), startPage(), addTOCPage(), endTOCPage()
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 |
# File 'lib/tcpdf.rb', line 1653 def endPage(tocpage=false) # check if page is already closed if (@page == 0) or (@numpages > @page) or !@pageopen[@page] return end @in_footer = true # print page footer () # close page endpage() # mark page as closed @pageopen[@page] = false @in_footer = false if tocpage @tocpage = false end end |
#endTOCPage ⇒ Object Also known as: end_toc_page
Terminate the current TOC (Table Of Content) page
- @access public
- @since 5.0.001 (2010-05-06)
- @see
- @since 5.0.001 (2010-05-06)
-
AddPage(), startPage(), endPage(), addTOCPage()
1605 1606 1607 |
# File 'lib/tcpdf.rb', line 1605 def endTOCPage() endPage(true) end |
#Error(msg) ⇒ Object Also known as: error
This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
- 2004-06-11
-
Nicola Asuni : changed bold tag with strong
- @param string :msg
-
The error message
- @access public
- @since 1.0
1445 1446 1447 1448 1449 |
# File 'lib/tcpdf.rb', line 1445 def Error(msg) destroy(true) #Fatal error raise ("TCPDF error: #{msg}") end |
#Footer ⇒ Object Also known as:
This method is used to render the page footer. It is automatically called by AddPage() and could be overwritten in your own inherited class.
- @access public
1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 |
# File 'lib/tcpdf.rb', line 1964 def Footer() cur_y = GetY() ormargins = getOriginalMargins() SetTextColor(0, 0, 0) # set style for cell border line_width = 0.85 / getScaleFactor() SetLineStyle({'width' => line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => [0, 0, 0]}) # print document barcode #barcode = getBarcode() #if !barcode.empty? # Ln(line_width) # barcode_width = ((getPageWidth() - ormargins['left'] - ormargins['right']) / 3).round # write1DBarcode(barcode, 'C128B', GetX(), cur_y + line_width, barcode_width, ((getFooterMargin() / 3) - line_width), 0.3, '', '') #end w_page = (@l.nil? or @l['w_page'].nil?) ? '' : @l['w_page'] if @pagegroups.empty? pagenumtxt = w_page + ' ' + getAliasNumPage() + ' / ' + getAliasNbPages() else pagenumtxt = w_page + ' ' + getPageNumGroupAlias() + ' / ' + getPageGroupAlias() end SetY(cur_y) # Print page number if getRTL() SetX(ormargins['right']) Cell(0, 0, pagenumtxt, 'T', 0, 'L') else SetX(ormargins['left']) Cell(0, 0, pagenumtxt, 'T', 0, 'R') end end |
#GetAbsX ⇒ Object Also known as: get_abs_x
Returns the absolute X value of current position.
- @return float
- @access public
- @since 1.2
- @see
- @access public
-
SetY(), GetX(), SetX()
5007 5008 5009 |
# File 'lib/tcpdf.rb', line 5007 def GetAbsX() return @x end |
#getAliasNbPages ⇒ Object Also known as: get_alias_nb_pages
Returns the string alias used for the total number of pages. If the current font is unicode type, the returned string is surrounded by additional curly braces.
- @return string
- @access public
- @since 4.0.018 (2008-08-08)
- @see
- @access public
-
AliasNbPages(), PageNo(), Footer()
9444 9445 9446 9447 9448 9449 |
# File 'lib/tcpdf.rb', line 9444 def getAliasNbPages() if (@current_font['type'] == 'TrueTypeUnicode') or (@current_font['type'] == 'cidfont0') return '{' + @alias_nb_pages + '}' end return @alias_nb_pages end |
#getAliasNumPage ⇒ Object Also known as: get_alias_num_page
Returns the string alias used for the page number. If the current font is unicode type, the returned string is surrounded by additional curly braces.
- @return string
- @access public
- @since 4.5.000 (2009-01-02)
- @see
- @access public
-
AliasNbPages(), PageNo(), Footer()
9474 9475 9476 9477 9478 9479 |
# File 'lib/tcpdf.rb', line 9474 def getAliasNumPage() if (@current_font['type'] == 'TrueTypeUnicode') or (@current_font['type'] == 'cidfont0') return '{' + @alias_num_page + '}' end return @alias_num_page end |
#GetArrStringWidth(sa, fontname = '', fontstyle = '', fontsize = 0, getarray = false) ⇒ Object Also known as: get_arr_string_width
Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.
- @param string :sa
-
The array of chars whose total length is to be computed
- @param string :fontname
-
Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
- @param string :fontstyle
-
Font style. Possible values are (case insensitive):
-
empty string: regular
-
B: bold
-
I: italic
-
U: underline
-
D: line trough
-
O: overline
or any combination. The default value is regular.
-
- @param float :fontsize
-
Font size in points. The default value is the current size.
- @param boolean :getarray
-
if true returns an array of characters widths, if false returns the total length.
- @return mixed int
-
total string length or array of characted widths
- @author
-
Nicola Asuni
- @access public
- @since 2.4.000 (2008-03-06)
2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 |
# File 'lib/tcpdf.rb', line 2448 def GetArrStringWidth(sa, fontname='', fontstyle='', fontsize=0, getarray=false) # store current values if !empty_string(fontname) prev_FontFamily = @font_family prev_FontStyle = @font_style prev_FontSizePt = @font_size_pt SetFont(fontname, fontstyle, fontsize) end # convert UTF-8 array to Latin1 if required sa = UTF8ArrToLatin1(sa) w = 0 # total width wa = [] # array of characters widths sa.each do |char| # character width cw = GetCharWidth(char) wa.push cw w += cw end # restore previous values if !empty_string(fontname) SetFont(prev_FontFamily, prev_FontStyle, prev_FontSizePt) end if getarray return wa end return w end |
#getBreakMargin(pagenum = '') ⇒ Object Also known as: get_break_margin
Returns the page break margin.
- @param int :pagenum
-
page number (empty = current page)
- @return int page
-
break margin.
- @author
-
Nicola Asuni
[@access publi]c
- @since 1.5.2
- @see
-
getPageDimensions()
1154 1155 1156 1157 1158 1159 |
# File 'lib/tcpdf.rb', line 1154 def getBreakMargin(pagenum='') if pagenum.empty? return @b_margin end return @pagedim[pagenum]['bm'] end |
#GetBreakMargin(pagenum = '') ⇒ Object
1162 1163 1164 1165 |
# File 'lib/tcpdf.rb', line 1162 def GetBreakMargin(pagenum='') warn "[DEPRECATION] 'GetBreakMargin' is deprecated. Please use 'get_break_margin' instead." getBreakMargin(pagenum) end |
#getCellHeightRatio ⇒ Object Also known as: get_cell_height_ratio
return the height of cell repect font height.
- @access public
- @since 4.0.012 (2008-07-24)
9720 9721 9722 |
# File 'lib/tcpdf.rb', line 9720 def getCellHeightRatio() return @cell_height_ratio end |
#GetCharWidth(char) ⇒ Object Also known as: get_char_width
Returns the length of the char in user unit for the current font.
- @param int :char
-
The char code whose length is to be returned
- @return int
-
char width
- @author
-
Nicola Asuni
- @access public
- @since 2.4.000 (2008-03-06)
2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 |
# File 'lib/tcpdf.rb', line 2485 def GetCharWidth(char) if char == 173 # SHY character will not be printed return 0 end cw = @current_font['cw'] if !cw[char].nil? w = cw[char] elsif !@current_font['dw'].nil? # default width w = @current_font['dw'] elsif !cw[32].nil? # default width w = cw[32] else w = 600 end return (w * @font_size / 1000.0) end |
#getFontAscent(font, style = '', size = 0) ⇒ Object Also known as: get_font_ascent
Return the font ascent value
- @param string :font
-
font name
- @param string :style
-
font style
- @param float :size
-
The size (in points)
- @return int
-
font ascent
- @access public
- @since 4.9.003 (2010-03-30)
2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 |
# File 'lib/tcpdf.rb', line 2861 def getFontAscent(font, style='', size=0) # Set font size in points sizek = size / @k fontdata = AddFont(font, style) font = getFontBuffer(fontdata['fontkey']) if font['desc'] and font['desc']['Ascent'] and (font['desc']['Ascent'] > 0) ascent = font['desc']['Ascent'] * sizek / 1000 else ascent = 0.85 * sizek end return ascent end |
#getFontDescent(font, style = '', size = 0) ⇒ Object Also known as: get_font_descent
Return the font descent value
- @param string :font
-
font name
- @param string :style
-
font style
- @param float :size
-
The size (in points)
- @return int
-
font descent
- @access public
- @since 4.9.003 (2010-03-30)
2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 |
# File 'lib/tcpdf.rb', line 2838 def getFontDescent(font, style='', size=0) # Set font size in points sizek = size / @k fontdata = AddFont(font, style) font = getFontBuffer(fontdata['fontkey']) if font['desc'] and font['desc']['Descent'] and (font['desc']['Descent'] <= 0) descent = - font['desc']['Descent'] * sizek / 1000 else descent = 0.15 * sizek end return descent end |
#getFontFamily ⇒ Object Also known as: get_font_family
Returns the current font family name.
- @return string
-
current font family name
- @access public
- @since 4.3.008 (2008-12-05)
9992 9993 9994 |
# File 'lib/tcpdf.rb', line 9992 def getFontFamily() return @font_family end |
#getFontSize ⇒ Object Also known as: get_font_size
Returns the current font size.
- @return
-
current font size
- @access public
- @since 3.2.000 (2008-06-23)
9970 9971 9972 |
# File 'lib/tcpdf.rb', line 9970 def getFontSize() return @font_size end |
#getFontSizePt ⇒ Object Also known as: get_font_size_pt
Returns the current font size in points unit.
- @return
-
current font size in points unit
- @access public
- @since 3.2.000 (2008-06-23)
9981 9982 9983 |
# File 'lib/tcpdf.rb', line 9981 def getFontSizePt() return @font_size_pt end |
#getFontStyle ⇒ Object Also known as: get_font_style
Returns the current font style.
- @return string
-
current font style
- @access public
- @since 4.3.008 (2008-12-05)
10003 10004 10005 |
# File 'lib/tcpdf.rb', line 10003 def getFontStyle() return @font_style end |
#getFooterFont(font) ⇒ Object Also known as:
Get Footer font.
- @return array
- @access public
- @since 4.0.012 (2008-07-24)
- @access public
7584 7585 7586 |
# File 'lib/tcpdf.rb', line 7584 def (font) return @footer_font end |
#getFooterMargin ⇒ Object Also known as:
Returns footer margin in user units.
- @return float
- @since 4.0.012 (2008-07-24)
- @access public
- @since 4.0.012 (2008-07-24)
1853 1854 1855 |
# File 'lib/tcpdf.rb', line 1853 def () return @footer_margin end |
#getGroupPageNo ⇒ Object Also known as: get_group_page_no
Return the current page in the group.
- @return
-
current page in the group
- @access public
- @since 3.0.000 (2008-03-27)
9488 9489 9490 |
# File 'lib/tcpdf.rb', line 9488 def getGroupPageNo() return @pagegroups[@currpagegroup] end |
#getGroupPageNoFormatted ⇒ Object Also known as: get_group_page_no_formatted
Returns the current group page number formatted as a string.
- @access public
- @since 4.3.003 (2008-11-18)
- @see
- @since 4.3.003 (2008-11-18)
-
PaneNo(), formatPageNumber()
9499 9500 9501 |
# File 'lib/tcpdf.rb', line 9499 def getGroupPageNoFormatted() return formatPageNumber(getGroupPageNo()) end |
#getHeaderData ⇒ Object Also known as: get_header_data
Returns header data:
ret['logo'] = logo image
ret['logo_width'] = width of the image logo in user units
ret['title'] = header title
ret['string'] = header description string
- @return hash
- @access public
- @since 4.0.012 (2008-07-24)
- @access public
1794 1795 1796 1797 1798 1799 1800 1801 |
# File 'lib/tcpdf.rb', line 1794 def getHeaderData() ret = {} ret['logo'] = @header_logo ret['logo_width'] = @header_logo_width ret['title'] = @header_title ret['string'] = @header_string return ret end |
#getHeaderFont ⇒ Object Also known as: get_header_font
Get header font.
- @return array
- @access public
- @since 4.0.012 (2008-07-24)
- @access public
7557 7558 7559 |
# File 'lib/tcpdf.rb', line 7557 def getHeaderFont() return @header_font end |
#getHeaderMargin ⇒ Object Also known as: get_header_margin
Returns header margin in user units.
- @return float
- @since 4.0.012 (2008-07-24)
- @access public
- @since 4.0.012 (2008-07-24)
1826 1827 1828 |
# File 'lib/tcpdf.rb', line 1826 def getHeaderMargin() return @header_margin end |
#getHTMLUnitToUnits(htmlval, refsize = 1, defaultunit = 'px', points = false) ⇒ Object Also known as: get_html_unit_to_units
convert HTML string containing value and unit of measure to user’s units or points.
- @param string :htmlval
-
string containing values and unit
- @param string :refsize
-
reference value in points
- @param string :defaultunit
-
default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
- @param boolean :point
-
if true returns points, otherwise returns value in user’s units
- @return float
-
value in user’s unit or point if :points=true
- @access public
- @since 4.4.004 (2008-12-10)
12849 12850 12851 12852 12853 12854 12855 12856 12857 12858 12859 12860 12861 12862 12863 12864 12865 12866 12867 12868 12869 12870 12871 12872 12873 12874 12875 12876 12877 12878 12879 12880 12881 12882 12883 12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 |
# File 'lib/tcpdf.rb', line 12849 def getHTMLUnitToUnits(htmlval, refsize=1, defaultunit='px', points=false) supportedunits = ['%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt'] retval = 0 value = 0 unit = 'px' k = @k if points k = 1 end if supportedunits.include?(defaultunit) unit = defaultunit end if htmlval.is_a?(Numeric) value = htmlval.to_f else mnum = htmlval.scan(/[0-9\.\-\+]+/) unless mnum.empty? value = mnum[0].to_f munit = htmlval.scan(/[a-z%]+/) unless munit.empty? if supportedunits.include?(munit[0]) unit = munit[0] end end end end case unit when '%' # percentage retval = (value * refsize) / 100 when 'em' # relative-size retval = value * refsize when 'ex' # height of lower case 'x' (about half the font-size) retval = value * (refsize / 2) when 'in' # absolute-size retval = (value * @dpi) / k when 'cm' # centimeters retval = (value / 2.54 * @dpi) / k when 'mm' # millimeters retval = (value / 25.4 * @dpi) / k when 'pc' # one pica is 12 points retval = (value * 12) / k when 'pt' # points retval = value / k when 'px' # pixels retval = pixelsToUnits(value) end return retval end |
#getImageFileType(imgfile, iminfo = {}) ⇒ Object Also known as: get_image_file_type
Return the image type given the file name or array returned by getimagesize() function.
- @param string :imgfile
-
image file name
- @param hash :iminfo
-
array of image information returned by getimagesize() function.
- @return string
-
image type
- @access public
- @since 4.8.017 (2009-11-27)
4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 |
# File 'lib/tcpdf.rb', line 4491 def getImageFileType(imgfile, iminfo={}) if iminfo.is_a? Hash and iminfo['mime'] and !iminfo['mime'].empty? mime = iminfo['mime'].split('/') if (mime.length > 1) and (mime[0] == 'image') and !mime[1].empty? return mime[1].strip end end type = '' return type if imgfile.nil? fileinfo = File::extname(imgfile) type = fileinfo.sub(/^\./, '').downcase if fileinfo != '' if type == 'jpg' type = 'jpeg' end return type end |
#getImageRBX ⇒ Object Also known as: get_image_rbx
Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
- @return float
- @access public
1893 1894 1895 |
# File 'lib/tcpdf.rb', line 1893 def getImageRBX() return @img_rb_x end |
#getImageRBY ⇒ Object Also known as: get_image_rby
Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
- @return float
- @access public
1903 1904 1905 |
# File 'lib/tcpdf.rb', line 1903 def getImageRBY() return @img_rb_y end |
#GetImageScale ⇒ Object
1042 1043 1044 1045 |
# File 'lib/tcpdf.rb', line 1042 def GetImageScale() warn "[DEPRECATION] 'GetImageScale' is deprecated. Please use 'get_image_scale' instead." getImageScale() end |
#getImageScale ⇒ Object Also known as: get_image_scale
Returns the adjusting factor to convert pixels to user units.
- @return float
-
adjusting factor to convert pixels to user units.
- @author
-
Nicola Asuni
- @access public
- @since 1.5.2
1037 1038 1039 |
# File 'lib/tcpdf.rb', line 1037 def getImageScale() return @img_scale; end |
#getLastH ⇒ Object Also known as: get_last_h
Get the last cell height.
- @return
-
last cell height
- @access public
- @since 4.0.017 (2008-08-05)
1008 1009 1010 |
# File 'lib/tcpdf.rb', line 1008 def getLastH() return @lasth end |
#GetLineWidth ⇒ Object Also known as: get_line_width
Returns the current the line width.
- @return int
-
Line width
- @access public
- @since 2.1.000 (2008-01-07)
- @see
- @since 2.1.000 (2008-01-07)
-
Line(), SetLineWidth()
7909 7910 7911 |
# File 'lib/tcpdf.rb', line 7909 def GetLineWidth() return @line_width end |
#GetNumChars(s) ⇒ Object Also known as: get_num_chars
Returns the numbero of characters in a string.
- @param string :s
-
The input string.
- @return int
-
number of characters
- @access public
- @since 2.0.0001 (2008-01-07)
2513 2514 2515 2516 2517 2518 |
# File 'lib/tcpdf.rb', line 2513 def GetNumChars(s) if (@current_font['type'] == 'TrueTypeUnicode') or (@current_font['type'] == 'cidfont0') return UTF8StringToArray(s).length end return s.length end |
#getNumPages ⇒ Object Also known as: get_num_pages
Get the total number of insered pages.
- @return int
-
number of pages
- @access public
- @since 2.1.000 (2008-01-07)
- @see
- @since 2.1.000 (2008-01-07)
-
setPage(), getPage(), lastPage()
1581 1582 1583 |
# File 'lib/tcpdf.rb', line 1581 def getNumPages() return @numpages end |
#getOriginalMargins ⇒ Object Also known as: get_original_margins
Returns an array containing original margins:
ret['left'] = left margin
ret['right'] = right margin
- @return array
-
containing all margins measures
- @access public
- @since 4.0.012 (2008-07-24)
9958 9959 9960 9961 |
# File 'lib/tcpdf.rb', line 9958 def getOriginalMargins() ret = { 'left' => @original_l_margin, 'right' => @original_r_margin } return ret end |
#getPage ⇒ Object Also known as: get_page
Get current document page number.
- @return int
-
page number
- @access public
- @since 2.1.000 (2008-01-07)
- @see
- @since 2.1.000 (2008-01-07)
-
setPage(), lastPage(), getNumPages()
1569 1570 1571 |
# File 'lib/tcpdf.rb', line 1569 def getPage() return @page end |
#getPageDimensions(pagenum = '') ⇒ Object Also known as: get_page_dimensions
Returns an array of page dimensions:
@pagedim[@page]['w'] = page width in points
@pagedim[@page]['h'] = height in points
@pagedim[@page]['wk'] = page width in user units
@pagedim[@page]['hk'] = page height in user units
@pagedim[@page]['tm'] = top margin
@pagedim[@page]['bm'] = bottom margin
@pagedim[@page]['lm'] = left margin
@pagedim[@page]['rm'] = right margin
@pagedim[@page]['pb'] = auto page break
@pagedim[@page]['or'] = page orientation
@pagedim[@page]['olm'] = original left margin
@pagedim[@page]['orm'] = original right margin
@pagedim[@page]['Rotate'] = The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
@pagedim[@page]['PZ'] = The page's preferred zoom (magnification) factor.
@pagedim[@page]['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation
@pagedim[@page]['trans']['Dur'] = The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.
@pagedim[@page]['trans']['S'] = transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade
@pagedim[@page]['trans']['D'] = The duration of the transition effect, in seconds.
@pagedim[@page]['trans']['Dm'] = (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.
@pagedim[@page]['trans']['M'] = (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.
@pagedim[@page]['trans']['Di'] = (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.
@pagedim[@page]['trans']['SS'] = (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0.
@pagedim[@page]['trans']['B'] = (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.
@pagedim[@page]['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed
@pagedim[@page]['MediaBox']['llx'] = lower-left x coordinate in points
@pagedim[@page]['MediaBox']['lly'] = lower-left y coordinate in points
@pagedim[@page]['MediaBox']['urx'] = upper-right x coordinate in points
@pagedim[@page]['MediaBox']['ury'] = upper-right y coordinate in points
@pagedim[@page]['CropBox'] : the visible region of default user space
@pagedim[@page]['CropBox']['llx'] = lower-left x coordinate in points
@pagedim[@page]['CropBox']['lly'] = lower-left y coordinate in points
@pagedim[@page]['CropBox']['urx'] = upper-right x coordinate in points
@pagedim[@page]['CropBox']['ury'] = upper-right y coordinate in points
@pagedim[@page]['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment
@pagedim[@page]['BleedBox']['llx'] = lower-left x coordinate in points
@pagedim[@page]['BleedBox']['lly'] = lower-left y coordinate in points
@pagedim[@page]['BleedBox']['urx'] = upper-right x coordinate in points
@pagedim[@page]['BleedBox']['ury'] = upper-right y coordinate in points
@pagedim[@page]['TrimBox'] : the intended dimensions of the finished page after trimming
@pagedim[@page]['TrimBox']['llx'] = lower-left x coordinate in points
@pagedim[@page]['TrimBox']['lly'] = lower-left y coordinate in points
@pagedim[@page]['TrimBox']['urx'] = upper-right x coordinate in points
@pagedim[@page]['TrimBox']['ury'] = upper-right y coordinate in points
@pagedim[@page]['ArtBox'] : the extent of the page's meaningful content
@pagedim[@page]['ArtBox']['llx'] = lower-left x coordinate in points
@pagedim[@page]['ArtBox']['lly'] = lower-left y coordinate in points
@pagedim[@page]['ArtBox']['urx'] = upper-right x coordinate in points
@pagedim[@page]['ArtBox']['ury'] = upper-right y coordinate in points
- @param int :pagenum
-
page number (empty = current page)
- @return
-
array of page dimensions.
- @author
-
Nicola Asuni
- @access public
- @since 4.5.027 (2009-03-16)
1103 1104 1105 1106 1107 1108 |
# File 'lib/tcpdf.rb', line 1103 def getPageDimensions(pagenum='') if pagenum.empty? pagenum = @page end return @pagedim[pagenum] end |
#getPageGroupAlias ⇒ Object Also known as: get_page_group_alias
Return the alias of the current page group If the current font is unicode type, the returned string is surrounded by additional curly braces. (will be replaced by the total number of pages in this group).
- @return
-
alias of the current page group
- @access public
- @since 3.0.000 (2008-03-27)
9512 9513 9514 9515 9516 9517 |
# File 'lib/tcpdf.rb', line 9512 def getPageGroupAlias() if (@current_font['type'] == 'TrueTypeUnicode') or (@current_font['type'] == 'cidfont1') return '{' + @currpagegroup + '}' end return @currpagegroup end |
#GetPageHeight ⇒ Object
1140 1141 1142 1143 |
# File 'lib/tcpdf.rb', line 1140 def GetPageHeight() warn "[DEPRECATION] 'GetPageHeight' is deprecated. Please use 'get_page_height' instead." getPageHeight() end |
#getPageHeight ⇒ Object Also known as: get_page_height
Returns the page height in units.
- @return int
-
page height.
- @author
-
Nicola Asuni
- @access public
- @since 1.5.2
1135 1136 1137 |
# File 'lib/tcpdf.rb', line 1135 def getPageHeight() return @h; end |
#getPageNumGroupAlias ⇒ Object Also known as: get_page_num_group_alias
Return the alias for the page number on the current page group If the current font is unicode type, the returned string is surrounded by additional curly braces. (will be replaced by the total number of pages in this group).
- @return
-
alias of the current page group
- @access public
- @since 4.5.000 (2009-01-02)
9528 9529 9530 9531 9532 9533 |
# File 'lib/tcpdf.rb', line 9528 def getPageNumGroupAlias() if (@current_font['type'] == 'TrueTypeUnicode') or (@current_font['type'] == 'cidfont0') return '{' + @currpagegroup.gsub('{nb', '{pnb') +'}' end return @currpagegroup.gsub('{nb', '{pnb') end |
#getPageSizeFromFormat(format) ⇒ Object Also known as: get_page_size_from_format
Get page dimensions from fromat name.
- @param mixed :format
-
The format name. It can be:
-
4A0,2A0,A0,A1,A2,A3,A4 (default),A5,A6,A7,A8,A9,A10
-
B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10
-
C0,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10
-
RA0,RA1,RA2,RA3,RA4
-
SRA0,SRA1,SRA2,SRA3,SRA4
-
LETTER,LEGAL,EXECUTIVE,FOLIO
-
- @return array
-
containing page width and height in points
- @access public
- @since 5.0.010 (2010-05-17)
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/tcpdf.rb', line 551 def getPageSizeFromFormat(format) # Page formats (45 standard ISO paper formats and 4 american common formats). # Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm) case format.upcase when '4A0'; pf = [4767.87,6740.79] when '2A0'; pf = [3370.39,4767.87] when 'A0'; pf = [2383.94,3370.39] when 'A1'; pf = [1683.78,2383.94] when 'A2'; pf = [1190.55,1683.78] when 'A3'; pf = [841.89,1190.55] when 'A4'; pf = [595.28,841.89] when 'A5'; pf = [419.53,595.28] when 'A6'; pf = [297.64,419.53] when 'A7'; pf = [209.76,297.64] when 'A8'; pf = [147.40,209.76] when 'A9'; pf = [104.88,147.40] when 'A10'; pf = [73.70,104.88] when 'B0'; pf = [2834.65,4008.19] when 'B1'; pf = [2004.09,2834.65] when 'B2'; pf = [1417.32,2004.09] when 'B3'; pf = [1000.63,1417.32] when 'B4'; pf = [708.66,1000.63] when 'B5'; pf = [498.90,708.66] when 'B6'; pf = [354.33,498.90] when 'B7'; pf = [249.45,354.33] when 'B8'; pf = [175.75,249.45] when 'B9'; pf = [124.72,175.75] when 'B10'; pf = [87.87,124.72] when 'C0'; pf = [2599.37,3676.54] when 'C1'; pf = [1836.85,2599.37] when 'C2'; pf = [1298.27,1836.85] when 'C3'; pf = [918.43,1298.27] when 'C4'; pf = [649.13,918.43] when 'C5'; pf = [459.21,649.13] when 'C6'; pf = [323.15,459.21] when 'C7'; pf = [229.61,323.15] when 'C8'; pf = [161.57,229.61] when 'C9'; pf = [113.39,161.57] when 'C10'; pf = [79.37,113.39] when 'RA0'; pf = [2437.80,3458.27] when 'RA1'; pf = [1729.13,2437.80] when 'RA2'; pf = [1218.90,1729.13] when 'RA3'; pf = [864.57,1218.90] when 'RA4'; pf = [609.45,864.57] when 'SRA0'; pf = [2551.18,3628.35] when 'SRA1'; pf = [1814.17,2551.18] when 'SRA2'; pf = [1275.59,1814.17] when 'SRA3'; pf = [907.09,1275.59] when 'SRA4'; pf = [637.80,907.09] when 'LETTER'; pf = [612.00,792.00] when 'LEGAL'; pf = [612.00,1008.00] when 'EXECUTIVE'; pf = [521.86,756.00] when 'FOLIO'; pf = [612.00,936.00] else pf = [595.28,841.89] # DEFAULT A4 end return pf end |
#GetPageWidth ⇒ Object
1123 1124 1125 1126 |
# File 'lib/tcpdf.rb', line 1123 def GetPageWidth() warn "[DEPRECATION] 'GetPageWidth' is deprecated. Please use 'get_page_width' instead." getPageWidth() end |
#getPageWidth ⇒ Object Also known as: get_page_width
Returns the page width in units.
- @return int
-
page width.
- @author
-
Nicola Asuni
- @access public
- @since 1.5.2
1118 1119 1120 |
# File 'lib/tcpdf.rb', line 1118 def getPageWidth() return @w; end |
#getPDFData ⇒ Object Also known as: get_pdf_data
Returns the PDF data.
- @access public
7613 7614 7615 7616 7617 7618 |
# File 'lib/tcpdf.rb', line 7613 def getPDFData() if (@state < 3) Close(); end return @buffer; end |
#GetPDFData ⇒ Object
7621 7622 7623 7624 |
# File 'lib/tcpdf.rb', line 7621 def GetPDFData() warn "[DEPRECATION] 'GetPDFData' is deprecated. Please use 'get_pdf_data' instead." getPDFData() end |
#getRTL ⇒ Object Also known as: get_rtl
Return the RTL status
- @return boolean
- @access public
- @since 4.0.012 (2008-07-24)
- @access public
956 957 958 |
# File 'lib/tcpdf.rb', line 956 def getRTL() return @rtl end |
#getScaleFactor ⇒ Object Also known as: get_scale_factor
Returns the scale factor (number of points in user unit).
- @return int
-
scale factor.
- @author
-
Nicola Asuni
- @access public
- @since 1.5.2
1174 1175 1176 |
# File 'lib/tcpdf.rb', line 1174 def getScaleFactor() return @k; end |
#GetScaleFactor ⇒ Object
1179 1180 1181 1182 |
# File 'lib/tcpdf.rb', line 1179 def GetScaleFactor() warn "[DEPRECATION] 'GetScaleFactor' is deprecated. Please use 'get_scale_factor' instead." getScaleFactor() end |
#GetStringWidth(s, fontname = '', fontstyle = '', fontsize = 0, getarray = false) ⇒ Object Also known as: get_string_width
Returns the length of a string in user unit. A font must be selected.
- @param string :s
-
The string whose length is to be computed
- @param string :fontname
-
Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
- @param string :fontstyle
-
Font style. Possible values are (case insensitive):
-
empty string: regular
-
B: bold
-
I: italic
-
U: underline
-
D: line trough
-
O: overline
or any combination. The default value is regular.
-
- @param float :fontsize
-
Font size in points. The default value is the current size.
- @param boolean :getarray
-
if true returns an array of characters widths, if false returns the total length.
- @return mixed int
-
total string length or array of characted widths
- @author
-
Nicola Asuni
- @access public
- @since 1.2
2423 2424 2425 |
# File 'lib/tcpdf.rb', line 2423 def GetStringWidth(s, fontname='', fontstyle='', fontsize=0, getarray=false) return GetArrStringWidth(utf8Bidi(UTF8StringToArray(s), s, @tmprtl), fontname, fontstyle, fontsize, getarray) end |
#GetX ⇒ Object Also known as: get_x
Returns the relative X value of current position. The value is relative to the left border for LTR languages and to the right border for RTL languages.
- @return float
- @access public
- @since 1.2
- @see
- @access public
-
SetX(), GetY(), SetY()
4991 4992 4993 4994 4995 4996 4997 |
# File 'lib/tcpdf.rb', line 4991 def GetX() if @rtl return @w - @x else return @x end end |
#GetY ⇒ Object Also known as: get_y
Returns the ordinate of the current position.
- @return float
- @access public
- @since 1.0
- @see
- @access public
-
SetY(), GetX(), SetX()
5019 5020 5021 |
# File 'lib/tcpdf.rb', line 5019 def GetY() return @y; end |
#Header ⇒ Object Also known as: header
This method is used to render the page header. It is automatically called by AddPage() and could be overwritten in your own inherited class.
- @access public
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 |
# File 'lib/tcpdf.rb', line 1913 def Header() ormargins = getOriginalMargins() headerfont = getHeaderFont() headerdata = getHeaderData() if headerdata['logo'] and (headerdata['logo'] != @@k_blank_image) result_img = Image(@@k_path_images + headerdata['logo'], '', '', headerdata['logo_width']) if result_img != false imgy = getImageRBY() else Write(@lasth, File.basename(headerdata['logo']), '', false, '', false, 0, false) imgy = GetY() end else imgy = GetY() end cell_height = ((getCellHeightRatio() * headerfont[2]) / getScaleFactor()).round(2) # set starting margin for text data cell if getRTL() header_x = ormargins['right'] + (headerdata['logo_width'] * 1.1) else header_x = ormargins['left'] + (headerdata['logo_width'] * 1.1) end SetTextColor(0, 0, 0) # header title SetFont(headerfont[0], 'B', headerfont[2] + 1) SetX(header_x) Cell(0, cell_height, headerdata['title'], 0, 1, '', 0, '', 0) # header string SetFont(headerfont[0], headerfont[1], headerfont[2]) SetX(header_x) MultiCell(0, cell_height, headerdata['string'], 0, '', 0, 1, '', '', true, 0, false) # print an ending header line SetLineStyle({'width' => 0.85 / getScaleFactor(), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => [0, 0, 0]}) SetY((2.835 / getScaleFactor()) + (imgy > GetY() ? imgy : GetY())) if getRTL() SetX(ormargins['right']) else SetX(ormargins['left']) end Cell(0, 0, '', 'T', 0, 'C') end |
#Image(file, x = '', y = '', w = 0, h = 0, type = '', link = nil, align = '', resize = false, dpi = 300, palign = '', ismask = false, imgmask = false, border = 0, fitbox = false, hidden = false, fitonpage = false) ⇒ Object Also known as: image
Puts an image in the page. The upper-left corner must be given. The dimensions can be specified in different ways:
-
explicit width and height (expressed in user unit)
-
one explicit dimension, the other being calculated automatically in order to keep the original proportions
-
no explicit dimension, in which case the image is put at 72 dpi
Supported formats are PNG images whitout RMagick library and JPEG and GIF images supported by RMagick. For JPEG, all flavors are allowed:
-
gray scales
-
true colors (24 bits)
-
CMYK (32 bits)
For PNG, are allowed:
-
gray scales on at most 8 bits (256 levels)
-
indexed colors
-
true colors (24 bits)
If a transparent color is defined, it will be taken into account (but will be only interpreted by Acrobat 4 and above). The format can be specified explicitly or inferred from the file extension. It is possible to put a link on the image.
-
Remark: if an image is used several times, only one copy will be embedded in the file.
- @param string :file
-
Name of the file containing the image.
- @param float :x
-
Abscissa of the upper-left corner.
- @param float :y
-
Ordinate of the upper-left corner.
- @param float :w
-
Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
- @param float :h
-
Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
- @param string :type
-
Image format. Possible values are (case insensitive): JPG, JPEG, PNG. If not specified, the type is inferred from the file extension.
- @param mixed :link
-
URL or identifier returned by AddLink().
- @param string :align
-
Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:
-
T: top-right for LTR or top-left for RTL
-
M: middle-right for LTR or middle-left for RTL
-
B: bottom-right for LTR or bottom-left for RTL
-
N: next line
-
- @param mixed :resize
-
If true resize (reduce) the image to fit :w and :h (requires RMagick library); if false do not resize; if 2 force resize in all cases (upscaling and downscaling).
- @param int :dpi
-
dot-per-inch resolution used on resize
- @param string :palign
-
Allows to center or align the image on the current line. Possible values are:
-
L : left align
-
C : center
-
R : right align
-
” : empty string : left for LTR or right for RTL
-
- @param boolean :ismask
-
true if this image is a mask, false otherwise
- @param mixed :imgmask
-
image object returned by this function or false
- @param mixed :border
-
Indicates if borders must be drawn around the image. The value can be either a number:
-
0: no border (default)
-
1: frame
or a string containing some or all of the following characters (in any order):
-
L: left
-
T: top
-
R: right
-
B: bottom
-
- @param boolean :fitbox
-
If true scale image dimensions proportionally to fit within the (:w, :h) box.
- @param boolean :hidden
-
if true do not display the image.
- @param boolean :fitonpage
-
if true the image is resized to not exceed page dimensions.
- @return
-
image information
- @access public
- @since 1.1
4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 |
# File 'lib/tcpdf.rb', line 4569 def Image(file, x='', y='', w=0, h=0, type='', link=nil, align='', resize=false, dpi=300, palign='', ismask=false, imgmask=false, border=0, fitbox=false, hidden=false, fitonpage=false) w = 0 if w == '' h = 0 if h == '' x = @x if x == '' y = @y if y == '' # set bottomcoordinates @img_rb_y = y + h # get image dimensions imsize = getimagesize(file) if imsize.nil? or imsize == false # encode spaces on filename file = file.gsub(' ', '%20') imsize = getimagesize(file) if imsize.nil? Error('Missing image file: ' + file) elsif imsize == false if (w > 0) and (h > 0) pw = getHTMLUnitToUnits(w, 0, @pdfunit, true) * @img_scale * @k ph = getHTMLUnitToUnits(h, 0, @pdfunit, true) * @img_scale * @k imsize = [pw, ph] else Error('[Image] Unable to get image width and height: ' + file) end end end # get original image width and height in pixels pixw = imsize[0] pixh = imsize[1] # calculate image width and height on document if (w <= 0) and (h <= 0) # convert image size to document unit w = pixelsToUnits(pixw) h = pixelsToUnits(pixh) elsif w <= 0 w = h * pixw / pixh elsif h <= 0 h = w * pixh / pixw elsif fitbox and (w > 0) and (h > 0) # scale image dimensions proportionally to fit within the (:w, :h) box if ((w * pixh) / (h * pixw)) < 1 h = w * pixh / pixw else w = h * pixw / pixh end end # Check whether we need a new page first as this does not fit prev_x = @x if checkPageBreak(h, y) y = @y if @rtl x += prev_x - @x else x += @x - prev_x end end # resize image to be contained on a single page if fitonpage ratio_wh = w / h if (y + h) > @page_break_trigger h = @page_break_trigger - y w = h * ratio_wh end if !@rtl and ((x + w) > (@w - @r_margin)) w = @w - @r_margin - x h = w / ratio_wh elsif @rtl and ((x - w) < @l_margin) w = x - @l_margin h = w / ratio_wh end end # calculate new minimum dimensions in pixels neww = (w * @k * dpi / @dpi).round newh = (h * @k * dpi / @dpi).round # check if resize is necessary (resize is used only to reduce the image) newsize = neww * newh pixsize = pixw * pixh if resize == 2 resize = true elsif newsize >= pixsize resize = false end # check if image has been already added on document newimage = true if @imagekeys.include?(file) newimage = false; # get existing image data info = getImageBuffer(file) # check if the newer image is larger oldsize = info['w'] * info['h'] if ((oldsize < newsize) and resize) or ((oldsize < pixsize) and !resize) newimage = true end end if newimage #First use of image, get info if (type == '') type = getImageFileType(file, imsize) else type.downcase! type = 'jpeg' if type == 'jpg' end info = false if !resize or !Object.const_defined?(:Magick) if (type == 'jpeg') info=parsejpeg(file) elsif (type == 'png') info=parsepng(file); elsif (type == 'gif') tmpFile = imageToPNG(file) info=parsepng(tmpFile.path) tmpFile.delete else #Allow for additional formats mtd='parse' + type; unless self.respond_to?(mtd, true) Error('Unsupported image type: ' + type); end info=send(mtd, file); end # not use #if info == 'pngalpha' # return ImagePngAlpha(file, x, y, w, h, 'PNG', link, align, resize, dpi, palign) #end end if !info if Object.const_defined?(:Magick) # RMagick library ### T.B.D ### TCPDF 5.0.000 ### # if type == 'SVG' # else img = Magick::ImageList.new(file) # end if resize img.resize(neww,newh) end img.format = 'JPEG' tmpname = Tempfile.new(File::basename(file), @@k_path_cache) tmpname.binmode jpeg_quality = @jpeg_quality tmpname.print img.to_blob { self.quality = jpeg_quality } tmpname.close info = parsejpeg(tmpname.path) tmpname.delete else return false end end if info == false # If false, we cannot process image return false end if ismask # force grayscale info['cs'] = 'DeviceGray' end info['i'] = @numimages if !@imagekeys.include?(file) info['i'] += 1 end if imgmask != false info['masked'] = imgmask end # add image to document setImageBuffer(file, info) end # set alignment @img_rb_y = y + h # set alignment if @rtl if palign == 'L' ximg = @l_margin elsif palign == 'C' ximg = (@w + @l_margin - @r_margin - w) / 2 elsif palign == 'R' ximg = @w - @r_margin - w else ximg = x - w end @img_rb_x = ximg else if palign == 'L' ximg = @l_margin elsif palign == 'C' ximg = (@w + @l_margin - @r_margin - w) / 2 elsif palign == 'R' ximg = @w - @r_margin - w else ximg = x end @img_rb_x = ximg + w end if ismask or hidden # image is not displayed return info['i'] end xkimg = ximg * @k out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q', w * @k, h * @k, xkimg, (@h -(y + h)) * @k, info['i'])) if border != 0 bx = x by = y @x = ximg if @rtl @x += w end @y = y Cell(w, h, '', border, 0, '', 0, '', 0) @x = bx @y = by end if link and !link.empty? Link(ximg, y, w, h, link) end # set pointer to align the successive text/objects case align when 'T' @y = y @x = @img_rb_x when 'M' @y = y + (h/2).round @x = @img_rb_x when 'B' @y = @img_rb_y @x = @img_rb_x when 'N' SetY(@img_rb_y) end @endlinex = @img_rb_x return info['i'] end |
#intToRoman(number) ⇒ Object Also known as: int_to_roman
Returns the Roman representation of an integer number
- @param int :number
-
to convert
- @return string
-
roman representation of the specified number
- @access public
- @since 4.4.004 (2008-12-10)
12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931 12932 12933 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 12944 12945 12946 12947 12948 12949 12950 12951 12952 12953 12954 12955 12956 12957 12958 12959 12960 12961 |
# File 'lib/tcpdf.rb', line 12906 def intToRoman(number) roman = '' while number >= 1000 roman << 'M' number -= 1000 end while number >= 900 roman << 'CM' number -= 900 end while number >= 500 roman << 'D' number -= 500 end while number >= 400 roman << 'CD' number -= 400 end while number >= 100 roman << 'C' number -= 100 end while number >= 90 roman << 'XC' number -= 90 end while number >= 50 roman << 'L' number -= 50 end while number >= 40 roman << 'XL' number -= 40 end while number >= 10 roman << 'X' number -= 10 end while number >= 9 roman << 'IX' number -= 9 end while number >= 5 roman << 'V' number -= 5 end while number >= 4 roman << 'IV' number -= 4 end while number >= 1 roman << 'I' number -= 1 end return roman end |
#isRTLTextDir ⇒ Object Also known as: is_rtl_text_dir
Return the current temporary RTL status
- @return boolean
- @access public
- @since 4.8.014 (2009-11-04)
- @access public
985 986 987 |
# File 'lib/tcpdf.rb', line 985 def isRTLTextDir() return (@rtl or (@tmprtl == 'R')) end |
#lastPage(resetmargins = false) ⇒ Object Also known as: last_page
Reset pointer to the last document page.
- @param boolean :resetmargins
-
if true reset left, right, top margins and Y position.
- @access public
- @since 2.0.000 (2008-01-04)
- @see
- @since 2.0.000 (2008-01-04)
-
setPage(), getPage(), getNumPages()
1557 1558 1559 |
# File 'lib/tcpdf.rb', line 1557 def lastPage(resetmargins=false) setPage(getNumPages(), resetmargins) end |
#Line(x1, y1, x2, y2, style = nil) ⇒ Object Also known as: line
Draws a line between two points.
- @param float :x1
-
Abscissa of first point
- @param float :y1
-
Ordinate of first point
- @param float :x2
-
Abscissa of second point
- @param float :y2]
-
Ordinate of second point
- @param hash :style
-
Line style. Array like for SetLineStyle SetLineStyle. Default value: default line style (empty array).
- @access public
- @since 1.0
- @see
- @since 1.0
-
SetLineWidth(), SetDrawColor(), SetLineStyle()
8079 8080 8081 8082 8083 8084 8085 8086 |
# File 'lib/tcpdf.rb', line 8079 def Line(x1, y1, x2, y2, style=nil) if style.is_a? Hash SetLineStyle(style) end outPoint(x1, y1) outLine(x2, y2) out('S') end |
#Link(x, y, w, h, link, spaces = 0) ⇒ Object Also known as: 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.
- @param float :x
-
Abscissa of the upper-left corner of the rectangle
- @param float :y
-
Ordinate of the upper-left corner of the rectangle
- @param float :w
-
Width of the rectangle
- @param float :h
-
Height of the rectangle
- @param mixed :link
-
URL or identifier returned by AddLink()
- @param int :spaces
-
number of spaces on the text to link
- @access public
- @since 1.5
- @see
- @since 1.5
-
AddLink(), Annotation(), Cell(), Write(), Image()
2934 2935 2936 |
# File 'lib/tcpdf.rb', line 2934 def Link(x, y, w, h, link, spaces=0) Annotation(x, y, w, h, link, {'Subtype'=>'Link'}, spaces) end |
#Ln(h = '', cell = false) ⇒ Object Also known as: ln
Performs a line break. The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
- @param float :h
-
The height of the break. By default, the value equals the height of the last printed cell.
- @param boolean :cell
-
if true add a c_margin to the x coordinate
- @access public
- @since 1.0
- @see
- @since 1.0
-
Cell()
4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 |
# File 'lib/tcpdf.rb', line 4959 def Ln(h='', cell=false) if (@num_columns > 0) and (@y == @columns[@current_column]['y']) and @columns[@current_column]['x'] and (@x == @columns[@current_column]['x']) # revove vertical space from the top of the column return end if cell cellmargin = @c_margin else cellmargin = 0 end if @rtl @x = @w - @r_margin - cellmargin else @x = @l_margin + cellmargin end if h.is_a?(String) @y += @lasth else @y += h end @newline = true end |
#logger ⇒ Object
92 93 94 |
# File 'lib/tcpdf.rb', line 92 def logger Rails.logger end |
#movePage(frompage, topage) ⇒ Object Also known as: move_page
Move a page to a previous position.
- @param int :frompage
-
number of the source page
- @param int :topage
-
number of the destination page (must be less than :frompage)
- @return
-
true in case of success, false in case of error.
- @access public
- @since 4.5.000 (2009-01-02)
13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 13423 13424 13425 13426 13427 13428 13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442 13443 13444 13445 13446 13447 13448 13449 13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 13462 13463 13464 13465 13466 13467 13468 13469 13470 13471 13472 13473 13474 13475 13476 13477 13478 13479 13480 13481 13482 13483 13484 13485 13486 13487 13488 13489 13490 13491 13492 13493 13494 13495 13496 13497 13498 13499 13500 13501 13502 13503 13504 13505 13506 13507 13508 13509 13510 13511 13512 13513 13514 13515 13516 13517 13518 13519 13520 13521 13522 13523 13524 13525 13526 13527 13528 13529 13530 13531 13532 13533 13534 13535 13536 13537 13538 13539 13540 |
# File 'lib/tcpdf.rb', line 13409 def movePage(frompage, topage) if (frompage > @numpages) or (frompage <= topage) return false end if frompage == @page # close the page before moving it endPage() end # move all page-related states tmppage = @pages[frompage] tmppagedim = @pagedim[frompage] tmppagelen = @pagelen[frompage] tmpintmrk = @intmrk[frompage] if @footerpos[frompage] = @footerpos[frompage] end if @footerlen[frompage] = @footerlen[frompage] end if @transfmrk[frompage] tmptransfmrk = @transfmrk[frompage] end if @page_annots[frompage] tmpannots = @page_annots[frompage] end if @newpagegroup[frompage] tmpnewpagegroup = @newpagegroup[frompage] end frompage.downto(topage + 1) do |i| j = i - 1 # shift pages down @pages[i] = @pages[j] @pagedim[i] = @pagedim[j] @pagelen[i] = @pagelen[j] @intmrk[i] = @intmrk[j] if @footerpos[j] @footerpos[i] = @footerpos[j] elsif [i] @footerpos[i] = nil end if @footerlen[j] @footerlen[i] = @footerlen[j] elsif @footerlen[i] @footerlen[i] = nil end if @transfmrk[j] @transfmrk[i] = @transfmrk[j] elsif @transfmrk[i] @transfmrk[i] = nil end if @page_annots[j] @page_annots[i] = @page_annots[j] elsif @page_annots[i] @page_annots[i] = nil end if @newpagegroup[j] @newpagegroup[i] = @newpagegroup[j] elsif @newpagegroup[i] @newpagegroup[i] = nil end end @pages[topage] = tmppage @pagedim[topage] = tmppagedim @pagelen[topage] = tmppagelen @intmrk[topage] = tmpintmrk if @footerpos[topage] = elsif @footerpos[topage] @footerpos[topage] = nil end if @footerlen[topage] = elsif @footerlen[topage] @footerlen[topage] = nil end if tmptransfmrk @transfmrk[topage] = tmptransfmrk elsif @transfmrk[topage] @transfmrk[topage] = nil end if tmpannots @page_annots[topage] = tmpannots elsif @page_annots[topage] @page_annots[topage] = nil end if tmpnewpagegroup @newpagegroup[topage] = tmpnewpagegroup elsif @newpagegroup[topage] @newpagegroup[topage] = nil end # adjust outlines tmpoutlines = @outlines tmpoutlines.each_with_index do |outline, key| if (outline[:p] >= topage) and (outline[:p] < frompage) @outlines[key][:p] = outline[:p] + 1 elsif outline[:p] == frompage @outlines[key][:p] = topage end end # adjust links tmplinks = @links tmplinks.each_with_index do |link, key| next if link.nil? if (link[0] >= topage) and (link[0] < frompage) @links[key][0] = link[0] + 1 elsif link[0] == frompage @links[key][0] = topage end end ### T.B.D ### TCPDF 5.0.001 ### # adjust javascript #tmpjavascript = @javascript #global jfrompage, jtopage #jfrompage = frompage #jtopage = topage #@javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', #create_function('$matches', 'global $jfrompage, $jtopage; # pagenum = matches[3].to_i + 1 # if (pagenum >= jtopage) and (pagenum < jfrompage) # newpage = pagenum + 1 # elsif pagenum == jfrompage # newpage = jtopage # else # newpage = pagenum # end # newpage -= 1 # return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript); # return to last page lastPage(true) return true end |
#MultiCell(w, h, txt, border = 0, align = 'J', fill = 0, ln = 1, x = '', y = '', reseth = true, stretch = 0, ishtml = false, autopadding = true, maxh = 0) ⇒ Object Also known as: multi_cell
This method allows printing text with line breaks. They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the n character). As many cells as necessary are output, one below the other. Text can be aligned, centered or justified. The cell block can be framed and the background painted.
- @param float :w
-
Width of cells. If 0, they extend up to the right margin of the page.
- @param float :h
-
Cell minimum height. The cell extends automatically if needed.
- @param string :txt
-
String to print
- @param mixed :border
-
Indicates if borders must be drawn around the cell block. The value can be either a number:
-
0: no border (default)
-
1: frame
or a string containing some or all of the following characters (in any order):
-
L: left
-
T: top
-
R: right
-
B: bottom
-
- @param string :align
-
Allows to center or align the text. Possible values are:
-
L or empty string: left align
-
C: center
-
R: right align
-
J: justification (default value when :ishtml=false)
-
- @param int :fill
-
Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
- @param int :ln
-
Indicates where the current position should go after the call. Possible values are:
-
0: to the right
-
1: to the beginning of the next line [DEFAULT]
-
2: below
-
- @param float :x
-
x position in user units
- @param float :y
-
y position in user units
- @param boolean :reseth
-
if true reset the last cell height (default true).
- @param int :stretch
-
stretch carachter mode:
-
0 = disabled
-
1 = horizontal scaling only if necessary
-
2 = forced horizontal scaling
-
3 = character spacing only if necessary
-
4 = forced character spacing
-
- @param boolean :ishtml
-
set to true if :txt is HTML content (default = false).
- @param boolean :autopadding
-
if true, uses internal padding and automatically adjust it to account for line width.
- @param float :maxh
-
maximum height. It should be >= :h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when :ishtml=false.
- @return int
-
Rerurn the number of cells or 1 for html mode.
- @access public
- @since 1.3
- @see
- @since 1.3
-
SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 |
# File 'lib/tcpdf.rb', line 3752 def MultiCell(w, h, txt, border=0, align='J', fill=0, ln=1, x='', y='', reseth=true, stretch=0, ishtml=false, autopadding=true, maxh=0) w = 0 unless w.is_a?(Numeric) h = 0 unless h.is_a?(Numeric) if empty_string(@lasth) or reseth # set row height @lasth = @font_size * @cell_height_ratio end if !empty_string(y) SetY(y) else y = GetY() end resth = 0 if !@in_footer and (y + h > @page_break_trigger) # spit cell in two pages newh = @page_break_trigger - y resth = h - newh # cell to be printed on the next page h = newh end # get current page number startpage = @page if !empty_string(x) SetX(x) else x = GetX() end if empty_string(w) or (w <= 0) if @rtl w = @x - @l_margin else w = @w - @r_margin - @x end end # store original margin values l_margin = @l_margin r_margin = @r_margin if @rtl SetRightMargin(@w - @x) SetLeftMargin(@x - w) else SetLeftMargin(@x) SetRightMargin(@w - @x - w) end starty = @y if autopadding # Adjust internal padding if @c_margin < (@line_width / 2) @c_margin = @line_width / 2 end # Add top space if needed if (@lasth - @font_size) < @line_width @y += @line_width / 2 end # add top padding @y += @c_margin end if ishtml # ******* Write HTML text writeHTML(txt, true, false, reseth, true, align) nl = 1 else # ******* Write text nl = Write(@lasth, txt, '', 0, align, true, stretch, false, true, maxh) end if autopadding # add bottom padding @y += @c_margin # Add bottom space if needed if (@lasth - @font_size) < @line_width @y += @line_width / 2 end end # Get end-of-text Y position currentY = @y # get latest page number end_page = @page if resth > 0 skip = endpage - startpage tmpresth = resth while tmpresth > 0 if skip <= 0 # add a page (or trig AcceptPageBreak() for multicolumn mode) checkPageBreak(@page_break_trigger + 1) end tmpresth -= (@h - @t_margin - @b_margin) skip -= 1 end currentY = @y endpage = @page end # check if a new page has been created if end_page > startpage # design borders around HTML cells. for page in startpage..end_page setPage(page) if page == startpage # first page @y = starty # put cursor at the beginning of cell on the first page h = @h - starty - @b_margin cborder = getBorderMode(border, position='start') elsif page == end_page # last page @y = @t_margin # put cursor at the beginning of last page h = currentY - @t_margin if resth > h h = resth end cborder = getBorderMode(border, position='end') else @y = @t_margin # put cursor at the beginning of the current page h = @h - @t_margin - @b_margin resth -= h cborder = getBorderMode(border, position='middle') end nx = x # account for margin changes if page > startpage if @rtl and (@pagedim[page]['orm'] != @pagedim[startpage]['orm']) nx = x + (@pagedim[page]['orm'] - @pagedim[startpage]['orm']) elsif !@rtl and (@pagedim[page]['olm'] != @pagedim[startpage]['olm']) nx = x + (@pagedim[page]['olm'] - @pagedim[startpage]['olm']) end end SetX(nx) ccode = getCellCode(w, h, '', cborder, 1, '', fill, '', 0, false) if (cborder != 0) or (fill == 1) pagebuff = getPageBuffer(@page) pstart = pagebuff[0, @intmrk[@page]] pend = pagebuff[@intmrk[@page]..-1] setPageBuffer(@page, pstart + ccode + "\n" + pend) @intmrk[@page] += (ccode + "\n").length end end else h = [h, currentY - y].max # put cursor at the beginning of text SetY(y) SetX(x) # design a cell around the text ccode = getCellCode(w, h, '', border, 1, '', fill, '', 0, true) if (border != 0) or (fill == 1) if !@transfmrk[@page].nil? pagemark = @transfmrk[@page] @transfmrk[@page] += (ccode + "\n").length elsif @in_footer pagemark = @footerpos[@page] else pagemark = @intmrk[@page] end pagebuff = getPageBuffer(@page) pstart = pagebuff[0, pagemark] pend = pagebuff[pagemark..-1].to_s setPageBuffer(@page, pstart + ccode + "\n" + pend) pagemark += (ccode + "\n").length end end # Get end-of-cell Y position currentY = GetY() # restore original margin values SetLeftMargin(l_margin) SetRightMargin(r_margin) if ln > 0 # Go to the beginning of the next line SetY(currentY) if ln == 2 SetX(x + w) end else # go left or right by case setPage(startpage) @y = y SetX(x + w) end setContentMark() return nl end |
#objclone(object) ⇒ Object
Creates a copy of a class object
- @param object :object
-
class object to be cloned
- @return
-
cloned object
- @access public
- @since 4.5.029 (2009-03-19)
14016 14017 14018 14019 14020 14021 14022 14023 14024 14025 14026 |
# File 'lib/tcpdf.rb', line 14016 def objclone(object) if @diskcache newobj = object.dup newobj.cache_file_length = object.cache_file_length.dup newobj.prev_pages = object.prev_pages.dup newobj.pages = object.pages.dup return newobj else return Marshal.load(Marshal.dump(object)) end end |
#Open ⇒ Object
This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
-
Note: no page is created by this method
- @access public
- @since 1.0
- @see
- @since 1.0
-
AddPage(), Close()
1459 1460 1461 1462 |
# File 'lib/tcpdf.rb', line 1459 def Open() #Begin document @state = 1 end |
#Output(name = '', dest = '') ⇒ Object Also known as: output
Send the document to a given destination: string, local file or browser. In the last case, the plug-in may be used (if present) or a download (“Save as” dialog box) may be forced. The method first calls Close() if necessary to terminate the document.
- @param string :name
-
The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
- @param string :dest
-
Destination where to send the document. It can take one of the following values:
-
I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the “Save as” option on the link generating the PDF.
-
D: send to the browser and force a file download with the name given by name.
-
F: save to a local server file with the name given by name.
-
S: return the document as a string. name is ignored.
-
FI: equivalent to F + I option
-
FD: equivalent to F + D option
-
- @access public
- @since 1.0
- @see
- @since 1.0
-
Close()
5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 |
# File 'lib/tcpdf.rb', line 5117 def Output(name='', dest='') #Output PDF to some destination #Finish document if necessary lastPage() if (@state < 3) Close(); end #Normalize parameters # Boolean no longer supported # if (dest.is_a?(Boolean)) # dest = dest ? 'D' : 'F'; # end dest = dest.upcase if (dest=='') if (name=='') name='doc.pdf'; dest='I'; else dest='F'; end end case (dest) when 'I' # This is PHP specific code ##Send to standard output # if (ob_get_contents()) # Error('Some data has already been output, can\'t send PDF file'); # end # if (php_sapi_name()!='cli') # #We send to a browser # header('Content-Type: application/pdf'); # if (headers_sent()) # Error('Some data has already been output to browser, can\'t send PDF file'); # end # header('Content-Length: ' + @buffer.length); # header('Content-disposition: inline; filename="' + name + '"'); # end return getBuffer when 'D' # PHP specific #Download file # if (ob_get_contents()) # Error('Some data has already been output, can\'t send PDF file'); # end # if (!_SERVER['HTTP_USER_AGENT'].nil? && SERVER['HTTP_USER_AGENT'].include?('MSIE')) # header('Content-Type: application/force-download'); # else # header('Content-Type: application/octet-stream'); # end # if (headers_sent()) # Error('Some data has already been output to browser, can\'t send PDF file'); # end # header('Content-Length: '+ @buffer.length); # header('Content-disposition: attachment; filename="' + name + '"'); return getBuffer when 'F', 'FI', 'FD' # Save PDF to a local file if @diskcache FileUtils.copy(@buffer.path, name) else open(name,'wb') do |f| f.write(@buffer) end end if dest == 'FI' # This is PHP specific code # # send headers to browser # header('Content-Type: application/pdf') # header('Cache-Control: public, must-revalidate, max-age=0') # HTTP/1.1 # header('Pragma: public') # header('Expires: Sat, 26 Jul 1997 05:00:00 GMT') # Date in the past # header('Last-Modified: ' + gmdate('D, d M Y H:i:s') + ' GMT') # header('Content-Length: ' + filesize(name)) # header('Content-Disposition: inline; filename="' + File.basename(name) + '";') # send document to the browser data = '' open(name) do |f| data<< f.read ;end return data elsif dest == 'FD' # This is PHP specific code # # send headers to browser # if ob_get_contents() # Error('Some data has already been output, can\'t send PDF file') # end # header('Content-Description: File Transfer') # if headers_sent()) # Error('Some data has already been output to browser, can\'t send PDF file') # end # header('Cache-Control: public, must-revalidate, max-age=0') # HTTP/1.1 # header('Pragma: public') # header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); # Date in the past # header('Last-Modified: ' + gmdate('D, d M Y H:i:s') + ' GMT') # # force download dialog # header('Content-Type: application/force-download') # header('Content-Type: application/octet-stream', false) # header('Content-Type: application/download', false) # header('Content-Type: application/pdf', false) # # use the Content-Disposition header to supply a recommended filename # header('Content-Disposition: attachment; filename="' + File.basename(name) + '";') # header('Content-Transfer-Encoding: binary') # header('Content-Length: ' + filesize(name)) # send document to the browser data = '' open(name) do |f| data<< f.read ;end return data end when 'S' # Returns PDF as a string return getBuffer else Error('Incorrect output destination: ' + dest); end return ''; ensure destroy(true) end |
#PageNo ⇒ Object Also known as: page_no
Returns the current page number.
- @return int
-
page number
- @access public
- @since 1.0
- @see
- @since 1.0
-
alias_nb_pages()
2130 2131 2132 2133 |
# File 'lib/tcpdf.rb', line 2130 def PageNo() #Get current page number return @page; end |
#PageNoFormatted ⇒ Object Also known as: page_no_formatted
Returns the current page number formatted as a string.
- @access public
- @since 4.2.005 (2008-11-06)
- @see
- @since 4.2.005 (2008-11-06)
-
PaneNo(), formatPageNumber()
9567 9568 9569 |
# File 'lib/tcpdf.rb', line 9567 def PageNoFormatted() return formatPageNumber(PageNo()) end |
#PieSector(xc, yc, r, a, b, style = 'FD', cw = true, o = 90) ⇒ Object Also known as: pie_sector
Draw the sector of a circle. It can be used for instance to render pie charts.
- @param float :xc
-
abscissa of the center.
- @param float :yc
-
ordinate of the center.
- @param float :r
-
radius.
- @param float :a
-
start angle (in degrees).
- @param float :b
-
end angle (in degrees).
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param float :cw
-
indicates whether to go clockwise (default: true).
- @param float :o
-
origin of angles (0 for 3 o’clock, 90 for noon, 180 for 9 o’clock, 270 for 6 o’clock). Default: 90.
- @author
-
Maxime Delorme, Nicola Asuni
- @since 3.1.000 (2008-06-09)
- @access public
9811 9812 9813 |
# File 'lib/tcpdf.rb', line 9811 def PieSector(xc, yc, r, a, b, style='FD', cw=true, o=90) PieSectorXY(xc, yc, r, r, a, b, style, cw, o) end |
#PieSectorXY(xc, yc, rx, ry, a, b, style = 'FD', cw = false, o = 0, nc = 2) ⇒ Object Also known as: pie_sector_xy
Draw the sector of an ellipse. It can be used for instance to render pie charts.
- @param float :xc
-
abscissa of the center.
- @param float :yc
-
ordinate of the center.
- @param float :rx
-
the x-axis radius.
- @param float :ry
-
the y-axis radius.
- @param float :a
-
start angle (in degrees).
- @param float :b
-
end angle (in degrees).
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param float :cw
-
indicates whether to go clockwise.
- @param float :o
-
origin of angles (0 for 3 o’clock, 90 for noon, 180 for 9 o’clock, 270 for 6 o’clock).
- @param integer :nc
-
Number of curves used to draw a 90 degrees portion of arc.
- @author
-
Maxime Delorme, Nicola Asuni
- @since 3.1.000 (2008-06-09)
- @access public
9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 |
# File 'lib/tcpdf.rb', line 9833 def PieSectorXY(xc, yc, rx, ry, a, b, style='FD', cw=false, o=0, nc=2) if @rtl xc = @w - xc end op = getPathPaintOperator(style) ### not use ### #if op == 'f' # line_style = nil #end if cw d = b b = 360 - a + o a = 360 - d + o else b += o a += o end outellipticalarc(xc, yc, rx, ry, 0, a, b, true, nc) out(op) end |
#pixelsToUnits(px) ⇒ Object Also known as: pixels_to_units
Converts pixels to Units.
- @param int
-
:px pixels
- @return float
-
millimeters
- @access public
- @see
-
setImageScale(), getImageScale()
7743 7744 7745 |
# File 'lib/tcpdf.rb', line 7743 def pixelsToUnits(px) return (px.to_f / (@img_scale * @k)) end |
#Polygon(p, style = '', line_style = nil, fill_color = nil, closed = true) ⇒ Object Also known as: polygon
Draws a polygon.
- @param array :p
-
Points 0 to (np - 1). Array with values (x0, y0, x1, y1,…, x(np-1), y(np - 1))
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param array :line_style
-
Line style of polygon. Array with keys among the following:
-
all: Line style of all lines. Array like for SetLineStyle SetLineStyle.
-
0 to (:np - 1): Line style of each line. Array like for SetLineStyle SetLineStyle.
-
If a key is not present or is null, not draws the line. Default value is default line style (empty array).
- @param array :fill_color
-
Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
- @param boolean :closed
-
if true the polygon is closes, otherwise will remain open
- @access public
- @since 2.1.000 (2008-01-08)
8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 |
# File 'lib/tcpdf.rb', line 8367 def Polygon(p, style='', line_style=nil, fill_color=nil, closed=true) style = '' if style.nil? nc = p.length # number of coordinates np = nc / 2 # number of points if closed # close polygon by adding the first 2 points at the end (one line) 0.upto(3) do |i| p[nc + i] = p[i] end # copy style for the last added line if line_style if line_style.is_a? Array and line_style[0] line_style[np] = line_style[0] elsif line_style.is_a? Hash and line_style['all'] line_style[np] = line_style['all'] end end nc += 4 end if (nil != style.index('F')) and fill_color SetFillColorArray(fill_color) end op = getPathPaintOperator(style) if op == 'f' line_style = [] end draw = true if line_style if line_style.is_a? Hash and line_style['all'] SetLineStyle(line_style['all']) else draw = false if op == 'B' # draw fill op = 'f' outPoint(p[0], p[1]) 2.step(nc - 1, 2) do |i| outLine(p[i], p[i + 1]) end out(op) end # draw outline outPoint(p[0], p[1]) 2.step(nc - 1, 2) do |i| line_num = i / 2 - 1 if line_style[line_num] if line_style[line_num] != 0 if line_style[line_num].is_a? Hash out('S') SetLineStyle(line_style[line_num]) outPoint(p[i - 2], p[i - 1]) outLine(p[i], p[i + 1]) out('S') outPoint(p[i], p[i + 1]) else outLine(p[i], p[i + 1]) end end else outLine(p[i], p[i + 1]) end end out(op) end end if draw outPoint(p[0], p[1]) 2.step(nc - 1, 2) do |i| outLine(p[i], p[i + 1]) end out(op) end end |
#PolyLine(p, style = '', line_style = nil, fill_color = nil) ⇒ Object Also known as: poly_line
Draws a polygonal line
- @param array :p
-
Points 0 to (:np - 1). Array with values (x0, y0, x1, y1,…, x(np-1), y(np - 1))
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param array :line_style
-
Line style of polygon. Array with keys among the following:
-
all: Line style of all lines. Array like for SetLineStyle SetLineStyle.
-
0 to (:np - 1): Line style of each line. Array like for SetLineStyle SetLineStyle.
If a key is not present or is null, not draws the line. Default value is default line style (empty array).
-
[@param array :fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). [@param boolean :closed if true the polygon is closes, otherwise will remain open
- @access public
- @since 4.8.003 (2009-09-15)
8348 8349 8350 |
# File 'lib/tcpdf.rb', line 8348 def PolyLine(p, style='', line_style=nil, fill_color=nil) Polygon(p, style, line_style, fill_color, false) end |
#Rect(x, y, w, h, style = '', border_style = {}, fill_color = {}) ⇒ Object Also known as: rect
Draws a rectangle.
- @param float :x
-
Abscissa of upper-left corner (or upper-right corner for RTL language).
- @param float :y
-
Ordinate of upper-left corner (or upper-right corner for RTL language).
- @param float :w
-
Width.
- @param float :h
-
Height.
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
-
all: Line style of all borders. Array like for SetLineStyle SetLineStyle.
-
L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle SetLineStyle.
If a key is not present or is null, not draws the border. Default value: default line style (empty array).
-
- @param array :border_style
-
Border style of rectangle. Array like for SetLineStyle SetLineStyle. Default value: default line style (empty array).
- @param array :fill_color
-
Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
- @access public
- @since 1.0
- @see
- @since 1.0
-
SetLineStyle()
8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 |
# File 'lib/tcpdf.rb', line 8106 def Rect(x, y, w, h, style='', border_style={}, fill_color={}) if style.index('F') != nil and !fill_color.empty? SetFillColorArray(fill_color) end op = getPathPaintOperator(style) if !border_style or !border_style['all'].nil? if !border_style['all'].nil? and border_style['all'] SetLineStyle(border_style['all']) border_style = {} end end outRect(x, y, w, h, op) if border_style border_style2 = {} border_style.each { |line, value| length = line.length 0.upto(length - 1) do |i| border_style2[line[i]] = value end } border_style = border_style2 if !border_style['L'].nil? and border_style['L'] Line(x, y, x, y + h, border_style['L']) end if !border_style['T'].nil? and border_style['T'] Line(x, y, x + w, y, border_style['T']) end if !border_style['R'].nil? and border_style['R'] Line(x + w, y, x + w, y + h, border_style['R']) end if !border_style['B'].nil? and border_style['B'] Line(x, y + h, x + w, y + h, border_style['B']) end end end |
#RegularPolygon(x0, y0, r, ns, angle = 0, draw_circle = false, style = '', line_style = nil, fill_color = nil, circle_style = '', circle_outLine_style = nil, circle_fill_color = nil) ⇒ Object Also known as: regular_polygon
Draws a regular polygon.
- @param float :x0
-
Abscissa of center point.
- @param float :y0
-
Ordinate of center point.
- @param float :r
-
Radius of inscribed circle.
- @param integer :ns
-
Number of sides.
- @param float :angle
-
Angle oriented (anti-clockwise). Default value: 0.
- @param boolean :draw_circle
-
Draw inscribed circle or not. Default value: false.
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param array :line_style
-
Line style of polygon sides. Array with keys among the following:
-
all: Line style of all sides. Array like for SetLineStyle SetLineStyle.
-
0 to (:ns - 1): Line style of each side. Array like for SetLineStyle SetLineStyle.
If a key is not present or is null, not draws the side. Default value is default line style (empty array).
-
- @param array :fill_color
-
Fill color. Format: array(red, green, blue). Default value: default color (empty array).
- @param string :circle_style
-
Style of rendering of inscribed circle (if draws). Possible values are:
-
D or empty string: Draw (default).
-
F: Fill.
-
DF or FD: Draw and fill.
-
CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).
-
CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).
-
- @param array :circle_outLine_style
-
Line style of inscribed circle (if draws). Array like for SetLineStyle SetLineStyle. Default value: default line style (empty array).
- @param array :circle_fill_color
-
Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
- @access public
- @since 2.1.000 (2008-01-08)
8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 |
# File 'lib/tcpdf.rb', line 8469 def RegularPolygon(x0, y0, r, ns, angle=0, draw_circle=false, style='', line_style=nil, fill_color=nil, circle_style='', circle_outLine_style=nil, circle_fill_color=nil) draw_circle = false if draw_circle == 0 if 3 > ns ns = 3 end if draw_circle Circle(x0, y0, r, 0, 360, circle_style, circle_outLine_style, circle_fill_color) end p = [] 0.upto(ns -1) do |i| a = angle + i * 360 / ns a_rad = a * ::Math::PI / 180 # deg2rad p.push x0 + (r * ::Math.sin(a_rad)) p.push y0 + (r * ::Math.cos(a_rad)) end Polygon(p, style, line_style, fill_color) end |
#removeSHY(txt = '') ⇒ Object Also known as: remove_shy
Removes SHY characters from text.
- @param string :txt
-
input string
- @return string
-
without SHY characters.
- @access public
- @since (4.5.019) 2009-02-28
3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 |
# File 'lib/tcpdf.rb', line 3278 def removeSHY(txt='') # Unicode Data # Name : SOFT HYPHEN, commonly abbreviated as SHY # HTML Entity (decimal): ­ # HTML Entity (hex): ­ # HTML Entity (named): ­ # How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173] # UTF-8 (hex): 0xC2 0xAD (c2ad) # UTF-8 character: chr(194).chr(173) txt.force_encoding('ASCII-8BIT') if txt.respond_to?(:force_encoding) txt.gsub!(/([\xc2]{1}[\xad]{1})/, '') if !@is_unicode txt.gsub!(/([\xad]{1})/, '') return txt end txt.force_encoding('UTF-8') if txt.respond_to?(:force_encoding) return txt end |
#revstrpos(haystack, needle, offset = 0) ⇒ Object
Find position of last occurrence of a substring in a string
- @param string :haystack
-
The string to search in.
- @param string :needle
-
substring to search.
- @param int :offset
-
May be specified to begin searching an arbitrary number of characters into the string.
- @return
-
Returns the position where the needle exists. Returns FALSE if the needle was not found.
- @access public
- @since 4.8.038 (2010-03-13)
14051 14052 14053 14054 14055 14056 14057 |
# File 'lib/tcpdf.rb', line 14051 def revstrpos(haystack, needle, offset = 0) length = haystack.length offset = (offset > 0) ? (length - offset) : offset.abs pos = haystack.reverse.index(needle.reverse, offset) return (pos.nil? ? nil : length - pos - needle.length) end |
#rollbackTransaction(this_self = false) ⇒ Object Also known as: rollback_transaction
This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
- @param boolean :this_self
-
if true restores current class object to previous state without the need of reassignment via the returned value.
- @return
-
TCPDF object.
- @access public
- @since 4.5.029 (2009-03-19)
13983 13984 13985 13986 13987 13988 13989 13990 13991 13992 13993 13994 13995 13996 13997 13998 13999 14000 14001 14002 14003 14004 14005 14006 |
# File 'lib/tcpdf.rb', line 13983 def rollbackTransaction(this_self=false) if @objcopy if @objcopy.diskcache # truncate files to previous values @objcopy.cache_file_length.each { |file, length| File.truncate(file, length) if File.exist?(file) } @pages.each_with_index do |file, i| if @prev_pages[i] and File.exist?(@prev_pages[i].path) File.delete(file.path) end end end destroy(true, true) if this_self objvars = @objcopy.instance_variables objvars.each {|key| eval("#{key} = @objcopy.instance_variable_get(key)") if key.to_s != '@objcopy' } end return @objcopy end return self end |
#Rotate(angle, x = "", y = "") ⇒ Object Also known as: rotate
Rotate object.
- @param float :angle
-
angle in degrees for counter-clockwise rotation
- @param int :x
-
abscissa of the rotation center. Default is current x position
- @param int :y
-
ordinate of the rotation center. Default is current y position
- @access public
- @since 2.1.000 (2008-01-07)
- @see
- @since 2.1.000 (2008-01-07)
-
StartTransform(), StopTransform()
7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 |
# File 'lib/tcpdf.rb', line 7836 def Rotate(angle, x="", y="") if (x == '') x = @x end if (y == '') y = @y end y = (@h - y) * @k x *= @k # calculate elements of transformation matrix tm = [] tm[0] = ::Math::cos(angle * ::Math::PI / 180) # deg2rad tm[1] = ::Math::sin(angle * ::Math::PI / 180) # deg2rad tm[2] = -tm[1] tm[3] = tm[0] tm[4] = x + tm[1] * y - tm[0] * x tm[5] = y - tm[0] * y - tm[1] * x # generate the transformation matrix Transform(tm) end |
#RoundedRect(x, y, w, h, r, round_corner = '1111', style = '', border_style = nil, fill_color = nil) ⇒ Object Also known as: rounded_rect
Draws a rounded rectangle.
- @param float :x
-
Abscissa of upper-left corner.
- @param float :y
-
Ordinate of upper-left corner.
- @param float :w
-
Width.
- @param float :h
-
Height.
- @param float :r
-
the radius of the circle used to round off the corners of the rectangle.
- @param string :round_corner
-
Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top left, top right, bottom right and bottom left. Default value: all rounded corner (“1111”).
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param array :border_style
-
Border style of rectangle. Array like for SetLineStyle SetLineStyle. Default value: default line style (empty array).
- @param array :fill_color
-
Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
- @access public
- @since 2.1.000 (2008-01-08)
8561 8562 8563 |
# File 'lib/tcpdf.rb', line 8561 def RoundedRect(x, y, w, h, r, round_corner='1111', style='', border_style=nil, fill_color=nil) RoundedRectXY(x, y, w, h, r, r, round_corner, style, border_style, fill_color) end |
#RoundedRectXY(x, y, w, h, rx, ry, round_corner = '1111', style = '', border_style = nil, fill_color = nil) ⇒ Object Also known as: rounded_rect_xy
Draws a rounded rectangle.
- @param float :x
-
Abscissa of upper-left corner.
- @param float :y
-
Ordinate of upper-left corner.
- @param float :w
-
Width.
- @param float :h
-
Height.
- @param float :rx
-
the x-axis radius of the ellipse used to round off the corners of the rectangle.
- @param float :ry
-
the y-axis radius of the ellipse used to round off the corners of the rectangle.
- @param string :round_corner
-
Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top left, top right, bottom right and bottom left. Default value: all rounded corner (“1111”).
- @param string :style
-
Style of rendering. See the getPathPaintOperator() function for more information.
- @param array :border_style
-
Border style of rectangle. Array like for SetLineStyle SetLineStyle. Default value: default line style (empty array).
- @param array :fill_color
-
Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
- @access public
- @since 4.9.019 (2010-04-22)
8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 |
# File 'lib/tcpdf.rb', line 8581 def RoundedRectXY(x, y, w, h, rx, ry, round_corner='1111', style='', border_style=nil, fill_color=nil) style = '' if style.nil? if (round_corner == '0000') or ((rx == ry) and (rx == 0)) # Not rounded Rect(x, y, w, h, style, border_style, fill_color) return end # Rounded if (nil != style.index('F')) and fill_color SetFillColorArray(fill_color) end op = getPathPaintOperator(style) if op == 'f' border_style = [] end if border_style SetLineStyle(border_style) end myArc = 4 / 3 * (::Math.sqrt(2) - 1) outPoint(x + rx, y) xc = x + w - rx yc = y + ry outLine(xc, y) if round_corner[0,1] == '1' outCurve(xc + (rx * myArc), yc - ry, xc + rx, yc - (ry * myArc), xc + rx, yc) else outLine(x + w, y) end xc = x + w - rx yc = y + h - ry outLine(x + w, yc) if round_corner[1,1] == '1' outCurve(xc + rx, yc + (ry * myArc), xc + (rx * myArc), yc + ry, xc, yc + ry) else outLine(x + w, y + h) end xc = x + rx yc = y + h - ry outLine(xc, y + h) if round_corner[2,1] == '1' outCurve(xc - (rx * myArc), yc + ry, xc - rx, yc + (ry * myArc), xc - rx, yc) else outLine(x, y + h) end xc = x + rx yc = y + ry outLine(x, yc) if round_corner[3,1] == '1' outCurve(xc - rx, yc - (ry * myArc), xc - (rx * myArc), yc - ry, xc, yc - ry) else outLine(x, y) outLine(x + rx, y) end out(op) end |
#setAlpha(alpha, bm = 'Normal') ⇒ Object Also known as: set_alpha
Set alpha for stroking (CA) and non-stroking (ca) operations.
- @param float :alpha
-
real value from 0 (transparent) to 1 (opaque)
- @param string :bm
-
blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
- @access public
- @since 3.0.000 (2008-03-27)
9684 9685 9686 9687 |
# File 'lib/tcpdf.rb', line 9684 def setAlpha(alpha, bm='Normal') gs = addExtGState({'ca' => alpha, 'CA' => alpha, 'BM' => '/' + bm, 'AIS' => 'false'}) setExtGState(gs) end |
#SetAuthor(author) ⇒ Object Also known as:
Defines the author of the document.
- @param string :author
-
The name of the author.
- @access public
- @since 1.2
- @see
- @since 1.2
-
SetCreator(), SetKeywords(), SetSubject(), SetTitle()
1406 1407 1408 1409 |
# File 'lib/tcpdf.rb', line 1406 def SetAuthor() #Author of document @author = end |
#SetAutoPageBreak(auto, margin = 0) ⇒ Object Also known as: set_auto_page_break
Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
- @param boolean :auto
-
Boolean indicating if mode should be on or off.
- @param float :margin
-
Distance from the bottom of the page.
- @access public
- @since 1.0
- @see
- @since 1.0
-
Cell(), MultiCell(), AcceptPageBreak()
1277 1278 1279 1280 1281 1282 |
# File 'lib/tcpdf.rb', line 1277 def SetAutoPageBreak(auto, margin=0) #Set auto page break mode and triggering margin @auto_page_break = auto @b_margin = margin @page_break_trigger = @h - margin end |
#SetBooklet(booklet = true, inner = -1,, outer = -1)) ⇒ Object Also known as: set_booklet
Set the booklet mode for double-sided pages.
- @param boolean :booklet
-
true set the booklet mode on, fals eotherwise.
- @param float :inner
-
Inner page margin.
- @param float :outer
-
Outer page margin.
- @access public
- @since 4.2.000 (2008-10-29)
12792 12793 12794 12795 12796 12797 12798 12799 12800 |
# File 'lib/tcpdf.rb', line 12792 def SetBooklet(booklet=true, inner=-1, outer=-1) @booklet = booklet if inner >= 0 @l_margin = inner end if outer >= 0 @r_margin = outer end end |
#setCellHeightRatio(h) ⇒ Object Also known as: set_cell_height_ratio
Set the height of cell repect font height.
- @param int :h
-
cell proportion respect font height (typical value = 1.25).
- @access public
- @since 3.0.014 (2008-06-04)
9710 9711 9712 |
# File 'lib/tcpdf.rb', line 9710 def setCellHeightRatio(h) @cell_height_ratio = h end |
#SetCellPadding(pad) ⇒ Object Also known as: set_cell_padding
Set the internal Cell padding.
- @param float :pad
-
internal padding.
- @access public
- @since 2.1.000 (2008-01-09)
- @see
- @since 2.1.000 (2008-01-09)
-
Cell(), SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
1264 1265 1266 |
# File 'lib/tcpdf.rb', line 1264 def SetCellPadding(pad) @c_margin = pad end |
#SetCompression(compress) ⇒ Object Also known as: set_compression
Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
-
Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
- @param boolean :compress
-
Boolean indicating if compression must be enabled.
- @access public
- @since 1.4
1363 1364 1365 1366 1367 1368 1369 1370 |
# File 'lib/tcpdf.rb', line 1363 def SetCompression(compress) #Set page compression if Object.const_defined?(:Zlib) @compress = compress else @compress = false end end |
#SetCreator(creator) ⇒ Object Also known as: set_creator
Defines the creator of the document. This is typically the name of the application that generates the PDF.
- @param string :creator
-
The name of the creator.
- @access public
- @since 1.2
- @see
- @since 1.2
-
SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
1432 1433 1434 1435 |
# File 'lib/tcpdf.rb', line 1432 def SetCreator(creator) #Creator of document @creator = creator end |
#SetDefaultMonospacedFont(font) ⇒ Object Also known as: set_default_monospaced_font
Defines the default monospaced font.
- @param string :font
-
Font name.
- @access public
- @since 4.5.025
2881 2882 2883 |
# File 'lib/tcpdf.rb', line 2881 def SetDefaultMonospacedFont(font) @default_monospaced_font = font end |
#SetDisplayMode(zoom, layout = 'SinglePage', mode = 'UseNone') ⇒ Object Also known as: set_display_mode
Defines the way the document is to be displayed by the viewer.
- @param mixed :zoom
-
The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use.
-
fullpage: displays the entire page on screen
-
fullwidth: uses maximum width of window
-
real: uses real size (equivalent to 100% zoom)
-
default: uses viewer default mode
-
- @param string :layout
-
The page layout. Possible values are:
-
SinglePage Display one page at a time
-
OneColumn Display the pages in one column
-
TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left
-
TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right
-
TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left
-
TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right
-
- @param string :mode
-
A name object specifying how the document should be displayed when opened:
-
UseNone Neither document outline nor thumbnail images visible
-
UseOutlines Document outline visible
-
UseThumbs Thumbnail images visible
-
FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible
-
UseOC (PDF 1.5) Optional content group panel visible
-
UseAttachments (PDF 1.6) Attachments panel visible
-
- @access public
- @since 1.2
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 |
# File 'lib/tcpdf.rb', line 1312 def SetDisplayMode(zoom, layout='SinglePage', mode='UseNone') #Set display mode in viewer if (zoom == 'fullpage' or zoom == 'fullwidth' or zoom == 'real' or zoom == 'default' or !zoom.is_a?(String)) @zoom_mode = zoom else Error('Incorrect zoom display mode: ' + zoom) end case layout when 'default', 'single', 'SinglePage' @layout_mode = 'SinglePage' when 'continuous', 'OneColumn' @layout_mode = 'OneColumn' when 'two', 'TwoColumnLeft' @layout_mode = 'TwoColumnLeft' when 'TwoColumnRight' @layout_mode = 'TwoColumnRight' when 'TwoPageLeft' @layout_mode = 'TwoPageLeft' when 'TwoPageRight' @layout_mode = 'TwoPageRight' else @layout_mode = 'SinglePage' end case mode when 'UseNone' @page_mode = 'UseNone' when 'UseOutlines' @page_mode = 'UseOutlines' when 'UseThumbs' @page_mode = 'UseThumbs' when 'FullScreen' @page_mode = 'FullScreen' when 'UseOC' @page_mode = 'UseOC' when '' @page_mode = 'UseAttachments' else @page_mode = 'UseNone' end end |
#SetDrawColor(col1 = 0, col2 = -1,, col3 = -1,, col4 = -1)) ⇒ Object Also known as: set_draw_color
Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
- @param int :col1
-
Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
- @param int :col2
-
Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
- @param int :col3
-
Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
- @param int :col4
-
Key (Black) color for CMYK. Value between 0 and 255
- @access public
- @since 1.3
- @see
- @since 1.3
-
SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 |
# File 'lib/tcpdf.rb', line 2189 def SetDrawColor(col1=0, col2=-1, col3=-1, col4=-1) # set default values unless col1.is_a?(Numeric) col1 = 0 end unless col2.is_a?(Numeric) col2 = 0 end unless col3.is_a?(Numeric) col3 = 0 end unless col4.is_a?(Numeric) col4 = 0 end #Set color for all stroking operations if (col2 == -1) and (col3 == -1) and (col4 == -1) # Grey scale @draw_color = sprintf('%.3f G', col1 / 255.0) @strokecolor['G'] = col1 elsif col4 == -1 # RGB @draw_color = sprintf('%.3f %.3f %.3f RG', col1 / 255.0, col2 / 255.0, col3 / 255.0) @strokecolor['R'] = col1 @strokecolor['G'] = col2 @strokecolor['B'] = col3 else # CMYK @draw_color = sprintf('%.3f %.3f %.3f %.3f K', col1 / 100.0, col2 / 100.0, col3 / 100.0, col4 / 100.0) @strokecolor['C'] = col1 @strokecolor['M'] = col2 @strokecolor['Y'] = col3 @strokecolor['K'] = col4 end if (@page>0) out(@draw_color + ' ') end end |
#SetDrawColorArray(color) ⇒ Object Also known as: set_draw_color_array
Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
- @param array or ordered hash :color
-
array(or ordered hash) of colors
- @access public
- @since 3.1.000 (2008-6-11)
- @see
- @since 3.1.000 (2008-6-11)
-
SetDrawColor()
2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 |
# File 'lib/tcpdf.rb', line 2165 def SetDrawColorArray(color) if !color.nil? color = color.values if color.is_a? Hash r = !color[0].nil? ? color[0] : -1 g = !color[1].nil? ? color[1] : -1 b = !color[2].nil? ? color[2] : -1 k = !color[3].nil? ? color[3] : -1 if r >= 0 SetDrawColor(r, g, b, k) end end end |
#SetFillColor(col1 = 0, col2 = -1,, col3 = -1,, col4 = -1)) ⇒ Object Also known as: set_fill_color
Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
- @param int :col1
-
Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
- @param int :col2
-
Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
- @param int :col3
-
Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
- @param int :col4
-
Key (Black) color for CMYK. Value between 0 and 255
- @access public
- @since 1.3
- @see
- @since 1.3
-
SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 |
# File 'lib/tcpdf.rb', line 2261 def SetFillColor(col1=0, col2=-1, col3=-1, col4=-1) # set default values unless col1.is_a?(Numeric) col1 = 0 end unless col2.is_a?(Numeric) col2 = -1 end unless col3.is_a?(Numeric) col3 = -1 end unless col4.is_a?(Numeric) col4 = -1 end # Set color for all filling operations if (col2 == -1) and (col3 == -1) and (col4 == -1) # Grey scale @fill_color = sprintf('%.3f g', col1 / 255.0) @bgcolor['G'] = col1 elsif col4 == -1 # RGB @fill_color = sprintf('%.3f %.3f %.3f rg', col1 / 255.0, col2 / 255.0, col3 / 255.0) @bgcolor['R'] = col1 @bgcolor['G'] = col2 @bgcolor['B'] = col3 else # CMYK @fill_color = sprintf('%.3f %.3f %.3f %.3f k', col1 / 100.0, col2 / 100.0, col3 / 100.0, col4 / 100.0) @bgcolor['C'] = col1 @bgcolor['M'] = col2 @bgcolor['Y'] = col3 @bgcolor['K'] = col4 end @color_flag = (@fill_color != @text_color) if @page > 0 out(@fill_color) end end |
#SetFillColorArray(color) ⇒ Object Also known as: set_fill_color_array
Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
- @param array or ordered hash :color
-
array(or ordered hash) of colors
- @access public
- @since 3.1.000 (2008-6-11)
- @see
- @since 3.1.000 (2008-6-11)
-
SetFillColor()
2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 |
# File 'lib/tcpdf.rb', line 2237 def SetFillColorArray(color) if !color.nil? color = color.values if color.is_a? Hash r = !color[0].nil? ? color[0] : -1 g = !color[1].nil? ? color[1] : -1 b = !color[2].nil? ? color[2] : -1 k = !color[3].nil? ? color[3] : -1 if r >= 0 SetFillColor(r, g, b, k) end end end |
#SetFont(family, style = '', size = 0, fontfile = '') ⇒ Object Also known as: set_font
Sets the font used to print character strings. The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe). The method can be called before the first page is created and the font is retained from page to page. If you just wish to change the current font size, it is simpler to call SetFontSize().
-
Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:
-
They are in the current directory (the one where the running script lies)
-
They are in one of the directories defined by the include_path parameter
-
They are in the directory defined by the FPDF_FONTPATH constant
-
- @param string :family
-
Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):
-
times (Times-Roman)
-
timesb (Times-Bold)
-
timesi (Times-Italic)
-
timesbi (Times-BoldItalic)
-
helvetica (Helvetica)
-
helveticab (Helvetica-Bold)
-
helveticai (Helvetica-Oblique)
-
helveticabi (Helvetica-BoldOblique)
-
courier (Courier)
-
courierb (Courier-Bold)
-
courieri (Courier-Oblique)
-
courierbi (Courier-BoldOblique)
-
symbol (Symbol)
-
zapfdingbats (ZapfDingbats)
It is also possible to pass an empty string. In that case, the current family is retained.
-
- @param string :style
-
Font style. Possible values are (case insensitive):
-
empty string: regular
-
B: bold
-
I: italic
-
U: underline
-
D: line trough
-
O: overline
or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined.
-
- @param float :size
-
Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
- @param string :fontfile
-
The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
- @access public
- @since 1.0
- @see
- @since 1.0
-
AddFont(), SetFontSize()
2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 |
# File 'lib/tcpdf.rb', line 2788 def SetFont(family, style='', size=0, fontfile='') # Select a font; size given in points if size == 0 size = @font_size_pt end # try to add font (if not already added) fontdata = AddFont(family, style, fontfile) @font_family = fontdata['family'] @font_style = fontdata['style'] @current_font = getFontBuffer(fontdata['fontkey']) SetFontSize(size) end |
#SetFontSize(size) ⇒ Object Also known as: set_font_size
Defines the size of the current font.
- @param float :size
-
The size (in points)
- @access public
- @since 1.0
- @see
- @since 1.0
-
SetFont()
2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 |
# File 'lib/tcpdf.rb', line 2809 def SetFontSize(size) #Set font size in points @font_size_pt = size; @font_size = size.to_f / @k; if !@current_font['desc'].nil? and !@current_font['desc']['Ascent'].nil? and (@current_font['desc']['Ascent'] > 0) @font_ascent = @current_font['desc']['Ascent'] * @font_size / 1000 else @font_ascent = 0.85 * @font_size end if !@current_font['desc'].nil? and !@current_font['desc']['Descent'].nil? and (@current_font['desc']['Descent'] <= 0) @font_descent = - @current_font['desc']['Descent'] * @font_size / 1000 else @font_descent = 0.15 * @font_size end if (@page > 0) and !@current_font['i'].nil? out(sprintf('BT /F%d %.2f Tf ET ', @current_font['i'], @font_size_pt)); end end |
#setFooterFont(font) ⇒ Object Also known as:
Set footer font.
- @param array :font
-
font
- @access public
- @since 1.1
7568 7569 7570 |
# File 'lib/tcpdf.rb', line 7568 def (font) @footer_font = font; end |
#SetFooterFont(font) ⇒ Object
7573 7574 7575 7576 |
# File 'lib/tcpdf.rb', line 7573 def SetFooterFont(font) warn "[DEPRECATION] 'SetFooterFont' is deprecated. Please use 'set_footer_font' instead." (font) end |
#setFooterMargin(fm = 10) ⇒ Object Also known as:
Set footer margin. (minimum distance between footer and bottom page margin)
- @param int :fm
-
distance in millimeters
- @access public
1837 1838 1839 |
# File 'lib/tcpdf.rb', line 1837 def (fm=10) @footer_margin = fm; end |
#SetFooterMargin(fm = 10) ⇒ Object
1842 1843 1844 1845 |
# File 'lib/tcpdf.rb', line 1842 def SetFooterMargin(fm=10) warn "[DEPRECATION] 'SetFooterMargin' is deprecated. Please use 'set_footer_margin' instead." (fm) end |
#setHeaderData(ln = "", lw = 0, ht = "", hs = "") ⇒ Object Also known as: set_header_data
Set header data.
- @param string :ln
-
header image logo
- @param string :lw
-
header image logo width in mm
- @param string :ht
-
string to print as title on document header
- @param string :hs
-
string to print on document header
- @access public
1771 1772 1773 1774 1775 1776 |
# File 'lib/tcpdf.rb', line 1771 def setHeaderData(ln="", lw=0, ht="", hs="") @header_logo = ln || "" @header_logo_width = lw || 0 @header_title = ht || "" @header_string = hs || "" end |
#SetHeaderData(ln = "", lw = 0, ht = "", hs = "") ⇒ Object
1779 1780 1781 1782 |
# File 'lib/tcpdf.rb', line 1779 def SetHeaderData(ln="", lw=0, ht="", hs="") warn "[DEPRECATION] 'SetHeaderData' is deprecated. Please use 'set_header_data' instead." setHeaderData(ln, lw, ht, hs) end |
#SetHeaderFont(font) ⇒ Object
7546 7547 7548 7549 |
# File 'lib/tcpdf.rb', line 7546 def SetHeaderFont(font) warn "[DEPRECATION] 'SetHeaderFont' is deprecated. Please use 'set_header_font' instead." setHeaderFont(font) end |
#setHeaderFont(font) ⇒ Object Also known as: set_header_font
Set header font.
- @param array :font
-
font
- @access public
- @since 1.1
7541 7542 7543 |
# File 'lib/tcpdf.rb', line 7541 def setHeaderFont(font) @header_font = font; end |
#setHeaderMargin(hm = 10) ⇒ Object Also known as: set_header_margin
Set header margin. (minimum distance between header and top page margin)
- @param int :hm
-
distance in user units
- @access public
1810 1811 1812 |
# File 'lib/tcpdf.rb', line 1810 def setHeaderMargin(hm=10) @header_margin = hm; end |
#SetHeaderMargin(hm = 10) ⇒ Object
1815 1816 1817 1818 |
# File 'lib/tcpdf.rb', line 1815 def SetHeaderMargin(hm=10) warn "[DEPRECATION] 'SetHeaderMargin' is deprecated. Please use 'set_header_margin' instead." setHeaderMargin(hm) end |
#setHtmlVSpace(tagvs) ⇒ Object Also known as: set_html_v_space
Set the vertical spaces for HTML tags. The array must have the following structure (example):
:tagvs = {'h1' => [{'h' => '', 'n' => 2}, {'h' => 1.3, 'n' => 1}]}
The first array level contains the tag names, the second level contains 0 for opening tags or 1 for closing tags, the third level contains the vertical space unit (h) and the number spaces to add (n). If the h parameter is not specified, default values are used.
- @param array :tagvs
-
array of tags and relative vertical spaces.
- @access public
- @since 4.2.001 (2008-10-30)
12834 12835 12836 |
# File 'lib/tcpdf.rb', line 12834 def setHtmlVSpace(tagvs) @tagvspaces = tagvs end |
#setImageScale(scale) ⇒ Object Also known as: set_image_scale
Set the adjusting factor to convert pixels to user units.
- @param float :scale
-
adjusting factor to convert pixels to user units.
- @author
-
Nicola Asuni
- @access public
- @since 1.5.2
1020 1021 1022 |
# File 'lib/tcpdf.rb', line 1020 def setImageScale(scale) @img_scale = scale; end |
#SetImageScale(scale) ⇒ Object
1025 1026 1027 1028 |
# File 'lib/tcpdf.rb', line 1025 def SetImageScale(scale) warn "[DEPRECATION] 'SetImageScale' is deprecated. Please use 'set_image_scale' instead." setImageScale(scale) end |
#setJPEGQuality(quality) ⇒ Object Also known as: set_jpeg_quality
Set the default JPEG compression quality (1-100)
- @param int :quality
-
JPEG quality, integer between 1 and 100
- @access public
- @since 3.0.000 (2008-03-27)
9696 9697 9698 9699 9700 9701 |
# File 'lib/tcpdf.rb', line 9696 def setJPEGQuality(quality) if (quality < 1) or (quality > 100) quality = 75 end @jpeg_quality = quality end |
#SetKeywords(keywords) ⇒ Object Also known as: set_keywords
Associates keywords with the document, generally in the form ‘keyword1 keyword2 …’.
- @param string :keywords
-
The list of keywords.
- @access public
- @since 1.2
- @see
- @since 1.2
-
SetAuthor(), SetCreator(), SetSubject(), SetTitle()
1419 1420 1421 1422 |
# File 'lib/tcpdf.rb', line 1419 def SetKeywords(keywords) #Keywords of document @keywords = keywords end |
#SetLanguageArray(language) ⇒ Object
7604 7605 7606 7607 |
# File 'lib/tcpdf.rb', line 7604 def SetLanguageArray(language) warn "[DEPRECATION] 'SetLanguageArray' is deprecated. Please use 'set_language_array' instead." setLanguageArray(language) end |
#setLanguageArray(language) ⇒ Object Also known as: set_language_array
Set language array.
- @param array :language
- @since 1.1
7594 7595 7596 7597 7598 7599 7600 7601 |
# File 'lib/tcpdf.rb', line 7594 def setLanguageArray(language) @l = language; if @l['a_meta_dir'] @rtl = (@l['a_meta_dir'] == 'rtl') ? true : false else @rtl = false end end |
#setLastH(h) ⇒ Object Also known as: set_last_h
Set the last cell height.
- @param float :h
-
cell height.
- @author
-
Nicola Asuni
- @access public
- @since 1.53.0.TC034
997 998 999 |
# File 'lib/tcpdf.rb', line 997 def setLastH(h) @lasth = h end |
#SetLeftMargin(margin) ⇒ Object Also known as: set_left_margin
Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin.
- @param float :margin
-
The margin.
- @access public
- @since 1.4
- @see
- @since 1.4
-
SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
1217 1218 1219 1220 1221 1222 1223 |
# File 'lib/tcpdf.rb', line 1217 def SetLeftMargin(margin |