Class: TCPDF
- Inherits:
-
Object
- Object
- TCPDF
- Includes:
- Core::RFPDF, RFPDF, RFPDF::Math
- Defined in:
- lib/plugins/rfpdf/lib/tcpdf.rb
Overview
This is a Ruby class for generating PDF files on-the-fly without requiring
external extensions.<br> 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]<br> TCPDF project (tcpdf.sourceforge.net) is based on
the Public Domain FPDF class by Olivier Plathey (www.fpdf.org).
> To add your own
TTF fonts please read /fonts/README.TXT @@version 1.53.0.TC031
Direct Known Subclasses
Constant Summary
- @@version =
"1.53.0.TC031"
- @@fpdf_charwidths =
{}
- @@k_cell_height_ratio =
1.25
- @@k_blank_image =
""
- @@k_small_ratio =
2/3.0
- @@k_path_cache =
Rails.root.join('tmp')
- @@k_path_url_cache =
Rails.root.join('tmp')
Constants included from RFPDF::Math
RFPDF::Math::DG, RFPDF::Math::DR, RFPDF::Math::GD, RFPDF::Math::GR, RFPDF::Math::PI2, RFPDF::Math::RD, RFPDF::Math::RG
Instance Attribute Summary (collapse)
-
- (Object) barcode
Returns the value of attribute barcode.
-
- (Object) buffer
Returns the value of attribute buffer.
-
- (Object) color_flag
Returns the value of attribute color_flag.
-
- (Object) default_font
Returns the value of attribute default_font.
-
- (Object) default_table_columns
Returns the value of attribute default_table_columns.
-
- (Object) diffs
Returns the value of attribute diffs.
-
- (Object) draw_color
Returns the value of attribute draw_color.
-
- (Object) encoding
Returns the value of attribute encoding.
-
- (Object) fill_color
Returns the value of attribute fill_color.
-
- (Object) font_family
Returns the value of attribute font_family.
-
- (Object) font_files
Returns the value of attribute font_files.
-
- (Object) font_size_pt
Returns the value of attribute font_size_pt.
-
- (Object) font_style
Returns the value of attribute font_style.
-
- (Object) fonts
Returns the value of attribute fonts.
-
- (Object) header_logo
Returns the value of attribute header_logo.
-
- (Object) header_logo_width
Returns the value of attribute header_logo_width.
-
- (Object) header_string
Returns the value of attribute header_string.
-
- (Object) header_title
Returns the value of attribute header_title.
-
- (Object) header_width
Returns the value of attribute header_width.
-
- (Object) images
Returns the value of attribute images.
-
- (Object) img_scale
Returns the value of attribute img_scale.
-
- (Object) in_footer
Returns the value of attribute in_footer.
-
- (Object) is_unicode
Returns the value of attribute is_unicode.
-
- (Object) lasth
Returns the value of attribute lasth.
-
- (Object) li_spacer
Returns the value of attribute li_spacer.
-
- (Object) links
Returns the value of attribute links.
-
- (Object) list_count
Returns the value of attribute list_count.
-
- (Object) list_ordered
Returns the value of attribute list_ordered.
-
- (Object) max_table_columns
Returns the value of attribute max_table_columns.
-
- (Object) n
Returns the value of attribute n.
-
- (Object) offsets
Returns the value of attribute offsets.
-
- (Object) orientation_changes
Returns the value of attribute orientation_changes.
-
- (Object) page
Returns the value of attribute page.
-
- (Object) page_links
Returns the value of attribute page_links.
-
- (Object) pages
Returns the value of attribute pages.
-
- (Object) pdf_version
Returns the value of attribute pdf_version.
-
- (Object) prevfill_color
Returns the value of attribute prevfill_color.
-
- (Object) prevtext_color
Returns the value of attribute prevtext_color.
-
- (Object) print_footer
Returns the value of attribute print_footer.
-
- (Object) print_header
Returns the value of attribute print_header.
-
- (Object) state
Returns the value of attribute state.
-
- (Object) tableborder
Returns the value of attribute tableborder.
-
- (Object) tdalign
Returns the value of attribute tdalign.
-
- (Object) tdbegin
Returns the value of attribute tdbegin.
-
- (Object) tdfill
Returns the value of attribute tdfill.
-
- (Object) tdheight
Returns the value of attribute tdheight.
-
- (Object) tdwidth
Returns the value of attribute tdwidth.
-
- (Object) tempfontsize
Returns the value of attribute tempfontsize.
-
- (Object) text_color
Returns the value of attribute text_color.
-
- (Object) underline
Returns the value of attribute underline.
-
- (Object) ws
Returns the value of attribute ws.
Instance Method Summary (collapse)
-
- (Object) AcceptPageBreak
(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.
-
- (Object) AddFont(family, style = '', file = '')
(also: #add_font)
Imports a TrueType or Type1 font and makes it available.
-
- (Object) addHtmlLink(url, name, fill = 0)
Output anchor link.
-
- (Object) AddLink
(also: #add_link)
Creates a new internal link and returns its identifier.
-
- (Object) AddPage(orientation = '')
(also: #add_page)
Adds a new page to the document.
-
- (Object) AliasNbPages(alias_nb = '{nb}')
(also: #alias_nb_pages)
Defines an alias for the total number of pages.
-
- (Object) begindoc
Start document.
-
- (Object) beginpage(orientation)
beginpage.
- - (Boolean) BreakThePage?(h) (also: #break_the_page?)
-
- (Object) Cell(w, h = 0, txt = '', border = 0, ln = 0, align = '', fill = 0, link = nil)
(also: #cell)
Prints a cell (rectangular area) with optional borders, background color and character string.
-
- (Object) checkTableBlockingCellPosition(table, tr_id, td_id)
Check html table tag position.
- - (Object) Circle(mid_x, mid_y, radius, style = '') (also: #circle)
-
- (Object) Close
Terminates the PDF document.
-
- (Object) closedHTMLTagCalc(tag)
Calculate closing tags.
-
- (Object) closedHTMLTagHandler(tag)
Process closing tags.
-
- (Object) convertColorHexToDec(color = "#000000")
Returns an associative array (keys: R,G,B) from a hex html code (e.g. #3FE5AA).
-
- (Object) dochecks
Check for locale-related bug.
-
- (Object) dolinetxt(x, y, txt)
Underline and Deleted text.
-
- (Object) enddoc
enddoc.
-
- (Object) endpage
End of page contents.
-
- (Object) Error(msg)
(also: #error)
This method is automatically called in case of fatal error; it simply outputs the message and halts the execution.
-
- (Object) escape(s)
Add \ before , ( and ).
-
- (Object) escapetext(s)
Format a text string.
-
- (Object) Footer
(also: #footer)
This method is used to render the page footer.
-
- (Object) freadint(f)
Read a 4-byte integer from file.
-
- (Object) GetBreakMargin
(also: #get_break_margin)
Returns the page break margin.
-
- (Object) getfontpath(file)
Return fonts path.
-
- (Object) getImageFilename(attrname)
Convert to accessible file path.
-
- (Object) GetImageScale
(also: #get_image_scale)
Returns the image scale.
-
- (Object) GetPageHeight
(also: #get_page_height)
Returns the page height in units.
-
- (Object) GetPageWidth
(also: #get_page_width)
Returns the page width in units.
-
- (Object) GetPDFData
Returns the PDF data.
-
- (Object) GetScaleFactor
(also: #get_scale_factor)
Returns the scale factor (number of points in user unit).
-
- (Object) GetStringWidth(s)
(also: #get_string_width)
Returns the length of a string in user unit.
-
- (Object) GetX
(also: #get_x)
Returns the abscissa of the current position.
-
- (Object) GetY
(also: #get_y)
Returns the ordinate of the current position.
-
- (Object) Header
(also: #header)
This method is used to render the page header.
-
- (Object) Image(file, x, y, w = 0, h = 0, type = '', link = nil)
(also: #image)
Puts an image in the page.
- - (Object) imageToPNG(file)
-
- (TCPDF) initialize(orientation = 'P', unit = 'mm', format = 'A4', unicode = true, encoding = "UTF-8")
constructor
This is the class constructor.
-
- (Object) Line(x1, y1, x2, y2)
(also: #line)
Draws a line between two points.
-
- (Object) Link(x, y, w, h, link)
(also: #link)
Puts a link on a rectangular area of the page.
-
- (Object) Ln(h = '')
(also: #ln)
Performs a line break.
- - (Object) logger
-
- (Object) MultiCell(w, h, txt, border = 0, align = 'J', fill = 0, ln = 1)
(also: #multi_cell)
This method allows printing text with line breaks.
-
- (Object) newobj
Begin a new object.
-
- (Object) Open
This method begins the generation of the PDF document.
-
- (Object) openHTMLTagCalc(tag, attrs)
Calculate opening tags.
-
- (Object) openHTMLTagHandler(tag, attrs, fill = 0)
Process opening tags.
-
- (Object) out(s)
Add a line to the document.
-
- (Object) Output(name = '', dest = '')
(also: #output)
Send the document to a given destination: string, local file or browser.
-
- (Object) PageNo
(also: #page_no)
Returns the current page number.
-
- (Object) parsejpg(file)
Extract info from a JPEG file.
-
- (Object) parsepng(file)
Extract info from a PNG file.
-
- (Object) pixelsToMillimeters(px)
Converts pixels to millimeters in 72 dpi.
-
- (Object) putcatalog
putcatalog.
-
- (Object) putfonts
Adds fonts putfonts.
-
- (Object) putheader
putheader.
-
- (Object) putimages
putimages.
-
- (Object) putinfo
putinfo.
-
- (Object) putpages
putpages.
-
- (Object) putresourcedict
putresourcedict.
-
- (Object) putresources
putresources.
- - (Object) putstream(s)
-
- (Object) puttrailer
puttrailer.
-
- (Object) puttruetypeunicode(font)
Adds unicode fonts.
- - (Object) putType0(font)
-
- (Object) putxobjectdict
putxobjectdict.
-
- (Object) Rect(x, y, w, h, style = '')
(also: #rect)
Outputs a rectangle.
-
- (Object) Rotate(angle, x = "", y = "")
(also: #rotate)
Rotate object.
-
- (Object) SetAuthor(author)
(also: #set_author)
Defines the author of the document.
-
- (Object) SetAutoPageBreak(auto, margin = 0)
(also: #set_auto_page_break)
Enables or disables the automatic page breaking mode.
- - (Object) SetBarcode(bc = "")
-
- (Object) SetCmykFillColor(c, m, y, k, storeprev = false)
(also: #set_cmyk_fill_color)
This hasn't been ported from tcpdf, it's a variation on SetTextColor for setting cmyk colors.
-
- (Object) SetCmykTextColor(c, m, y, k, storeprev = false)
(also: #set_cmyk_text_color)
This hasn't been ported from tcpdf, it's a variation on SetTextColor for setting cmyk colors.
-
- (Object) SetCompression(compress)
(also: #set_compression)
Activates or deactivates page compression.
-
- (Object) SetCreator(creator)
(also: #set_creator)
Defines the creator of the document.
-
- (Object) SetDisplayMode(zoom, layout = 'continuous')
(also: #set_display_mode)
Defines the way the document is to be displayed by the viewer.
-
- (Object) SetDrawColor(r, g = -1,, b = -1))
(also: #set_draw_color)
Defines the color used for all drawing operations (lines, rectangles and cell borders).
-
- (Object) SetFillColor(r, g = -1,, b = -1,, storeprev = false)
(also: #set_fill_color)
Defines the color used for all filling operations (filled rectangles and cell backgrounds).
-
- (Object) SetFont(family, style = '', size = 0)
(also: #set_font)
Sets the font used to print character strings.
-
- (Object) SetFontSize(size)
(also: #set_font_size)
Defines the size of the current font.
- - (Object) SetFooterFont(font) (also: #set_footer_font)
-
- (Object) SetFooterMargin(fm = 10)
(also: #set_footer_margin)
(minimum distance between footer and bottom page margin).
- - (Object) SetHeaderData(ln = "", lw = 0, ht = "", hs = "") (also: #set_header_data)
- - (Object) SetHeaderFont(font) (also: #set_header_font)
-
- (Object) SetHeaderMargin(hm = 10)
(also: #set_header_margin)
(minimum distance between header and top page margin).
-
- (Object) SetImageScale(scale)
(also: #set_image_scale)
Set the image scale.
-
- (Object) SetKeywords(keywords)
(also: #set_keywords)
Associates keywords with the document, generally in the form 'keyword1 keyword2 …'.
- - (Object) SetLanguageArray(language) (also: #set_language_array)
-
- (Object) SetLeftMargin(margin)
(also: #set_left_margin)
Defines the left margin.
-
- (Object) SetLineWidth(width)
(also: #set_line_width)
Defines the line width.
-
- (Object) SetLink(link, y = 0, page = -1))
(also: #set_link)
Defines the page and position a link points to.
-
- (Object) SetMargins(left, top, right = -1))
(also: #set_margins)
Defines the left, top and right margins.
- - (Object) SetPrintFooter(val = true) (also: #set_print_footer)
- - (Object) SetPrintHeader(val = true) (also: #set_print_header)
-
- (Object) SetRightMargin(margin)
(also: #set_right_margin)
Defines the right margin.
-
- (Object) SetStyle(tag, enable)
Sets font style.
-
- (Object) SetSubject(subject)
(also: #set_subject)
Defines the subject of the document.
-
- (Object) SetTextColor(r, g = -1,, b = -1,, storeprev = false)
(also: #set_text_color)
Defines the color used for text.
-
- (Object) SetTitle(title)
(also: #set_title)
Defines the title of the document.
-
- (Object) SetTopMargin(margin)
(also: #set_top_margin)
Defines the top margin.
-
- (Object) SetX(x)
(also: #set_x)
Defines the abscissa of the current position.
-
- (Object) SetXY(x, y)
(also: #set_xy)
Defines the abscissa and ordinate of the current position.
-
- (Object) SetY(y)
(also: #set_y)
Moves the current abscissa back to the left margin and sets the ordinate.
-
- (Object) StartTransform
(also: #start_transform)
Starts a 2D tranformation saving current graphic state.
-
- (Object) StopTransform
(also: #stop_transform)
Stops a 2D tranformation restoring previous graphic state.
-
- (Object) Text(x, y, txt)
(also: #text)
Prints a character string.
-
- (Object) textstring(s)
Format a text string.
-
- (Object) Transform(tm)
(also: #transform)
Apply graphic transformations.
-
- (Object) unhtmlentities(string)
Reverse function for htmlentities.
-
- (Object) UTF8StringToArray(str)
Converts UTF-8 strings to codepoints array.
-
- (Object) UTF8ToUTF16BE(str, setbom = true)
UTF-16 proceeds as follows.
-
- (Object) Write(h, txt, link = nil, fill = 0)
(also: #write)
This method prints text from the current position.
- - (Object) writeBarcode(x, y, w, h, type, style, font, xres, code)
-
- (Object) writeHTML(html, ln = true, fill = 0, h = 0)
(also: #write_html)
Allows to preserve some HTML formatting.
- - (Object) writeHTMLCell(w, h, x, y, html = '', border = 0, ln = 1, fill = 0) (also: #write_html_cell)
Methods included from RFPDF::Math
#deg2deg, #deg2grad, #deg2rad, #grad2deg, #grad2grad, #grad2rad, #rad2deg, #rad2grad, #rad2rad, #remt
Methods included from RFPDF
Constructor Details
- (TCPDF) initialize(orientation = 'P', unit = 'mm', format = 'A4', unicode = true, encoding = "UTF-8")
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).
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 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 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 212 def initialize(orientation = 'P', unit = 'mm', format = 'A4', unicode = true, encoding = "UTF-8") # 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"); # } #Some checks dochecks(); #Initialization of properties @barcode ||= false @buffer ||= '' @diffs ||= [] @color_flag ||= false @default_table_columns ||= 4 @table_columns ||= 0 @max_table_columns ||= [] @tr_id ||= 0 @max_td_page ||= [] @max_td_y ||= [] @t_columns ||= 0 @default_font ||= "FreeSans" if unicode @default_font ||= "Helvetica" @draw_color ||= '0 G' @encoding ||= "UTF-8" @fill_color ||= '0 g' @fonts ||= {} @font_family ||= '' @font_files ||= {} @font_style ||= '' @font_size ||= 12 @font_size_pt ||= 12 @header_width ||= 0 @header_logo ||= "" @header_logo_width ||= 30 @header_title ||= "" @header_string ||= "" @images ||= {} @img_scale ||= 1 @in_footer ||= false @is_unicode = unicode @lasth ||= 0 @links ||= [] @list_ordered ||= [] @list_count ||= [] @li_spacer ||= "" @li_count ||= 0 @spacer ||= "" @quote_count ||= 0 @prevquote_count ||= 0 @quote_top ||= [] @quote_page ||= [] @n ||= 2 @offsets ||= [] @orientation_changes ||= [] @page ||= 0 @page_links ||= {} @pages ||= [] @pdf_version ||= "1.3" @prevfill_color ||= [255,255,255] @prevtext_color ||= [0,0,0] @print_header ||= false @print_footer ||= false @state ||= 0 @tableborder ||= 0 @tdbegin ||= false @tdtext ||= '' @tdwidth ||= 0 @tdheight ||= 0 @tdalign ||= "L" @tdfill ||= 0 @tempfontsize ||= 10 @text_color ||= '0 g' @underline ||= false @deleted ||= false @ws ||= 0 #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'} #Scale factor case unit.downcase when 'pt' ; @k=1 when 'mm' ; @k=72/25.4 when 'cm' ; @k=72/2.54 when 'in' ; @k=72 else Error("Incorrect unit: #{unit}") end #Page format if format.is_a?(String) # 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' ; format = [4767.87,6740.79] when '2A0' ; format = [3370.39,4767.87] when 'A0' ; format = [2383.94,3370.39] when 'A1' ; format = [1683.78,2383.94] when 'A2' ; format = [1190.55,1683.78] when 'A3' ; format = [841.89,1190.55] when 'A4' ; format = [595.28,841.89] # ; default when 'A5' ; format = [419.53,595.28] when 'A6' ; format = [297.64,419.53] when 'A7' ; format = [209.76,297.64] when 'A8' ; format = [147.40,209.76] when 'A9' ; format = [104.88,147.40] when 'A10' ; format = [73.70,104.88] when 'B0' ; format = [2834.65,4008.19] when 'B1' ; format = [2004.09,2834.65] when 'B2' ; format = [1417.32,2004.09] when 'B3' ; format = [1000.63,1417.32] when 'B4' ; format = [708.66,1000.63] when 'B5' ; format = [498.90,708.66] when 'B6' ; format = [354.33,498.90] when 'B7' ; format = [249.45,354.33] when 'B8' ; format = [175.75,249.45] when 'B9' ; format = [124.72,175.75] when 'B10' ; format = [87.87,124.72] when 'C0' ; format = [2599.37,3676.54] when 'C1' ; format = [1836.85,2599.37] when 'C2' ; format = [1298.27,1836.85] when 'C3' ; format = [918.43,1298.27] when 'C4' ; format = [649.13,918.43] when 'C5' ; format = [459.21,649.13] when 'C6' ; format = [323.15,459.21] when 'C7' ; format = [229.61,323.15] when 'C8' ; format = [161.57,229.61] when 'C9' ; format = [113.39,161.57] when 'C10' ; format = [79.37,113.39] when 'RA0' ; format = [2437.80,3458.27] when 'RA1' ; format = [1729.13,2437.80] when 'RA2' ; format = [1218.90,1729.13] when 'RA3' ; format = [864.57,1218.90] when 'RA4' ; format = [609.45,864.57] when 'SRA0' ; format = [2551.18,3628.35] when 'SRA1' ; format = [1814.17,2551.18] when 'SRA2' ; format = [1275.59,1814.17] when 'SRA3' ; format = [907.09,1275.59] when 'SRA4' ; format = [637.80,907.09] when 'LETTER' ; format = [612.00,792.00] when 'LEGAL' ; format = [612.00,1008.00] when 'EXECUTIVE' ; format = [521.86,756.00] when 'FOLIO' ; format = [612.00,936.00] #else then Error("Unknown page format: #{format}" end @fw_pt = format[0] @fh_pt = format[1] else @fw_pt = format[0]*@k @fh_pt = format[1]*@k end @fw = @fw_pt/@k @fh = @fh_pt/@k #Page orientation orientation = orientation.downcase if orientation == 'p' or orientation == 'portrait' @def_orientation = 'P' @w_pt = @fw_pt @h_pt = @fh_pt elsif orientation == 'l' or orientation == 'landscape' @def_orientation = 'L' @w_pt = @fh_pt @h_pt = @fw_pt else Error("Incorrect orientation: #{orientation}") end @fw = @w_pt/@k @fh = @h_pt/@k @cur_orientation = @def_orientation @w = @w_pt/@k @h = @h_pt/@k #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.567 / @k #Automatic page break SetAutoPageBreak(true, 2 * margin) #Full width display mode SetDisplayMode('fullwidth') #Compression SetCompression(true) #Set default PDF version number @pdf_version = "1.3" @encoding = encoding @b = 0 @i = 0 @u = 0 @href = '' @fontlist = ["arial", "times", "courier", "helvetica", "symbol"] @issetfont = false @issetcolor = false SetFillColor(200, 200, 200, true) SetTextColor(0, 0, 0, true) end |
Instance Attribute Details
- (Object) barcode
Returns the value of attribute barcode
97 98 99 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 97 def @barcode end |
- (Object) buffer
Returns the value of attribute buffer
99 100 101 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 99 def buffer @buffer end |
- (Object) color_flag
Returns the value of attribute color_flag
103 104 105 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 103 def color_flag @color_flag end |
- (Object) default_font
Returns the value of attribute default_font
109 110 111 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 109 def default_font @default_font end |
- (Object) default_table_columns
Returns the value of attribute default_table_columns
105 106 107 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 105 def default_table_columns @default_table_columns end |
- (Object) diffs
Returns the value of attribute diffs
101 102 103 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 101 def diffs @diffs end |
- (Object) draw_color
Returns the value of attribute draw_color
111 112 113 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 111 def draw_color @draw_color end |
- (Object) encoding
Returns the value of attribute encoding
113 114 115 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 113 def encoding @encoding end |
- (Object) fill_color
Returns the value of attribute fill_color
115 116 117 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 115 def fill_color @fill_color end |
- (Object) font_family
Returns the value of attribute font_family
119 120 121 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 119 def font_family @font_family end |
- (Object) font_files
Returns the value of attribute font_files
121 122 123 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 121 def font_files @font_files end |
- (Object) font_size_pt
Returns the value of attribute font_size_pt
127 128 129 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 127 def font_size_pt @font_size_pt end |
- (Object) font_style
Returns the value of attribute font_style
125 126 127 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 125 def font_style @font_style end |
- (Object) fonts
Returns the value of attribute fonts
117 118 119 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 117 def fonts @fonts end |
- (Object) header_logo
Returns the value of attribute header_logo
131 132 133 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 131 def header_logo @header_logo end |
- (Object) header_logo_width
Returns the value of attribute header_logo_width
133 134 135 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 133 def header_logo_width @header_logo_width end |
- (Object) header_string
Returns the value of attribute header_string
137 138 139 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 137 def header_string @header_string end |
- (Object) header_title
Returns the value of attribute header_title
135 136 137 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 135 def header_title @header_title end |
- (Object) header_width
Returns the value of attribute header_width
129 130 131 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 129 def header_width @header_width end |
- (Object) images
Returns the value of attribute images
139 140 141 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 139 def images @images end |
- (Object) img_scale
Returns the value of attribute img_scale
141 142 143 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 141 def img_scale @img_scale end |
- (Object) in_footer
Returns the value of attribute in_footer
143 144 145 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 143 def @in_footer end |
- (Object) is_unicode
Returns the value of attribute is_unicode
145 146 147 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 145 def is_unicode @is_unicode end |
- (Object) lasth
Returns the value of attribute lasth
147 148 149 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 147 def lasth @lasth end |
- (Object) li_spacer
Returns the value of attribute li_spacer
155 156 157 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 155 def li_spacer @li_spacer end |
- (Object) links
Returns the value of attribute links
149 150 151 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 149 def links @links end |
- (Object) list_count
Returns the value of attribute list_count
153 154 155 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 153 def list_count @list_count end |
- (Object) list_ordered
Returns the value of attribute list_ordered
151 152 153 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 151 def list_ordered @list_ordered end |
- (Object) max_table_columns
Returns the value of attribute max_table_columns
107 108 109 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 107 def max_table_columns @max_table_columns end |
- (Object) n
Returns the value of attribute n
157 158 159 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 157 def n @n end |
- (Object) offsets
Returns the value of attribute offsets
159 160 161 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 159 def offsets @offsets end |
- (Object) orientation_changes
Returns the value of attribute orientation_changes
161 162 163 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 161 def orientation_changes @orientation_changes end |
- (Object) page
Returns the value of attribute page
163 164 165 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 163 def page @page end |
- (Object) page_links
Returns the value of attribute page_links
165 166 167 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 165 def page_links @page_links end |
- (Object) pages
Returns the value of attribute pages
167 168 169 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 167 def pages @pages end |
- (Object) pdf_version
Returns the value of attribute pdf_version
169 170 171 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 169 def pdf_version @pdf_version end |
- (Object) prevfill_color
Returns the value of attribute prevfill_color
171 172 173 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 171 def prevfill_color @prevfill_color end |
- (Object) prevtext_color
Returns the value of attribute prevtext_color
173 174 175 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 173 def prevtext_color @prevtext_color end |
- (Object) print_footer
Returns the value of attribute print_footer
177 178 179 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 177 def @print_footer end |
- (Object) print_header
Returns the value of attribute print_header
175 176 177 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 175 def print_header @print_header end |
- (Object) state
Returns the value of attribute state
179 180 181 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 179 def state @state end |
- (Object) tableborder
Returns the value of attribute tableborder
181 182 183 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 181 def tableborder @tableborder end |
- (Object) tdalign
Returns the value of attribute tdalign
189 190 191 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 189 def tdalign @tdalign end |
- (Object) tdbegin
Returns the value of attribute tdbegin
183 184 185 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 183 def tdbegin @tdbegin end |
- (Object) tdfill
Returns the value of attribute tdfill
191 192 193 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 191 def tdfill @tdfill end |
- (Object) tdheight
Returns the value of attribute tdheight
187 188 189 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 187 def tdheight @tdheight end |
- (Object) tdwidth
Returns the value of attribute tdwidth
185 186 187 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 185 def tdwidth @tdwidth end |
- (Object) tempfontsize
Returns the value of attribute tempfontsize
193 194 195 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 193 def tempfontsize @tempfontsize end |
- (Object) text_color
Returns the value of attribute text_color
195 196 197 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 195 def text_color @text_color end |
- (Object) underline
Returns the value of attribute underline
197 198 199 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 197 def underline @underline end |
- (Object) ws
Returns the value of attribute ws
199 200 201 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 199 def ws @ws end |
Instance Method Details
- (Object) AcceptPageBreak 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().<br /> This method is called automatically and should not be called directly by the application.<br /> Example:<br /> The method is overriden in an inherited class in order to obtain a 3 column layout:<br /> <pre> class PDF extends TCPDF { var :col=0;
def SetCol(col) #Move position to a column @col = col; :x=10+:col*65; SetLeftMargin(x); SetX(x); end
def AcceptPageBreak() if (@col<2) #Go to next column SetCol(@col+1); SetY(10); return false; end else #Go back to first column and issue page break SetCol(0); return true; end end }
:pdf=new PDF(); :pdf->Open(); :pdf->AddPage(); :pdf->SetFont('Arial','',12); for(i=1;:i<=300;:i++)
:pdf->Cell(0,5,"Line :i",0,1);
} :pdf->Output(); </pre>
1655 1656 1657 1658 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1655 def AcceptPageBreak() #Accept automatic page break or not return @auto_page_break; end |
- (Object) AddFont(family, style = '', file = '') Also known as: add_font
Imports a TrueType or Type1 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. Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]. Example:<br /> <pre> :pdf->AddFont('Comic','I'); # is equivalent to: :pdf->AddFont('Comic','I','comici.rb'); </pre>
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 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1320 def AddFont(family, style='', file='') if (family.empty?) return; end #Add a TrueType or Type1 font family = family.downcase if ((!@is_unicode) and (family == 'arial')) family = 'helvetica'; end style=style.upcase style=style.gsub('U',''); style=style.gsub('D',''); if (style == 'IB') style = 'BI'; end fontkey = family + style; # check if the font has been already added if !@fonts[fontkey].nil? return; end if (file=='') file = family.gsub(' ', '') + style.downcase + '.rb'; end font_file_name = getfontpath(file) if (font_file_name.nil?) # try to load the basic file without styles file = family.gsub(' ', '') + '.rb'; font_file_name = getfontpath(file) end if font_file_name.nil? Error("Could not find font #{file}.") end require(getfontpath(file)) font_desc = TCPDFFontDescriptor.font(file) if (font_desc[:name].nil? and @@fpdf_charwidths.nil?) Error('Could not include font definition file'); end i = @fonts.length+1; if (@is_unicode) @fonts[fontkey] = {'i' => i, 'type' => font_desc[:type], 'name' => font_desc[:name], 'desc' => font_desc[:desc], 'up' => font_desc[:up], 'ut' => font_desc[:ut], 'cw' => font_desc[:cw], 'enc' => font_desc[:enc], 'file' => font_desc[:file], 'ctg' => font_desc[:ctg], 'cMap' => font_desc[:cMap], 'registry' => font_desc[:registry]} @@fpdf_charwidths[fontkey] = font_desc[:cw]; else @fonts[fontkey]={'i' => i, 'type'=>'core', 'name'=>@core_fonts[fontkey], 'up'=>-100, 'ut'=>50, 'cw' => font_desc[:cw]} @@fpdf_charwidths[fontkey] = font_desc[:cw]; end 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 @fonts[fontkey]['diff'] = d; end if (font_desc[:file] and font_desc[:file].length > 0) if (font_desc[:type] == "TrueType") or (font_desc[:type] == "TrueTypeUnicode") @font_files[font_desc[:file]] = {'length1' => font_desc[:originalsize]} else @font_files[font_desc[:file]] = {'length1' => font_desc[:size1], 'length2' => font_desc[:size2]} end end end |
- (Object) addHtmlLink(url, name, fill = 0)
Output anchor link.
4297 4298 4299 4300 4301 4302 4303 4304 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 4297 def addHtmlLink(url, name, fill=0) #Put a hyperlink SetTextColor(0, 0, 255); SetStyle('u', true); Write(@lasth, name, url, fill); SetStyle('u', false); SetTextColor(0); end |
- (Object) AddLink 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.<br /> The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
1543 1544 1545 1546 1547 1548 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1543 def AddLink() #Create a new internal link n=@links.length+1; @links[n]=[0,0]; return n; end |
- (Object) AddPage(orientation = '') 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. Then the page is added, the current position set to the top-left corner according to the left and top margins, and Header() is called to display the header. The font which was set before calling is automatically restored. There is no need to call SetFont() again if you want to continue with the same font. The same is true for colors and line width. The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 752 def AddPage(orientation='') #Start a new page if (@state==0) Open(); end family=@font_family; style=@font_style + (@underline ? 'U' : '') + (@deleted ? 'D' : ''); size=@font_size_pt; lw=@line_width; dc=@draw_color; fc=@fill_color; tc=@text_color; cf=@color_flag; if (@page>0) #Page footer @in_footer=true; Footer(); @in_footer=false; #Close page endpage(); end #Start new page beginpage(orientation); #Set line cap style to square out('2 J'); #Set line width @line_width = lw; out(sprintf('%.2f w', lw*@k)); #Set font if (family) SetFont(family, style, size); end #Set colors @draw_color = dc; if (dc!='0 G') out(dc); end @fill_color = fc; if (fc!='0 g') out(fc); end @text_color = tc; @color_flag = cf; #Page header Header(); #Restore line width if (@line_width != lw) @line_width = lw; out(sprintf('%.2f w', lw*@k)); end #Restore font if (family) SetFont(family, style, size); end #Restore colors if (@draw_color != dc) @draw_color = dc; out(dc); end if (@fill_color != fc) @fill_color = fc; out(fc); end @text_color = tc; @color_flag = cf; end |
- (Object) AliasNbPages(alias_nb = '{nb}') Also known as: alias_nb_pages
Defines an alias for the total number of pages. It will be substituted as the document is closed.<br /> Example:<br /> <pre> class PDF extends TCPDF { def Footer() #Go to 1.5 cm from bottom SetY(-15); #Select Arial italic 8 SetFont('Arial','I',8); #Print current and total page numbers Cell(0,10,'Page '.PageNo().'/nb',0,0,'C'); end } :pdf=new PDF(); :pdf->alias_nb_pages(); </pre>
690 691 692 693 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 690 def AliasNbPages(alias_nb ='{nb}') #Define an alias for total number of pages @alias_nb_pages = escapetext(alias_nb) end |
- (Object) begindoc
Start document
2368 2369 2370 2371 2372 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2368 def begindoc() #Start document @state=1; out('%PDF-1.3'); end |
- (Object) beginpage(orientation)
beginpage
2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2803 def beginpage(orientation) @page += 1; @pages[@page]=''; @state=2; @x=@l_margin; @y=@t_margin; @font_family=''; #Page orientation if (orientation.empty?) orientation=@def_orientation; else orientation.upcase! if (orientation!=@def_orientation) @orientation_changes[@page]=true; end end if (orientation!=@cur_orientation) #Change orientation if (orientation=='P') @w_pt=@fw_pt; @h_pt=@fh_pt; @w=@fw; @h=@fh; else @w_pt=@fh_pt; @h_pt=@fw_pt; @w=@fh; @h=@fw; end @page_break_trigger=@h-@b_margin; @cur_orientation = orientation; end end |
- (Boolean) BreakThePage?(h) Also known as: break_the_page?
1661 1662 1663 1664 1665 1666 1667 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1661 def BreakThePage?(h) if ((@y + h) > @page_break_trigger and !@in_footer and AcceptPageBreak()) true else false end end |
- (Object) Cell(w, h = 0, txt = '', border = 0, ln = 0, align = '', fill = 0, link = nil) 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.<br /> If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1684 def Cell(w, h=0, txt='', border=0, ln=0, align='', fill=0, link=nil) #Output a cell k=@k; if ((@y + h) > @page_break_trigger and !@in_footer and AcceptPageBreak()) #Automatic page break if @pages[@page+1].nil? x = @x; ws = @ws; if (ws > 0) @ws = 0; out('0 Tw'); end AddPage(@cur_orientation); @x = x; if (ws > 0) @ws = ws; out(sprintf('%.3f Tw', ws * k)); end else @page += 1; @y=@t_margin; end end if (w == 0) w = @w - @r_margin - @x; end s = ''; if ((fill.to_i == 1) or (border.to_i == 1)) if (fill.to_i == 1) op = (border.to_i == 1) ? 'B' : 'f'; else op = 'S'; end s = sprintf('%.2f %.2f %.2f %.2f re %s ', @x * k, (@h - @y) * k, w * k, -h * k, op); end if (border.is_a?(String)) x=@x; y=@y; if (border.include?('L')) s<<sprintf('%.2f %.2f m %.2f %.2f l S ', x*k,(@h-y)*k, x*k,(@h-(y+h))*k); end if (border.include?('T')) s<<sprintf('%.2f %.2f m %.2f %.2f l S ', x*k,(@h-y)*k,(x+w)*k,(@h-y)*k); end if (border.include?('R')) s<<sprintf('%.2f %.2f m %.2f %.2f l S ',(x+w)*k,(@h-y)*k,(x+w)*k,(@h-(y+h))*k); end if (border.include?('B')) s<<sprintf('%.2f %.2f m %.2f %.2f l S ', x*k,(@h-(y+h))*k,(x+w)*k,(@h-(y+h))*k); end end if (txt != '') width = GetStringWidth(txt); if (align == 'R' || align == 'right') dx = w - @c_margin - width; elsif (align=='C' || align == 'center') dx = (w - width)/2; else dx = @c_margin; end if (@color_flag) s << 'q ' + @text_color + ' '; end txt2 = escapetext(txt); s<<sprintf('BT %.2f %.2f Td (%s) Tj ET', (@x + dx) * k, (@h - (@y + 0.5 * h + 0.3 * @font_size)) * k, txt2); if (@underline) s<<' ' + dolinetxt(@x + dx, @y + 0.5 * h + 0.3 * @font_size, txt); end if (@deleted) s<<' ' + dolinetxt(@x + dx, @y + 0.3 * h + 0.2 * @font_size, txt); end if (@color_flag) s<<' Q'; end if link && !link.empty? Link(@x + dx, @y + 0.5 * h - 0.5 * @font_size, width, @font_size, link); end end if (s) out(s); end @lasth = h; if (ln.to_i>0) # Go to next line @y += h; if (ln == 1) @x = @l_margin; end else @x += w; end end |
- (Object) checkTableBlockingCellPosition(table, tr_id, td_id)
Check html table tag position.
3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3681 def checkTableBlockingCellPosition(table, tr_id, td_id ) 0.upto(tr_id) do |j| 0.upto(@t_cells[table][j].size - 1) do |i| if @t_cells[table][j][i]['i0'] <= td_id and td_id <= @t_cells[table][j][i]['i1'] if @t_cells[table][j][i]['j0'] <= tr_id and tr_id <= @t_cells[table][j][i]['j1'] return @t_cells[table][j][i]['i1'] - td_id + 1; end end end end return 0; end |
- (Object) Circle(mid_x, mid_y, radius, style = '') Also known as: circle
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1217 def Circle(mid_x, mid_y, radius, style='') mid_y = (@h-mid_y)*@k out(sprintf("q\n")) # postscript content in pdf # init line type etc. with /GSD gs G g (grey) RG rg (RGB) w=line witdh etc. out(sprintf("1 j\n")) # line join # translate ("move") circle to mid_y, mid_y out(sprintf("1 0 0 1 %f %f cm", mid_x, mid_y)) kappa = 0.5522847498307933984022516322796 # Quadrant 1 x_s = 0.0 # 12 o'clock y_s = 0.0 + radius x_e = 0.0 + radius # 3 o'clock y_e = 0.0 out(sprintf("%f %f m\n", x_s, y_s)) # move to 12 o'clock # cubic bezier control point 1, start height and kappa * radius to the right bx_e1 = x_s + (radius * kappa) by_e1 = y_s # cubic bezier control point 2, end and kappa * radius above bx_e2 = x_e by_e2 = y_e + (radius * kappa) # draw cubic bezier from current point to x_e/y_e with bx_e1/by_e1 and bx_e2/by_e2 as bezier control points out(sprintf("%f %f %f %f %f %f c\n", bx_e1, by_e1, bx_e2, by_e2, x_e, y_e)) # Quadrant 2 x_s = x_e y_s = y_e # 3 o'clock x_e = 0.0 y_e = 0.0 - radius # 6 o'clock bx_e1 = x_s # cubic bezier point 1 by_e1 = y_s - (radius * kappa) bx_e2 = x_e + (radius * kappa) # cubic bezier point 2 by_e2 = y_e out(sprintf("%f %f %f %f %f %f c\n", bx_e1, by_e1, bx_e2, by_e2, x_e, y_e)) # Quadrant 3 x_s = x_e y_s = y_e # 6 o'clock x_e = 0.0 - radius y_e = 0.0 # 9 o'clock bx_e1 = x_s - (radius * kappa) # cubic bezier point 1 by_e1 = y_s bx_e2 = x_e # cubic bezier point 2 by_e2 = y_e - (radius * kappa) out(sprintf("%f %f %f %f %f %f c\n", bx_e1, by_e1, bx_e2, by_e2, x_e, y_e)) # Quadrant 4 x_s = x_e y_s = y_e # 9 o'clock x_e = 0.0 y_e = 0.0 + radius # 12 o'clock bx_e1 = x_s # cubic bezier point 1 by_e1 = y_s + (radius * kappa) bx_e2 = x_e - (radius * kappa) # cubic bezier point 2 by_e2 = y_e out(sprintf("%f %f %f %f %f %f c\n", bx_e1, by_e1, bx_e2, by_e2, x_e, y_e)) if style=='F' op='f' elsif style=='FD' or style=='DF' op='b' else op='s' end out(sprintf("#{op}\n")) # stroke circle, do not fill and close path # for filling etc. b, b*, f, f* out(sprintf("Q\n")) # finish postscript in PDF end |
- (Object) Close
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.
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 725 def Close() #Terminate document if (@state==3) return; end if (@page==0) AddPage(); end #Page footer @in_footer=true; Footer(); @in_footer=false; #Close page endpage(); #Close document enddoc(); end |
- (Object) closedHTMLTagCalc(tag)
Calculate closing tags.
3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3789 def closedHTMLTagCalc(tag) #Closing tag case (tag) when 'table' if @max_table_columns[@table_id] < @t_columns @max_table_columns[@table_id] = @t_columns; end @table_id += 1; @t_cells.push [] end end |
- (Object) closedHTMLTagHandler(tag)
Process closing tags.
4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 4076 def closedHTMLTagHandler(tag) #Closing tag case (tag) when 'pre' @pre_state = false; @l_margin -= 5; @r_margin -= 5; @x = @l_margin; Ln(); when 'td','th' base_page = @page; base_x = @x; base_y = @y; MultiCell(@tdwidth, @tdheight, unhtmlentities(@tdtext.strip), @tableborder, @tdalign, @tdfill, 1); tr_end = @t_cells[@table_id][@tr_id][@td_id]['j1'] + 1; if @max_td_page[tr_end].nil? or (@max_td_page[tr_end] < @page) @max_td_page[tr_end] = @page @max_td_y[tr_end] = @y elsif (@max_td_page[tr_end] == @page) @max_td_y[tr_end] = @y if @max_td_y[tr_end].nil? or (@max_td_y[tr_end] < @y) end @page = base_page; @x = base_x + @tdwidth; @y = base_y; @tdtext = ''; @tdbegin = false; @tdwidth = 0; @tdheight = 0; @tdalign = "L"; SetStyle('b', false); @tdfill = 0; SetFillColor(@prevfill_color[0], @prevfill_color[1], @prevfill_color[2]); when 'tr' @y = @max_td_y[@tr_id + 1]; @x = @l_margin; @page = @max_td_page[@tr_id + 1]; when 'table' # Write Table Line width = (@w - @l_margin - @r_margin) / @table_columns; 0.upto(@t_cells[@table_id].size - 1) do |j| 0.upto(@t_cells[@table_id][j].size - 1) do |i| @page = @max_td_page[j] i0=@t_cells[@table_id][j][i]['i0']; j0=@t_cells[@table_id][j][i]['j0']; i1=@t_cells[@table_id][j][i]['i1']; j1=@t_cells[@table_id][j][i]['j1']; Line(@l_margin + width * i0, @max_td_y[j0], @l_margin + width * (i1+1), @max_td_y[j0]) # top if ( @page == @max_td_page[j1 + 1]) Line(@l_margin + width * i0, @max_td_y[j0], @l_margin + width * i0, @max_td_y[j1+1]) # left Line(@l_margin + width * (i1+1), @max_td_y[j0], @l_margin + width * (i1+1), @max_td_y[j1+1]) # right else Line(@l_margin + width * i0, @max_td_y[j0], @l_margin + width * i0, @page_break_trigger) # left Line(@l_margin + width * (i1+1), @max_td_y[j0], @l_margin + width * (i1+1), @page_break_trigger) # right @page += 1; while @page < @max_td_page[j1 + 1] Line(@l_margin + width * i0, @t_margin, @l_margin + width * i0, @page_break_trigger) # left Line(@l_margin + width * (i1+1), @t_margin, @l_margin + width * (i1+1), @page_break_trigger) # right @page += 1; end Line(@l_margin + width * i0, @t_margin, @l_margin + width * i0, @max_td_y[j1+1]) # left Line(@l_margin + width * (i1+1), @t_margin, @l_margin + width * (i1+1), @max_td_y[j1+1]) # right end Line(@l_margin + width * i0, @max_td_y[j1+1], @l_margin + width * (i1+1), @max_td_y[j1+1]) # bottom end end @l_margin -= 5; @r_margin -= 5; @tableborder=0; @table_id += 1; when 'strong' SetStyle('b', false); when 'em' SetStyle('i', false); when 'ins' SetStyle('u', false); when 'del' SetStyle('d', false); when 'b', 'i', 'u' SetStyle(tag, false); when 'a' @href = nil; when 'p' Ln(); when 'sup' currentfont_size = @font_size; SetFontSize(@tempfontsize); @tempfontsize = @font_size_pt; SetXY(GetX(), GetY() - ((currentfont_size - @font_size)*(@@k_small_ratio))); when 'sub' currentfont_size = @font_size; SetFontSize(@tempfontsize); @tempfontsize = @font_size_pt; SetXY(GetX(), GetY() + ((currentfont_size - @font_size)*(@@k_small_ratio))); when 'small' currentfont_size = @font_size; SetFontSize(@tempfontsize); @tempfontsize = @font_size_pt; SetXY(GetX(), GetY() - ((@font_size - currentfont_size)/3)); when 'font' if (@issetcolor == true) SetTextColor(@prevtext_color[0], @prevtext_color[1], @prevtext_color[2]); end if (@issetfont) @font_family = @prevfont_family; @font_style = @prevfont_style; SetFont(@font_family); @issetfont = false; end currentfont_size = @font_size; SetFontSize(@tempfontsize); @tempfontsize = @font_size_pt; #@text_color = @prevtext_color; @lasth = @font_size * @@k_cell_height_ratio; when 'blockquote' @quote_count -= 1 if (@quote_page[@quote_count] == @page) Line(@l_margin - 1, @quote_top[@quote_count], @l_margin - 1, @y) # quoto line else cur_page = @page; cur_y = @y; @page = @quote_page[@quote_count]; if (@quote_top[@quote_count] < @page_break_trigger) Line(@l_margin - 1, @quote_top[@quote_count], @l_margin - 1, @page_break_trigger) # quoto line end @page += 1; while @page < cur_page Line(@l_margin - 1, @t_margin, @l_margin - 1, @page_break_trigger) # quoto line @page += 1; end @y = cur_y; Line(@l_margin - 1, @t_margin, @l_margin - 1, @y) # quoto line end if (@quote_count <= 0) SetStyle('i', false); @l_margin -= 5; else @l_margin -= 5 / 2; end @x = @l_margin; Ln() if @quote_count == 0 when 'ul', 'ol' @li_count -= 1 if @li_state == true Ln(); @li_state = false; end when 'li' @li_spacer = ""; if @li_state == true Ln(); @li_state = false; end when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' SetFontSize(@tempfontsize); @tempfontsize = @font_size_pt; SetStyle('b', false); Ln(); @lasth = @font_size * @@k_cell_height_ratio; if tag == 'h1' or tag == 'h2' or tag == 'h3' or tag == 'h4' margin = 1; hrWidth = @w - @l_margin - @r_margin - margin; if tag == 'h1' or tag == 'h2' SetLineWidth(0.2); else SetLineWidth(0.1); end Line(@x + margin, @y, @x + hrWidth, @y); end end end |
- (Object) convertColorHexToDec(color = "#000000")
Returns an associative array (keys: R,G,B) from a hex html code (e.g. #3FE5AA).
4313 4314 4315 4316 4317 4318 4319 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 4313 def convertColorHexToDec(color = "#000000") tbl_color = {} tbl_color['R'] = color[1,2].hex.to_i; tbl_color['G'] = color[3,2].hex.to_i; tbl_color['B'] = color[5,2].hex.to_i; return tbl_color; end |
- (Object) dochecks
Check for locale-related bug
2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2332 def dochecks() #Check for locale-related bug if (1.1==1) Error('Don\'t alter the locale before including class file'); end #Check for decimal separator if (sprintf('%.1f',1.0)!='1.0') setlocale(LC_NUMERIC,'C'); end end |
- (Object) dolinetxt(x, y, txt)
Underline and Deleted text
2859 2860 2861 2862 2863 2864 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2859 def dolinetxt(x, y, txt) up = @current_font['up']; ut = @current_font['ut']; w = GetStringWidth(txt) + @ws * txt.count(' '); sprintf('%.2f %.2f %.2f %.2f re f', x * @k, (@h - (y - up / 1000.0 * @font_size)) * @k, w * @k, -ut / 1000.0 * @font_size_pt); end |
- (Object) enddoc
enddoc
2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2764 def enddoc() putheader(); putpages(); putresources(); #Info newobj(); out('<<'); putinfo(); out('>>'); out('endobj'); #Catalog newobj(); out('<<'); putcatalog(); out('>>'); out('endobj'); #Cross-ref o=@buffer.length; out('xref'); out('0 ' + (@n+1).to_s); out('0000000000 65535 f '); 1.upto(@n) do |i| out(sprintf('%010d 00000 n ',@offsets[i])); end #Trailer out('trailer'); out('<<'); puttrailer(); out('>>'); out('startxref'); out(o); out('%%EOF'); @state=3; end |
- (Object) endpage
End of page contents
2841 2842 2843 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2841 def endpage() @state=1; end |
- (Object) Error(msg) 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
702 703 704 705 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 702 def Error(msg) #Fatal error raise ("TCPDF error: #{msg}") end |
- (Object) escape(s)
Add \ before , ( and )
3035 3036 3037 3038 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3035 def escape(s) # Add \ before \, ( and ) s.gsub('\\','\\\\\\').gsub('(','\\(').gsub(')','\\)').gsub(13.chr, '\r') end |
- (Object) escapetext(s)
Format a text string
3023 3024 3025 3026 3027 3028 3029 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3023 def escapetext(s) if (@is_unicode) #Convert string to UTF-16BE s = UTF8ToUTF16BE(s, false); end return escape(s); end |
- (Object) Footer 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.
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 997 def Footer() if (@print_footer) if (@original_l_margin.nil?) @original_l_margin = @l_margin; end if (@original_r_margin.nil?) @original_r_margin = @r_margin; end #set font SetFont(@footer_font[0], @footer_font[1] , @footer_font[2]); #set style for cell border line_width = 0.3; SetLineWidth(line_width); SetDrawColor(0, 0, 0); = ((@@k_cell_height_ratio * @footer_font[2]) / @k).round; #footer height, was , 2) #get footer y position = @h - @footer_margin - ; #set current position SetXY(@original_l_margin, ); #print document barcode if (@barcode) Ln(); = ((@w - @original_l_margin - @original_r_margin)).round; #max width writeBarcode(@original_l_margin, + line_width, , - line_width, "C128B", false, false, 2, @barcode); end SetXY(@original_l_margin, ); #Print page number Cell(0, , @l['w_page'] + " " + PageNo().to_s + ' / {nb}', 'T', 0, 'R'); end end |
- (Object) freadint(f)
Read a 4-byte integer from file
3001 3002 3003 3004 3005 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3001 def freadint(f) # Read a 4-byte integer from file a = f.read(4).unpack('N') return a[0] end |
- (Object) GetBreakMargin Also known as: get_break_margin
Returns the page break margin.
483 484 485 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 483 def GetBreakMargin() return @b_margin; end |
- (Object) getfontpath(file)
Return fonts path
2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2347 def getfontpath(file) # Is it in the @@font_path? if @@font_path fpath = File.join @@font_path, file if File.exists?(fpath) return fpath end end # Is it in this plugin's font folder? fpath = File.join File.dirname(__FILE__), 'fonts', file if File.exists?(fpath) return fpath end # Could not find it. nil end |
- (Object) getImageFilename(attrname)
Convert to accessible file path
3805 3806 3807 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3805 def getImageFilename( attrname ) nil end |
- (Object) GetImageScale Also known as: get_image_scale
Returns the image scale.
450 451 452 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 450 def GetImageScale() return @img_scale; end |
- (Object) GetPageHeight Also known as: get_page_height
Returns the page height in units.
472 473 474 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 472 def GetPageHeight() return @h; end |
- (Object) GetPageWidth Also known as: get_page_width
Returns the page width in units.
461 462 463 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 461 def GetPageWidth() return @w; end |
- (Object) GetPDFData
Returns the PDF data.
3448 3449 3450 3451 3452 3453 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3448 def GetPDFData() if (@state < 3) Close(); end return @buffer; end |
- (Object) GetScaleFactor Also known as: get_scale_factor
Returns the scale factor (number of points in user unit).
494 495 496 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 494 def GetScaleFactor() return @k; end |
- (Object) GetStringWidth(s) Also known as: get_string_width
Returns the length of a string in user unit. A font must be selected.<br> Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1153 def GetStringWidth(s) #Get width of a string in the current font s = s.to_s; cw = @current_font['cw'] w = 0; if (@is_unicode) unicode = UTF8StringToArray(s); unicode.each do |char| if (!cw[char].nil?) w += cw[char]; # This should not happen. UTF8StringToArray should guarentee the array is ascii values. # elsif (c!cw[char[0]].nil?) # w += cw[char[0]]; # elsif (!cw[char.chr].nil?) # w += cw[char.chr]; elsif (!@current_font['desc']['MissingWidth'].nil?) w += @current_font['desc']['MissingWidth']; # set default size else w += 500; end end else s.each_byte do |c| if cw[c.chr] w += cw[c.chr]; elsif cw[?c.chr] w += cw[?c.chr] end end end return (w * @font_size / 1000.0); end |
- (Object) GetX Also known as: get_x
Returns the abscissa of the current position.
2173 2174 2175 2176 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2173 def GetX() #Get x position return @x; end |
- (Object) GetY Also known as: get_y
Returns the ordinate of the current position.
2201 2202 2203 2204 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2201 def GetY() #Get y position return @y; end |
- (Object) Header 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.
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 945 def Header() if (@print_header) if (@original_l_margin.nil?) @original_l_margin = @l_margin; end if (@original_r_margin.nil?) @original_r_margin = @r_margin; end #set current position SetXY(@original_l_margin, @header_margin); if ((@header_logo) and (@header_logo != @@k_blank_image)) Image(@header_logo, @original_l_margin, @header_margin, @header_logo_width); else @img_rb_y = GetY(); end cell_height = ((@@k_cell_height_ratio * @header_font[2]) / @k).round(2) header_x = @original_l_margin + (@header_logo_width * 1.05); #set left margin for text data cell # header title SetFont(@header_font[0], 'B', @header_font[2] + 1); SetX(header_x); Cell(@header_width, cell_height, @header_title, 0, 1, 'L'); # header string SetFont(@header_font[0], @header_font[1], @header_font[2]); SetX(header_x); MultiCell(@header_width, cell_height, @header_string, 0, 'L', 0); # print an ending header line if (@header_width) #set style for cell border SetLineWidth(0.3); SetDrawColor(0, 0, 0); SetY(1 + (@img_rb_y > GetY() ? @img_rb_y : GetY())); SetX(@original_l_margin); Cell(0, 0, '', 'T', 0, 'C'); end #restore position SetXY(@original_l_margin, @t_margin); end end |
- (Object) Image(file, x, y, w = 0, h = 0, type = '', link = nil) 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:<ul><li>explicit width and height (expressed in user unit)</li><li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li><li>no explicit dimension, in which case the image is put at 72 dpi</li></ul> Supported formats are JPEG and PNG. For JPEG, all flavors are allowed:<ul><li>gray scales</li><li>true colors (24 bits)</li><li>CMYK (32 bits)</li></ul> For PNG, are allowed:<ul><li>gray scales on at most 8 bits (256 levels)</li><li>indexed colors</li><li>true colors (24 bits)</li></ul> but are not supported:<ul><li>Interlacing</li><li>Alpha channel</li></ul> If a transparent color is defined, it will be taken into account (but will be only interpreted by Acrobat 4 and above).<br /> The format can be specified explicitly or inferred from the file extension.<br /> It is possible to put a link on the image.<br /> Remark: if an image is used several times, only one copy will be embedded in the file.<br />
2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2046 def Image(file, x, y, w=0, h=0, type='', link=nil) #Put an image on the page if (@images[file].nil?) #First use of image, get info if (type == '') pos = File::basename(file).rindex('.'); if (pos.nil? or pos == 0) Error('Image file has no extension and no type was specified: ' + file); end pos = file.rindex('.'); type = file[pos+1..-1]; end type.downcase! if (type == 'jpg' or type == 'jpeg') info=parsejpg(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; if (!self.respond_to?(mtd)) Error('Unsupported image type: ' + type); end info=send(mtd, file); end info['i']=@images.length+1; @images[file] = info; else info=@images[file]; end #Automatic width and height calculation if needed if ((w == 0) and (h == 0)) rescale_x = (@w - @r_margin - x) / (info['w'] / (@img_scale * @k)) rescale_x = 1 if rescale_x >= 1 if (y + info['h'] * rescale_x / (@img_scale * @k) > @page_break_trigger and !@in_footer and AcceptPageBreak()) #Automatic page break if @pages[@page+1].nil? ws = @ws; if (ws > 0) @ws = 0; out('0 Tw'); end AddPage(@cur_orientation); if (ws > 0) @ws = ws; out(sprintf('%.3f Tw', ws * @k)); end else @page += 1; end y=@t_margin; end rescale_y = (@page_break_trigger - y) / (info['h'] / (@img_scale * @k)) rescale_y = 1 if rescale_y >= 1 rescale = rescale_y >= rescale_x ? rescale_x : rescale_y #Put image at 72 dpi # 2004-06-14 :: Nicola Asuni, scale factor where added w = info['w'] * rescale / (@img_scale * @k); h = info['h'] * rescale / (@img_scale * @k); elsif (w == 0) w = h * info['w'] / info['h']; elsif (h == 0) h = w * info['h'] / info['w']; end out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q', w*@k, h*@k, x*@k, (@h-(y+h))*@k, info['i'])); if (link) Link(x, y, w, h, link); end #2002-07-31 - Nicola Asuni # set right-bottom corner coordinates @img_rb_x = x + w; @img_rb_y = y + h; end |
- (Object) imageToPNG(file)
2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2896 def imageToPNG(file) return unless Object.const_defined?(:Magick) img = Magick::ImageList.new(file) img.format = 'PNG' # convert to PNG from gif img.opacity = 0 # PNG alpha channel delete #use a temporary file.... tmpFile = Tempfile.new(['', '_' + File::basename(file) + '.png'], @@k_path_cache); tmpFile.binmode tmpFile.print img.to_blob tmpFile ensure tmpFile.close end |
- (Object) Line(x1, y1, x2, y2) Also known as: line
Draws a line between two points.
1211 1212 1213 1214 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1211 def Line(x1, y1, x2, y2) #Draw a line out(sprintf('%.2f %.2f m %.2f %.2f l S', x1 * @k, (@h - y1) * @k, x2 * @k, (@h - y2) * @k)); end |
- (Object) Link(x, y, w, h, link) 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.
1581 1582 1583 1584 1585 1586 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1581 def Link(x, y, w, h, link) #Put a link on the page @page_links ||= Array.new @page_links[@page] ||= Array.new @page_links[@page].push([x * @k, @h_pt - y * @k, w * @k, h*@k, link]); end |
- (Object) Ln(h = '') 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.
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2133 def Ln(h='') #Line feed; default value is last cell height @x=@l_margin; if (h.is_a?(String)) @y += @lasth; else @y += h; end k=@k; if (@y > @page_break_trigger and !@in_footer and AcceptPageBreak()) #Automatic page break if @pages[@page+1].nil? x = @x; ws = @ws; if (ws > 0) @ws = 0; out('0 Tw'); end AddPage(@cur_orientation); @x = x; if (ws > 0) @ws = ws; out(sprintf('%.3f Tw', ws * k)); end else @page += 1; @y=@t_margin; end end end |
- (Object) logger
75 76 77 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 75 def logger Rails.logger end |
- (Object) MultiCell(w, h, txt, border = 0, align = 'J', fill = 0, ln = 1) 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.<br /> Text can be aligned, centered or justified. The cell block can be framed and the background painted.
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1792 def MultiCell(w, h, txt, border=0, align='J', fill=0, ln=1) # save current position prevx = @x; prevy = @y; prevpage = @page; #Output text with automatic or explicit line breaks if (w == 0) w = @w - @r_margin - @x; end wmax = (w - 3 * @c_margin); s = txt.gsub("\r", ''); # remove carriage returns nb = s.length; b=0; if (border) if (border==1) border='LTRB'; b='LRT'; b2='LR'; elsif border.is_a?(String) b2=''; if (border.include?('L')) b2<<'L'; end if (border.include?('R')) b2<<'R'; end b=(border.include?('T')) ? b2 + 'T' : b2; end end sep=-1; to_index=0; from_j=0; l=0; ns=0; nl=1; while to_index < nb #Get next character c = s[to_index]; if c == "\n"[0] #Explicit line break if @ws > 0 @ws = 0 out('0 Tw') end #Ed Moss - change begin end_i = to_index == 0 ? 0 : to_index - 1 # Changed from s[from_j..to_index] to fix bug reported by Hans Allis. from_j = to_index == 0 ? 1 : from_j Cell(w, h, s[from_j..end_i], b, 2, align, fill) #change end to_index += 1 sep=-1 from_j=to_index l=0 ns=0 nl += 1 b = b2 if border and nl==2 next end if (c == " "[0]) sep = to_index; ls = l; ns += 1; end l = GetStringWidth(s[from_j, to_index - from_j]); if (l > wmax) #Automatic line break if (sep == -1) if (to_index == from_j) to_index += 1; end if (@ws > 0) @ws = 0; out('0 Tw'); end Cell(w, h, s[from_j..to_index-1], b, 2, align, fill) # my FPDF version else if (align=='J' || align=='justify' || align=='justified') @ws = (ns>1) ? (wmax-ls)/(ns-1) : 0; out(sprintf('%.3f Tw', @ws * @k)); end Cell(w, h, s[from_j..sep], b, 2, align, fill); to_index = sep + 1; end sep=-1; from_j = to_index; l=0; ns=0; nl += 1; if (border and (nl==2)) b = b2; end else to_index += 1; end end #Last chunk if (@ws>0) @ws=0; out('0 Tw'); end if (border.is_a?(String) and border.include?('B')) b<<'B'; end Cell(w, h, s[from_j, to_index-from_j], b, 2, align, fill); # move cursor to specified position # since 2007-03-03 if (ln == 1) # go to the beginning of the next line @x = @l_margin; elsif (ln == 0) # go to the top-right of the cell @page = prevpage; @y = prevy; @x = prevx + w; elsif (ln == 2) # go to the bottom-left of the cell @x = prevx; end end |
- (Object) newobj
Begin a new object
2849 2850 2851 2852 2853 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2849 def newobj() @n += 1; @offsets[@n]=@buffer.length; out(@n.to_s + ' 0 obj'); end |
- (Object) Open
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
714 715 716 717 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 714 def Open() #Begin document @state = 1 end |
- (Object) openHTMLTagCalc(tag, attrs)
Calculate opening tags.
html table cell array : @t_cells
i0: table cell start position i1: table cell end position j0: table row start position j1: table row end position +------+ |i0,j0 | | i1,j1| +------+ example html: <table> <tr><td></td><td></td><td></td></tr> <tr><td colspan=2></td><td></td></tr> <tr><td rowspan=2></td><td></td><td></td></tr> <tr><td></td><td></td></tr> </table> i: 0 1 2 j+----+----+----+ :|0,0 |1,0 |2,0 | 0| 0,0| 1,0| 2,0| +----+----+----+ |0,1 |2,1 | 1| 1,1| 2,1| +----+----+----+ |0,2 |1,2 |2,2 | 2| | 1,2| 2,2| + +----+----+ | |1,3 |2,3 | 3| 0,3| 1,3| 2,3| +----+----+----+ html table cell array : [[[i0=>0,j0=>0,i1=>0,j1=>0],[i0=>1,j0=>0,i1=>1,j1=>0],[i0=>2,j0=>0,i1=>2,j1=>0]], [[i0=>0,j0=>1,i1=>1,j1=>1],[i0=>2,j0=>1,i1=>2,j1=>1]], [[i0=>0,j0=>2,i1=>0,j1=>3],[i0=>1,j0=>2,i1=>1,j1=>2],[i0=>2,j0=>2,i1=>2,j1=>2]] [[i0=>1,j0=>3,i1=>1,j1=>3],[i0=>2,j0=>3,i1=>2,j1=>3]]]
3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 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 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3742 def openHTMLTagCalc(tag, attrs) #Opening tag case (tag) when 'table' @max_table_columns[@table_id] = 0; @t_columns = 0; @tr_id = -1; when 'tr' if @max_table_columns[@table_id] < @t_columns @max_table_columns[@table_id] = @t_columns; end @t_columns = 0; @tr_id += 1; @td_id = -1; @t_cells[@table_id].push [] when 'td', 'th' @td_id += 1; if attrs['colspan'].nil? or attrs['colspan'] == '' colspan = 1; else colspan = attrs['colspan'].to_i; end if attrs['rowspan'].nil? or attrs['rowspan'] == '' rowspan = 1; else rowspan = attrs['rowspan'].to_i; end i = 0; while true next_i_distance = checkTableBlockingCellPosition(@table_id, @tr_id, @td_id + i); if next_i_distance == 0 @t_cells[@table_id][@tr_id].push "i0"=>@td_id + i, "j0"=>@tr_id, "i1"=>(@td_id + i + colspan - 1), "j1"=>@tr_id + rowspan - 1 break; end i += next_i_distance; end @t_columns += colspan; end end |
- (Object) openHTMLTagHandler(tag, attrs, fill = 0)
Process opening tags.
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 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3816 def openHTMLTagHandler(tag, attrs, fill=0) #Opening tag case (tag) when 'pre' @pre_state = true; @l_margin += 5; @r_margin += 5; @x += 5; when 'table' Ln(); if @default_table_columns < @max_table_columns[@table_id] @table_columns = @max_table_columns[@table_id]; else @table_columns = @default_table_columns; end @l_margin += 5; @r_margin += 5; @x += 5; if attrs['border'].nil? or attrs['border'] == '' @tableborder = 0; else @tableborder = attrs['border']; end @tr_id = -1; @max_td_page[0] = @page; @max_td_y[0] = @y; when 'tr', 'td', 'th' if tag == 'th' SetStyle('b', true); @tdalign = "C"; end if ((!attrs['width'].nil?) and (attrs['width'] != '')) @tdwidth = (attrs['width'].to_i/4); else @tdwidth = ((@w - @l_margin - @r_margin) / @table_columns); end if tag == 'tr' @tr_id += 1; @td_id = -1; else @td_id += 1; @x = @l_margin + @tdwidth * @t_cells[@table_id][@tr_id][@td_id]['i0']; end if attrs['colspan'].nil? or attrs['border'] == '' @colspan = 1; else @colspan = attrs['colspan'].to_i; end @tdwidth *= @colspan; if ((!attrs['height'].nil?) and (attrs['height'] != '')) @tdheight=(attrs['height'].to_i / @k); else @tdheight = @lasth; end if ((!attrs['align'].nil?) and (attrs['align'] != '')) case (attrs['align']) when 'center' @tdalign = "C"; when 'right' @tdalign = "R"; when 'left' @tdalign = "L"; end end if ((!attrs['bgcolor'].nil?) and (attrs['bgcolor'] != '')) coul = convertColorHexToDec(attrs['bgcolor']); SetFillColor(coul['R'], coul['G'], coul['B']); @tdfill=1; end @tdbegin=true; when 'hr' margin = 1; if ((!attrs['width'].nil?) and (attrs['width'] != '')) hrWidth = attrs['width']; else hrWidth = @w - @l_margin - @r_margin - margin; end SetLineWidth(0.2); Line(@x + margin, @y, @x + hrWidth, @y); Ln(); when 'strong' SetStyle('b', true); when 'em' SetStyle('i', true); when 'ins' SetStyle('u', true); when 'del' SetStyle('d', true); when 'b', 'i', 'u' SetStyle(tag, true); when 'a' @href = attrs['href']; when 'img' if (!attrs['src'].nil?) # Don't generates image inside table tag if (@tdbegin) @tdtext << attrs['src']; return end # Only generates image include a pdf if RMagick is avalaible unless Object.const_defined?(:Magick) Write(@lasth, attrs['src'], '', fill); return end file = getImageFilename(attrs['src']) if (file.nil?) Write(@lasth, attrs['src'], '', fill); return end if (attrs['width'].nil?) attrs['width'] = 0; end if (attrs['height'].nil?) attrs['height'] = 0; end begin Image(file, GetX(),GetY(), pixelsToMillimeters(attrs['width']), pixelsToMillimeters(attrs['height'])); #SetX(@img_rb_x); SetY(@img_rb_y); rescue => err logger.error "pdf: Image: error: #{err.}" Write(@lasth, attrs['src'], '', fill); end end when 'ul', 'ol' if @li_count == 0 Ln() if @prevquote_count == @quote_count; # insert Ln for keeping quote lines @prevquote_count = @quote_count; end if @li_state == true Ln(); @li_state = false; end if tag == 'ul' @list_ordered[@li_count] = false; else @list_ordered[@li_count] = true; end @list_count[@li_count] = 0; @li_count += 1 when 'li' Ln() if @li_state == true if (@list_ordered[@li_count - 1]) @list_count[@li_count - 1] += 1; @li_spacer = " " * @li_count + (@list_count[@li_count - 1]).to_s + ". "; else #unordered list simbol @li_spacer = " " * @li_count + "- "; end Write(@lasth, @spacer + @li_spacer, '', fill); @li_state = true; when 'blockquote' if (@quote_count == 0) SetStyle('i', true); @l_margin += 5; else @l_margin += 5 / 2; end @x = @l_margin; @quote_top[@quote_count] = @y; @quote_page[@quote_count] = @page; @quote_count += 1 when 'br' if @tdbegin @tdtext << "\n" return end Ln(); if (@li_spacer.length > 0) @x += GetStringWidth(@li_spacer); end when 'p' Ln(); 0.upto(@quote_count - 1) do |i| if @quote_page[i] == @page; if @quote_top[i] == @y - @lasth; # fix start line @quote_top[i] = @y; end else if @quote_page[i] == @page - 1; @quote_page[i] = @page; # fix start line @quote_top[i] = @t_margin; end end end when 'sup' currentfont_size = @font_size; @tempfontsize = @font_size_pt; SetFontSize(@font_size_pt * @@k_small_ratio); SetXY(GetX(), GetY() - ((currentfont_size - @font_size)*(@@k_small_ratio))); when 'sub' currentfont_size = @font_size; @tempfontsize = @font_size_pt; SetFontSize(@font_size_pt * @@k_small_ratio); SetXY(GetX(), GetY() + ((currentfont_size - @font_size)*(@@k_small_ratio))); when 'small' currentfont_size = @font_size; @tempfontsize = @font_size_pt; SetFontSize(@font_size_pt * @@k_small_ratio); SetXY(GetX(), GetY() + ((currentfont_size - @font_size)/3)); when 'font' if (!attrs['color'].nil? and attrs['color']!='') coul = convertColorHexToDec(attrs['color']); SetTextColor(coul['R'], coul['G'], coul['B']); @issetcolor=true; end if (!attrs['face'].nil? and @fontlist.include?(attrs['face'].downcase)) SetFont(attrs['face'].downcase); @issetfont=true; end if (!attrs['size'].nil?) headsize = attrs['size'].to_i; else headsize = 0; end currentfont_size = @font_size; @tempfontsize = @font_size_pt; SetFontSize(@font_size_pt + headsize); @lasth = @font_size * @@k_cell_height_ratio; when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' Ln(); headsize = (4 - tag[1,1].to_f) * 2 @tempfontsize = @font_size_pt; SetFontSize(@font_size_pt + headsize); SetStyle('b', true); @lasth = @font_size * @@k_cell_height_ratio; end end |
- (Object) out(s)
Add a line to the document
3054 3055 3056 3057 3058 3059 3060 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3054 def out(s) if (@state==2) @pages[@page] << s.to_s + "\n"; else @buffer << s.to_s + "\n"; end end |
- (Object) Output(name = '', dest = '') 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.<br /> The method first calls Close() if necessary to terminate the document.
2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 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 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2246 def Output(name='', dest='') #Output PDF to some destination #Finish document if necessary 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 @buffer; 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 @buffer; when 'F' open(name,'wb') do |f| f.write(@buffer) end # PHP code # #Save to local file # f=open(name,'wb'); # if (!f) # Error('Unable to create output file: ' + name); # end # fwrite(f,@buffer,@buffer.length); # f.close when 'S' #Return as a string return @buffer; else Error('Incorrect output destination: ' + dest); end return ''; end |
- (Object) PageNo Also known as: page_no
Returns the current page number.
1041 1042 1043 1044 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1041 def PageNo() #Get current page number return @page; end |
- (Object) parsejpg(file)
Extract info from a JPEG file
2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2870 def parsejpg(file) a=getimagesize(file); if (a.empty?) Error('Missing or incorrect image file: ' + file); end if (!a[2].nil? and a[2]!='JPEG') Error('Not a JPEG file: ' + file); end if (a['channels'].nil? or a['channels']==3) colspace='DeviceRGB'; elsif (a['channels']==4) colspace='DeviceCMYK'; else colspace='DeviceGray'; end bpc=!a['bits'].nil? ? a['bits'] : 8; #Read whole file data=''; open(file,'rb') do |f| data<<f.read(); end return {'w' => a[0],'h' => a[1],'cs' => colspace,'bpc' => bpc,'f'=>'DCTDecode','data' => data} end |
- (Object) parsepng(file)
Extract info from a PNG file
2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 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 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2916 def parsepng(file) f=open(file,'rb'); #Check signature if (f.read(8)!=137.chr + 'PNG' + 13.chr + 10.chr + 26.chr + 10.chr) Error('Not a PNG file: ' + file); end #Read header chunk f.read(4); if (f.read(4)!='IHDR') Error('Incorrect PNG file: ' + file); end w=freadint(f); h=freadint(f); bpc=f.read(1).unpack('C')[0]; if (bpc>8) Error('16-bit depth not supported: ' + file); end ct=f.read(1).unpack('C')[0]; if (ct==0) colspace='DeviceGray'; elsif (ct==2) colspace='DeviceRGB'; elsif (ct==3) colspace='Indexed'; else Error('Alpha channel not supported: ' + file); end if (f.read(1).unpack('C')[0] != 0) Error('Unknown compression method: ' + file); end if (f.read(1).unpack('C')[0] != 0) Error('Unknown filter method: ' + file); end if (f.read(1).unpack('C')[0] != 0) Error('Interlacing not supported: ' + file); end f.read(4); parms='/DecodeParms <</Predictor 15 /Colors ' + (ct==2 ? 3 : 1).to_s + ' /BitsPerComponent ' + bpc.to_s + ' /Columns ' + w.to_s + '>>'; #Scan chunks looking for palette, transparency and image data pal=''; trns=''; data=''; begin n=freadint(f); type=f.read(4); if (type=='PLTE') #Read palette pal=f.read( n); f.read(4); elsif (type=='tRNS') #Read transparency info t=f.read( n); if (ct==0) trns = t[1].unpack('C')[0] elsif (ct==2) trns = t[[1].unpack('C')[0], t[3].unpack('C')[0], t[5].unpack('C')[0]] else pos=t.index(0.chr); unless (pos.nil?) trns = [pos] end end f.read(4); elsif (type=='IDAT') #Read image data block data<<f.read( n); f.read(4); elsif (type=='IEND') break; else f.read( n+4); end end while(n) if (colspace=='Indexed' and pal.empty?) Error('Missing palette in ' + file); end return {'w' => w, 'h' => h, 'cs' => colspace, 'bpc' => bpc, 'f'=>'FlateDecode', 'parms' => parms, 'pal' => pal, 'trns' => trns, 'data' => data} ensure f.close end |
- (Object) pixelsToMillimeters(px)
Converts pixels to millimeters in 72 dpi.
4327 4328 4329 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 4327 def pixelsToMillimeters(px) return px.to_f * 25.4 / 72; end |
- (Object) putcatalog
putcatalog
2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2721 def putcatalog() out('/Type /Catalog'); out('/Pages 1 0 R'); if (@zoom_mode=='fullpage') out('/OpenAction [3 0 R /Fit]'); elsif (@zoom_mode=='fullwidth') out('/OpenAction [3 0 R /FitH null]'); elsif (@zoom_mode=='real') out('/OpenAction [3 0 R /XYZ null null 1]'); elsif (!@zoom_mode.is_a?(String)) out('/OpenAction [3 0 R /XYZ null null ' + (@zoom_mode/100) + ']'); end if (@layout_mode=='single') out('/PageLayout /SinglePage'); elsif (@layout_mode=='continuous') out('/PageLayout /OneColumn'); elsif (@layout_mode=='two') out('/PageLayout /TwoColumnLeft'); end end |
- (Object) putfonts
Adds fonts putfonts
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 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2449 def putfonts() nf=@n; @diffs.each do |diff| #Encodings newobj(); out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' + diff + ']>>'); out('endobj'); end @font_files.each do |file, info| #Font file embedding newobj(); @font_files[file]['n']=@n; font=''; open(getfontpath(file),'rb') do |f| font = f.read(); end compressed=(file[-2,2]=='.z'); if (!compressed && !info['length2'].nil?) header=((font[0][0])==128); if (header) #Strip first binary header font=font[6]; end if header && (font[info['length1']][0] == 128) #Strip second binary header font=font[0..info['length1']] + font[info['length1']+6]; end end out('<</Length '+ font.length.to_s); if (compressed) out('/Filter /FlateDecode'); end out('/Length1 ' + info['length1'].to_s); if (!info['length2'].nil?) out('/Length2 ' + info['length2'].to_s + ' /Length3 0'); end out('>>'); open(getfontpath(file),'rb') do |f| putstream(font) end out('endobj'); end @fonts.each do |k, font| #Font objects @fonts[k]['n']=@n+1; type = font['type']; name = font['name']; if (type=='core') #Standard font newobj(); out('<</Type /Font'); out('/BaseFont /' + name); out('/Subtype /Type1'); if (name!='Symbol' && name!='ZapfDingbats') out('/Encoding /WinAnsiEncoding'); end out('>>'); out('endobj'); elsif type == 'Type0' putType0(font) elsif (type=='Type1' || type=='TrueType') #Additional Type1 or TrueType font newobj(); out('<</Type /Font'); out('/BaseFont /' + name); out('/Subtype /' + type); out('/FirstChar 32 /LastChar 255'); out('/Widths ' + (@n+1).to_s + ' 0 R'); out('/FontDescriptor ' + (@n+2).to_s + ' 0 R'); if (font['enc']) if (!font['diff'].nil?) out('/Encoding ' + (nf+font['diff']).to_s + ' 0 R'); else out('/Encoding /WinAnsiEncoding'); end end out('>>'); out('endobj'); #Widths newobj(); cw=font['cw']; # & s='['; 32.upto(255) do |i| s << cw[i.chr] + ' '; end out(s + ']'); out('endobj'); #Descriptor newobj(); s='<</Type /FontDescriptor /FontName /' + name; font['desc'].each do |k, v| s<<' /' + k + ' ' + v; end file = font['file']; if (file) s<<' /FontFile' + (type=='Type1' ? '' : '2') + ' ' + @font_files[file]['n'] + ' 0 R'; end out(s + '>>'); out('endobj'); else #Allow for additional types mtd='put' + type.downcase; if (!self.respond_to?(mtd)) Error('Unsupported font type: ' + type) else self.send(mtd,font) end end end end |
- (Object) putheader
putheader
2756 2757 2758 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2756 def putheader() out('%PDF-' + @pdf_version); end |
- (Object) putimages
putimages
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 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2605 def putimages() filter=(@compress) ? '/Filter /FlateDecode ' : ''; @images.each do |file, info| # was while(list(file, info)=each(@images)) newobj(); @images[file]['n']=@n; out('<</Type /XObject'); out('/Subtype /Image'); out('/Width ' + info['w'].to_s); out('/Height ' + info['h'].to_s); if (info['cs']=='Indexed') out('/ColorSpace [/Indexed /DeviceRGB ' + (info['pal'].length/3-1).to_s + ' ' + (@n+1).to_s + ' 0 R]'); else out('/ColorSpace /' + info['cs']); if (info['cs']=='DeviceCMYK') out('/Decode [1 0 1 0 1 0 1 0]'); end end out('/BitsPerComponent ' + info['bpc'].to_s); if (!info['f'].nil?) out('/Filter /' + info['f']); end if (!info['parms'].nil?) out(info['parms']); end if (!info['trns'].nil? and info['trns'].kind_of?(Array)) trns=''; 0.upto(info['trns'].length) do |i| trns << ("#{info['trns'][i]} " * 2); end out('/Mask [' + trns + ']'); end out('/Length ' + info['data'].length.to_s + '>>'); putstream(info['data']); @images[file]['data']=nil out('endobj'); #Palette if (info['cs']=='Indexed') newobj(); pal=(@compress) ? gzcompress(info['pal']) : info['pal']; out('<<' + filter + '/Length ' + pal.length.to_s + '>>'); putstream(pal); out('endobj'); end end end |
- (Object) putinfo
putinfo
2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2697 def putinfo() out('/Producer ' + textstring(PDF_PRODUCER)); if (!@title.nil?) out('/Title ' + textstring(@title)); end if (!@subject.nil?) out('/Subject ' + textstring(@subject)); end if (!@author.nil?) out('/Author ' + textstring(@author)); end if (!@keywords.nil?) out('/Keywords ' + textstring(@keywords)); end if (!@creator.nil?) out('/Creator ' + textstring(@creator)); end out('/CreationDate ' + textstring('D:' + Time.now.strftime('%Y%m%d%H%M%S'))); end |
- (Object) putpages
putpages
2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2378 def putpages() nb = @page; if (@alias_nb_pages) nbstr = UTF8ToUTF16BE(nb.to_s, false); #Replace number of pages 1.upto(nb) do |n| @pages[n].gsub!(@alias_nb_pages, nbstr) end end if @def_orientation=='P' w_pt=@fw_pt h_pt=@fh_pt else w_pt=@fh_pt h_pt=@fw_pt end filter=(@compress) ? '/Filter /FlateDecode ' : '' 1.upto(nb) do |n| #Page newobj out('<</Type /Page') out('/Parent 1 0 R') unless @orientation_changes[n].nil? out(sprintf('/MediaBox [0 0 %.2f %.2f]', h_pt, w_pt)) end out('/Resources 2 0 R') if @page_links[n] #Links annots='/Annots [' @page_links[n].each do |pl| rect=sprintf('%.2f %.2f %.2f %.2f', pl[0], pl[1], pl[0]+pl[2], pl[1]-pl[3]); annots<<'<</Type /Annot /Subtype /Link /Rect [' + rect + '] /Border [0 0 0] '; if (pl[4].is_a?(String)) annots<<'/A <</S /URI /URI (' + escape(pl[4]) + ')>>>>'; else l=@links[pl[4]]; h=!@orientation_changes[l[0]].nil? ? w_pt : h_pt; annots<<sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*l[0], h-l[1]*@k); end end out(annots + ']'); end out('/Contents ' + (@n+1).to_s + ' 0 R>>'); out('endobj'); #Page content p=(@compress) ? gzcompress(@pages[n]) : @pages[n]; newobj(); out('<<' + filter + '/Length '+ p.length.to_s + '>>'); putstream(p); out('endobj'); end #Pages root @offsets[1]=@buffer.length; out('1 0 obj'); out('<</Type /Pages'); kids='/Kids ['; 0.upto(nb - 1) do |i| kids<<(3+2*i).to_s + ' 0 R '; end out(kids + ']'); out('/Count ' + nb.to_s); out(sprintf('/MediaBox [0 0 %.2f %.2f]', w_pt, h_pt)); out('>>'); out('endobj'); end |
- (Object) putresourcedict
putresourcedict
2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2665 def putresourcedict() out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); out('/Font <<'); @fonts.each_value do |font| out('/F' + font['i'].to_s + ' ' + font['n'].to_s + ' 0 R'); end out('>>'); out('/XObject <<'); putxobjectdict(); out('>>'); end |
- (Object) putresources
putresources
2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2681 def putresources() putfonts(); putimages(); #Resource dictionary @offsets[2]=@buffer.length; out('2 0 obj'); out('<<'); putresourcedict(); out('>>'); out('endobj'); end |
- (Object) putstream(s)
3044 3045 3046 3047 3048 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3044 def putstream(s) out('stream'); out(s); out('endstream'); end |
- (Object) puttrailer
puttrailer
2746 2747 2748 2749 2750 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2746 def puttrailer() out('/Size ' + (@n+1).to_s); out('/Root ' + @n.to_s + ' 0 R'); out('/Info ' + (@n-1).to_s + ' 0 R'); end |
- (Object) puttruetypeunicode(font)
Adds unicode fonts.<br> Based on PDF Reference 1.3 (section 5)
3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3069 def puttruetypeunicode(font) # Type0 Font # A composite font composed of other fonts, organized hierarchically newobj(); out('<</Type /Font'); out('/Subtype /Type0'); out('/BaseFont /' + font['name'] + ''); out('/Encoding /Identity-H'); #The horizontal identity mapping for 2-byte CIDs; may be used with CIDFonts using any Registry, Ordering, and Supplement values. out('/DescendantFonts [' + (@n + 1).to_s + ' 0 R]'); out('/ToUnicode ' + (@n + 2).to_s + ' 0 R'); out('>>'); out('endobj'); # CIDFontType2 # A CIDFont whose glyph descriptions are based on TrueType font technology newobj(); out('<</Type /Font'); out('/Subtype /CIDFontType2'); out('/BaseFont /' + font['name'] + ''); out('/CIDSystemInfo ' + (@n + 2).to_s + ' 0 R'); out('/FontDescriptor ' + (@n + 3).to_s + ' 0 R'); if (!font['desc']['MissingWidth'].nil?) out('/DW ' + font['desc']['MissingWidth'].to_s + ''); # The default width for glyphs in the CIDFont MissingWidth end w = ""; font['cw'].each do |cid, width| w << '' + cid.to_s + ' [' + width.to_s + '] '; # define a specific width for each individual CID end out('/W [' + w + ']'); # A description of the widths for the glyphs in the CIDFont out('/CIDToGIDMap ' + (@n + 4).to_s + ' 0 R'); out('>>'); out('endobj'); # ToUnicode # is a stream object that contains the definition of the CMap # (PDF Reference 1.3 chap. 5.9) newobj(); out('<</Length 345>>') out('stream'); out('/CIDInit /ProcSet findresource begin'); out('12 dict begin'); out('begincmap'); out('/CIDSystemInfo'); out('<</Registry (Adobe)'); out('/Ordering (UCS)'); out('/Supplement 0'); out('>> def'); out('/CMapName /Adobe-Identity-UCS def'); out('/CMapType 2 def'); out('1 begincodespacerange'); out('<0000> <FFFF>'); out('endcodespacerange'); out('1 beginbfrange'); out('<0000> <FFFF> <0000>'); out('endbfrange'); out('endcmap'); out('CMapName currentdict /CMap defineresource pop'); out('end'); out('end'); out('endstream'); out('endobj'); # CIDSystemInfo dictionary # A dictionary containing entries that define the character collection of the CIDFont. newobj(); out('<</Registry (Adobe)'); # A string identifying an issuer of character collections out('/Ordering (UCS)'); # A string that uniquely names a character collection issued by a specific registry out('/Supplement 0'); # The supplement number of the character collection. out('>>'); out('endobj'); # Font descriptor # A font descriptor describing the CIDFont default metrics other than its glyph widths newobj(); out('<</Type /FontDescriptor'); out('/FontName /' + font['name']); font['desc'].each do |key, value| out('/' + key.to_s + ' ' + value.to_s); end if (font['file']) # A stream containing a TrueType font program out('/FontFile2 ' + @font_files[font['file']]['n'].to_s + ' 0 R'); end out('>>'); out('endobj'); # Embed CIDToGIDMap # A specification of the mapping from CIDs to glyph indices newobj(); ctgfile = getfontpath(font['ctg']) if (!ctgfile) Error('Font file not found: ' + ctgfile); end size = File.size(ctgfile); out('<</Length ' + size.to_s + ''); if (ctgfile[-2,2] == '.z') # check file extension # Decompresses data encoded using the public-domain # zlib/deflate compression method, reproducing the # original text or binary data# out('/Filter /FlateDecode'); end out('>>'); open(ctgfile, "rb") do |f| putstream(f.read()) end out('endobj'); end |
- (Object) putType0(font)
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 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2560 def putType0(font) #Type0 newobj(); out('<</Type /Font') out('/Subtype /Type0') out('/BaseFont /'+font['name']+'-'+font['cMap']) out('/Encoding /'+font['cMap']) out('/DescendantFonts ['+(@n+1).to_s+' 0 R]') out('>>') out('endobj') #CIDFont newobj() out('<</Type /Font') out('/Subtype /CIDFontType0') out('/BaseFont /'+font['name']) out('/CIDSystemInfo <</Registry (Adobe) /Ordering ('+font['registry']['ordering']+') /Supplement '+font['registry']['supplement'].to_s+'>>') out('/FontDescriptor '+(@n+1).to_s+' 0 R') w='/W [1 [' font['cw'].keys.sort.each {|key| w+=font['cw'][key].to_s + " " # ActionController::Base::logger.debug key.to_s # ActionController::Base::logger.debug font['cw'][key].to_s } out(w+'] 231 325 500 631 [500] 326 389 500]') out('>>') out('endobj') #Font descriptor newobj() out('<</Type /FontDescriptor') out('/FontName /'+font['name']) out('/Flags 6') out('/FontBBox [0 -200 1000 900]') out('/ItalicAngle 0') out('/Ascent 800') out('/Descent -200') out('/CapHeight 800') out('/StemV 60') out('>>') out('endobj') end |
- (Object) putxobjectdict
putxobjectdict
2655 2656 2657 2658 2659 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2655 def putxobjectdict() @images.each_value do |image| out('/I' + image['i'].to_s + ' ' + image['n'].to_s + ' 0 R'); end end |
- (Object) Rect(x, y, w, h, style = '') Also known as: rect
Outputs a rectangle. It can be drawn (border only), filled (with no border) or both.
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1292 def Rect(x, y, w, h, style='') #Draw a rectangle if (style=='F') op='f'; elsif (style=='FD' or style=='DF') op='B'; else op='S'; end out(sprintf('%.2f %.2f %.2f %.2f re %s', x * @k, (@h - y) * @k, w * @k, -h * @k, op)); end |
- (Object) Rotate(angle, x = "", y = "") Also known as: rotate
Rotate object.
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 826 def Rotate(angle, x="", y="") if (x == '') x = @x; end if (y == '') y = @y; end if (@rtl) x = @w - x; angle = -@angle; end y = (@h - y) * @k; x *= @k; # calculate elements of transformation matrix tm = [] tm[0] = ::Math::cos(deg2rad(angle)); tm[1] = ::Math::sin(deg2rad(angle)); 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 |
- (Object) SetAuthor(author) Also known as:
Defines the author of the document.
639 640 641 642 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 639 def SetAuthor() #Author of document @author = end |
- (Object) SetAutoPageBreak(auto, margin = 0) 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.
564 565 566 567 568 569 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 564 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 |
- (Object) SetBarcode(bc = "")
3376 3377 3378 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3376 def SetBarcode(bc="") @barcode = bc; end |
- (Object) SetCmykFillColor(c, m, y, k, storeprev = false) Also known as: set_cmyk_fill_color
This hasn't been ported from tcpdf, it's a variation on SetTextColor for setting cmyk colors
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1096 def SetCmykFillColor(c, m, y, k, storeprev=false) #Set color for all filling operations @fill_color=sprintf('%.3f %.3f %.3f %.3f k', c, m, y, k); @color_flag=(@fill_color!=@text_color); if (storeprev) # store color as previous value @prevtext_color = [c, m, y, k] end if (@page>0) out(@fill_color); end end |
- (Object) SetCmykTextColor(c, m, y, k, storeprev = false) Also known as: set_cmyk_text_color
This hasn't been ported from tcpdf, it's a variation on SetTextColor for setting cmyk colors
1135 1136 1137 1138 1139 1140 1141 1142 1143 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1135 def SetCmykTextColor(c, m, y, k, storeprev=false) #Set color for text @text_color=sprintf('%.3f %.3f %.3f %.3f k', c, m, y, k); @color_flag=(@fill_color!=@text_color); if (storeprev) # store color as previous value @prevtext_color = [c, m, y, k] end end |
- (Object) SetCompression(compress) 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.
599 600 601 602 603 604 605 606 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 599 def SetCompression(compress) #Set page compression if (respond_to?('gzcompress')) @compress = compress else @compress = false end end |
- (Object) SetCreator(creator) Also known as: set_creator
Defines the creator of the document. This is typically the name of the application that generates the PDF.
663 664 665 666 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 663 def SetCreator(creator) #Creator of document @creator = creator end |
- (Object) SetDisplayMode(zoom, layout = 'continuous') Also known as: set_display_mode
Defines the way the document is to be displayed by the viewer. The zoom level can be set: pages can be displayed entirely on screen, occupy the full width of the window, use real size, be scaled by a specific zooming factor or use viewer default (configured in the Preferences menu of Acrobat). The page layout can be specified too: single at once, continuous display, two columns or viewer default. By default, documents use the full width mode with continuous display.
578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 578 def SetDisplayMode(zoom, layout = 'continuous') #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 if (layout == 'single' or layout == 'continuous' or layout == 'two' or layout == 'default') @layout_mode = layout else Error("Incorrect layout display mode: #{layout}") end end |
- (Object) SetDrawColor(r, g = -1,, b = -1)) 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.
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1055 def SetDrawColor(r, g=-1, b=-1) #Set color for all stroking operations if ((r==0 and g==0 and b==0) or g==-1) @draw_color=sprintf('%.3f G', r/255.0); else @draw_color=sprintf('%.3f %.3f %.3f RG', r/255.0, g/255.0, b/255.0); end if (@page>0) out(@draw_color); end end |
- (Object) SetFillColor(r, g = -1,, b = -1,, storeprev = false) 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.
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1077 def SetFillColor(r, g=-1, b=-1, storeprev=false) #Set color for all filling operations if ((r==0 and g==0 and b==0) or g==-1) @fill_color=sprintf('%.3f g', r/255.0); else @fill_color=sprintf('%.3f %.3f %.3f rg', r/255.0, g/255.0, b/255.0); end @color_flag=(@fill_color!=@text_color); if (@page>0) out(@fill_color); end if (storeprev) # store color as previous value @prevfill_color = [r, g, b] end end |
- (Object) SetFont(family, style = '', size = 0) Also known as: set_font
Sets the font used to print character strings. It is mandatory to call this method at least once before printing text or the resulting document would not be valid. 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:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the FPDF_FONTPATH constant</li></ul><br /> Example for the last case (note the trailing slash):<br /> <pre> define('FPDF_FONTPATH','/home/www/font/'); require('tcpdf.rb');
#Times regular 12 :pdf->SetFont('Times'); #Arial bold 14 :pdf->SetFont('Arial','B',14); #Removes bold :pdf->SetFont(''); #Times bold, italic and underlined 14 :pdf->SetFont('Times','BIUD'); </pre><br /> If the file corresponding to the requested font is not found, the error “Could not include font metric file” is generated.
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 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 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1425 def SetFont(family, style='', size=0) # save previous values @prevfont_family = @font_family; @prevfont_style = @font_style; family=family.downcase; if (family=='') family=@font_family; end if ((!@is_unicode) and (family == 'arial')) family = 'helvetica'; elsif ((family=="symbol") or (family=="zapfdingbats")) style=''; end style=style.upcase; if (style.include?('U')) @underline=true; style= style.gsub('U',''); else @underline=false; end if (style.include?('D')) @deleted=true; style= style.gsub('D',''); else @deleted=false; end if (style=='IB') style='BI'; end if (size==0) size=@font_size_pt; end # try to add font (if not already added) AddFont(family, style); #Test if font is already selected if ((@font_family == family) and (@font_style == style) and (@font_size_pt == size)) return; end fontkey = family + style; style = '' if (@fonts[fontkey].nil? and !@fonts[family].nil?) #Test if used for the first time if (@fonts[fontkey].nil?) #Check if one of the standard fonts if (!@core_fonts[fontkey].nil?) if @@fpdf_charwidths[fontkey].nil? #Load metric file file = family; if ((family!='symbol') and (family!='zapfdingbats')) file += style.downcase; end if (getfontpath(file + '.rb').nil?) # try to load the basic file without styles file = family; fontkey = family; end require(getfontpath(file + '.rb')); font_desc = TCPDFFontDescriptor.font(file) if ((@is_unicode and ctg.nil?) or ((!@is_unicode) and (@@fpdf_charwidths[fontkey].nil?)) ) Error("Could not include font metric file [" + fontkey + "]: " + getfontpath(file + ".rb")); end end i = @fonts.length + 1; if (@is_unicode) @fonts[fontkey] = {'i' => i, 'type' => font_desc[:type], 'name' => font_desc[:name], 'desc' => font_desc[:desc], 'up' => font_desc[:up], 'ut' => font_desc[:ut], 'cw' => font_desc[:cw], 'enc' => font_desc[:enc], 'file' => font_desc[:file], 'ctg' => font_desc[:ctg]} @@fpdf_charwidths[fontkey] = font_desc[:cw]; else @fonts[fontkey] = {'i' => i, 'type'=>'core', 'name'=>@core_fonts[fontkey], 'up'=>-100, 'ut'=>50, 'cw' => font_desc[:cw]} @@fpdf_charwidths[fontkey] = font_desc[:cw]; end else Error('Undefined font: ' + family + ' ' + style); end end #Select it @font_family = family; @font_style = style; @font_size_pt = size; @font_size = size / @k; @current_font = @fonts[fontkey]; # was & may need deep copy? if (@page>0) out(sprintf('BT /F%d %.2f Tf ET', @current_font['i'], @font_size_pt)); end end |
- (Object) SetFontSize(size) Also known as: set_font_size
Defines the size of the current font.
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1524 def SetFontSize(size) #Set font size in points if (@font_size_pt== size) return; end @font_size_pt = size; @font_size = size.to_f / @k; if (@page > 0) out(sprintf('BT /F%d %.2f Tf ET', @current_font['i'], @font_size_pt)); end end |
- (Object) SetFooterFont(font) Also known as:
3358 3359 3360 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3358 def SetFooterFont(font) @footer_font = font; end |
- (Object) SetFooterMargin(fm = 10) Also known as:
(minimum distance between footer and bottom page margin)
918 919 920 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 918 def SetFooterMargin(fm=10) @footer_margin = fm; end |
- (Object) SetHeaderData(ln = "", lw = 0, ht = "", hs = "") Also known as: set_header_data
895 896 897 898 899 900 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 895 def SetHeaderData(ln="", lw=0, ht="", hs="") @header_logo = ln || "" @header_logo_width = lw || 0 @header_title = ht || "" @header_string = hs || "" end |
- (Object) SetHeaderFont(font) Also known as: set_header_font
3348 3349 3350 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3348 def SetHeaderFont(font) @header_font = font; end |
- (Object) SetHeaderMargin(hm = 10) Also known as: set_header_margin
(minimum distance between header and top page margin)
908 909 910 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 908 def SetHeaderMargin(hm=10) @header_margin = hm; end |
- (Object) SetImageScale(scale) Also known as: set_image_scale
Set the image scale.
439 440 441 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 439 def SetImageScale(scale) @img_scale = scale; end |
- (Object) SetKeywords(keywords) Also known as: set_keywords
Associates keywords with the document, generally in the form 'keyword1 keyword2 …'.
651 652 653 654 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 651 def SetKeywords(keywords) #Keywords of document @keywords = keywords end |
- (Object) SetLanguageArray(language) Also known as: set_language_array
3368 3369 3370 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3368 def SetLanguageArray(language) @l = language; end |
- (Object) SetLeftMargin(margin) 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.
524 525 526 527 528 529 530 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 524 def SetLeftMargin(margin) #Set left margin @l_margin = margin if ((@page>0) and (@x < margin)) @x = margin end end |
- (Object) SetLineWidth(width) Also known as: set_line_width
Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
1193 1194 1195 1196 1197 1198 1199 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1193 def SetLineWidth(width) #Set line width @line_width = width; if (@page>0) out(sprintf('%.2f w', width*@k)); end end |
- (Object) SetLink(link, y = 0, page = -1)) Also known as: set_link
Defines the page and position a link points to
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1559 def SetLink(link, y=0, page=-1) #Set destination of internal link if (y==-1) y=@y; end if (page==-1) page=@page; end @links[link] = [page, y] end |
- (Object) SetMargins(left, top, right = -1)) Also known as: set_margins
Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
507 508 509 510 511 512 513 514 515 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 507 def SetMargins(left, top, right=-1) #Set left, top and right margins @l_margin = left @t_margin = top if (right == -1) right = left end @r_margin = right end |
- (Object) SetPrintFooter(val = true) Also known as:
936 937 938 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 936 def SetPrintFooter(val=true) @print_footer = val; end |
- (Object) SetPrintHeader(val = true) Also known as: set_print_header
927 928 929 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 927 def SetPrintHeader(val=true) @print_header = val; end |
- (Object) SetRightMargin(margin) Also known as: set_right_margin
Defines the right margin. The method can be called before creating the first page.
551 552 553 554 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 551 def SetRightMargin(margin) #Set right margin @r_margin = margin end |
- (Object) SetStyle(tag, enable)
Sets font style.
4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 4276 def SetStyle(tag, enable) #Modify style and select corresponding font ['b', 'i', 'u', 'd'].each do |s| if tag.downcase == s if enable @style << s if ! @style.include?(s) else @style = @style.gsub(s,'') end end end SetFont('', @style); end |
- (Object) SetSubject(subject) Also known as: set_subject
Defines the subject of the document.
627 628 629 630 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 627 def SetSubject(subject) #Subject of document @subject = subject end |
- (Object) SetTextColor(r, g = -1,, b = -1,, storeprev = false) Also known as: set_text_color
Defines the color used for text. 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.
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1119 def SetTextColor(r, g=-1, b=-1, storeprev=false) #Set color for text if ((r==0 and :g==0 and :b==0) or :g==-1) @text_color=sprintf('%.3f g', r/255.0); else @text_color=sprintf('%.3f %.3f %.3f rg', r/255.0, g/255.0, b/255.0); end @color_flag=(@fill_color!=@text_color); if (storeprev) # store color as previous value @prevtext_color = [r, g, b] end end |
- (Object) SetTitle(title) Also known as: set_title
Defines the title of the document.
615 616 617 618 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 615 def SetTitle(title) #Title of document @title = title end |
- (Object) SetTopMargin(margin) Also known as: set_top_margin
Defines the top margin. The method can be called before creating the first page.
539 540 541 542 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 539 def SetTopMargin(margin) #Set top margin @t_margin = margin end |
- (Object) SetX(x) Also known as: set_x
Defines the abscissa of the current position. If the passed value is negative, it is relative to the right of the page.
2185 2186 2187 2188 2189 2190 2191 2192 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2185 def SetX(x) #Set x position if (x>=0) @x = x; else @x=@w+x; end end |
- (Object) SetXY(x, y) Also known as: set_xy
Defines the abscissa and ordinate of the current position. If the passed values are negative, they are relative respectively to the right and bottom of the page.
2231 2232 2233 2234 2235 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2231 def SetXY(x, y) #Set x and y positions SetY(y); SetX(x); end |
- (Object) SetY(y) Also known as: set_y
Moves the current abscissa back to the left margin and sets the ordinate. If the passed value is negative, it is relative to the bottom of the page.
2213 2214 2215 2216 2217 2218 2219 2220 2221 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 2213 def SetY(y) #Set y position and reset x @x=@l_margin; if (y>=0) @y = y; else @y=@h+y; end end |
- (Object) StartTransform Also known as: start_transform
Starts a 2D tranformation saving current graphic state. This function must be called before scaling, mirroring, translation, rotation and skewing. Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
863 864 865 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 863 def StartTransform out('q'); end |
- (Object) StopTransform Also known as: stop_transform
Stops a 2D tranformation restoring previous graphic state. This function must be called after scaling, mirroring, translation, rotation and skewing. Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
873 874 875 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 873 def StopTransform out('Q'); end |
- (Object) Text(x, y, txt) Also known as: text
Prints a character string. The origin is on the left of the first charcter, on the baseline. This method allows to place a string precisely on the page, but it is usually easier to use Cell(), MultiCell() or Write() which are the standard methods to print text.
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1597 def Text(x, y, txt) #Output a string s=sprintf('BT %.2f %.2f Td (%s) Tj ET', x * @k, (@h-y) * @k, escapetext(txt)); if (@underline and (txt!='')) s += ' ' + dolinetxt(x, y, txt); end if (@color_flag) s='q ' + @text_color + ' ' + s + ' Q'; end out(s); end |
- (Object) textstring(s)
Format a text string
3011 3012 3013 3014 3015 3016 3017 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3011 def textstring(s) if (@is_unicode) #Convert string to UTF-16BE s = UTF8ToUTF16BE(s, true); end return '(' + escape(s) + ')'; end |
- (Object) Transform(tm) Also known as: transform
Apply graphic transformations.
883 884 885 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 883 def Transform(tm) x = out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f cm', tm[0], tm[1], tm[2], tm[3], tm[4], tm[5])); end |
- (Object) unhtmlentities(string)
Reverse function for htmlentities. Convert entities in UTF-8.
4338 4339 4340 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 4338 def unhtmlentities(string) CGI.unescapeHTML(string) end |
- (Object) UTF8StringToArray(str)
Converts UTF-8 strings to codepoints array.<br> Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br> Based on: www.faqs.org/rfcs/rfc3629.html <pre> Char. number range | UTF-8 octet sequence
(hexadecimal) | (binary)
--------------------+-----------------------------------------------
0000 0000-0000 007F | 0xxxxxxx
0000 0080-0000 07FF | 110xxxxx 10xxxxxx
0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
---------------------------------------------------------------------
ABFN notation:
---------------------------------------------------------------------
UTF8-octets =#( UTF8-char )
UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
UTF8-1 = %x00-7F
UTF8-2 = %xC2-DF UTF8-tail
UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
%xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
%xF4 %x80-8F 2( UTF8-tail )
UTF8-tail = %x80-BF
---------------------------------------------------------------------
</pre>
3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3211 def UTF8StringToArray(str) if (!@is_unicode) return str; # string is not in unicode end unicode = [] # array containing unicode values bytes = [] # array containing single character byte sequences numbytes = 1; # number of octetc needed to represent the UTF-8 character str = str.to_s; # force :str to be a string str.each_byte do |char| if (bytes.length == 0) # get starting octect if (char <= 0x7F) unicode << char # use the character "as is" because is ASCII numbytes = 1 elsif ((char >> 0x05) == 0x06) # 2 bytes character (0x06 = 110 BIN) bytes << ((char - 0xC0) << 0x06) numbytes = 2 elsif ((char >> 0x04) == 0x0E) # 3 bytes character (0x0E = 1110 BIN) bytes << ((char - 0xE0) << 0x0C) numbytes = 3 elsif ((char >> 0x03) == 0x1E) # 4 bytes character (0x1E = 11110 BIN) bytes << ((char - 0xF0) << 0x12) numbytes = 4 else # use replacement character for other invalid sequences unicode << 0xFFFD bytes = [] numbytes = 1 end elsif ((char >> 0x06) == 0x02) # bytes 2, 3 and 4 must start with 0x02 = 10 BIN bytes << (char - 0x80) if (bytes.length == numbytes) # compose UTF-8 bytes to a single unicode value char = bytes[0] 1.upto(numbytes-1) do |j| char += (bytes[j] << ((numbytes - j - 1) * 0x06)) end if (((char >= 0xD800) and (char <= 0xDFFF)) or (char >= 0x10FFFF)) # The definition of UTF-8 prohibits encoding character numbers between # U+D800 and U+DFFF, which are reserved for use with the UTF-16 # encoding form (as surrogate pairs) and do not directly represent # characters unicode << 0xFFFD; # use replacement character else unicode << char; # add char to array end # reset data for next char bytes = [] numbytes = 1; end else # use replacement character for other invalid sequences unicode << 0xFFFD; bytes = [] numbytes = 1; end end return unicode; end |
- (Object) UTF8ToUTF16BE(str, setbom = true)
UTF-16 proceeds as follows. Let U be the character number, no greater
than 0x10FFFF.
1) If U < 0x10000, encode U as a 16-bit unsigned integer and
terminate.
2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
U' must be less than or equal to 0xFFFFF. That is, U' can be
represented in 20 bits.
3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
0xDC00, respectively. These integers each have 10 bits free to
encode the character value, for a total of 20 bits.
4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
bits of W1 and the 10 low-order bits of U' to the 10 low-order
bits of W2. Terminate.
Graphically, steps 2 through 4 look like:
U' = yyyyyyyyyyxxxxxxxxxx
W1 = 110110yyyyyyyyyy
W2 = 110111xxxxxxxxxx
</pre>
3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3311 def UTF8ToUTF16BE(str, setbom=true) if (!@is_unicode) return str; # string is not in unicode end outstr = ""; # string to be returned unicode = UTF8StringToArray(str); # array containing UTF-8 unicode values numitems = unicode.length; if (setbom) outstr << "\xFE\xFF"; # Byte Order Mark (BOM) end unicode.each do |char| if (char == 0xFFFD) outstr << "\xFF\xFD"; # replacement character elsif (char < 0x10000) outstr << (char >> 0x08).chr; outstr << (char & 0xFF).chr; else char -= 0x10000; w1 = 0xD800 | (char >> 0x10); w2 = 0xDC00 | (char & 0x3FF); outstr << (w1 >> 0x08).chr; outstr << (w1 & 0xFF).chr; outstr << (w2 >> 0x08).chr; outstr << (w2 & 0xFF).chr; end end return outstr; end |
- (Object) Write(h, txt, link = nil, fill = 0) Also known as: write
This method prints text from the current position. When the right margin is reached (or the n character is met) a line break occurs and text continues from the left margin. Upon method exit, the current position is left just at the end of the text. It is possible to put a link on the text.<br /> Example:<br /> <pre> #Begin with regular font :pdf->SetFont('Arial','',14); :pdf->Write(5,'Visit '); #Then put a blue underlined link :pdf->SetTextColor(0,0,255); :pdf->SetFont('','U'); :pdf->Write(5,'www.tecnick.com’,‘http://www.tecnick.com'); </pre>
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 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 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 1943 def Write(h, txt, link=nil, fill=0) #Output text in flowing mode w = @w - @r_margin - @x; wmax = (w - 3 * @c_margin); s = txt.gsub("\r", ''); nb = s.length; # handle single space character if ((nb==1) and (s == " ")) @x += GetStringWidth(s); return; end sep=-1; i=0; j=0; l=0; nl=1; while(i<nb) #Get next character c = s[i]; if (c == "\n"[0]) #Explicit line break Cell(w, h, s[j,i-j], 0, 2, '', fill, link); i += 1; sep = -1; j = i; l = 0; if (nl == 1) @x = @l_margin; w = @w - @r_margin - @x; wmax = (w - 3 * @c_margin); end nl += 1; next end if (c == " "[0]) sep= i; end l = GetStringWidth(s[j, i - j]); if (l > wmax) #Automatic line break (word wrapping) if (sep == -1) if (@x > @l_margin) #Move to next line @x = @l_margin; @y += h; w=@w - @r_margin - @x; wmax=(w - 3 * @c_margin); i += 1 nl += 1 next end if (i == j) i += 1 end Cell(w, h, s[j, (i-1)], 0, 2, '', fill, link); else Cell(w, h, s[j, (sep-j)], 0, 2, '', fill, link); i = sep+1; end sep = -1; j = i; l = 0; if (nl==1) @x = @l_margin; w = @w - @r_margin - @x; wmax = (w - 3 * @c_margin); end nl += 1; else i += 1; end end #Last chunk if (i != j) Cell(GetStringWidth(s[j..i]), h, s[j..i], 0, 0, '', fill, link); end end |
- (Object) writeBarcode(x, y, w, h, type, style, font, xres, code)
3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3392 def writeBarcode(x, y, w, h, type, style, font, xres, code) require(File.dirname(__FILE__) + "/barcode/barcode.rb"); require(File.dirname(__FILE__) + "/barcode/i25object.rb"); require(File.dirname(__FILE__) + "/barcode/c39object.rb"); require(File.dirname(__FILE__) + "/barcode/c128aobject.rb"); require(File.dirname(__FILE__) + "/barcode/c128bobject.rb"); require(File.dirname(__FILE__) + "/barcode/c128cobject.rb"); if (code.empty?) return; end if (style.empty?) style = BCS_ALIGN_LEFT; style |= BCS_IMAGE_PNG; style |= BCS_TRANSPARENT; #:style |= BCS_BORDER; #:style |= BCS_DRAW_TEXT; #:style |= BCS_STRETCH_TEXT; #:style |= BCS_REVERSE_COLOR; end if (font.empty?) then font = BCD_DEFAULT_FONT; end if (xres.empty?) then xres = BCD_DEFAULT_XRES; end scale_factor = 1.5 * xres * @k; bc_w = (w * scale_factor).round #width in points bc_h = (h * scale_factor).round #height in points case (type.upcase) when "I25" obj = I25Object.new(bc_w, bc_h, style, code); when "C128A" obj = C128AObject.new(bc_w, bc_h, style, code); when "C128B" obj = C128BObject.new(bc_w, bc_h, style, code); when "C128C" obj = C128CObject.new(bc_w, bc_h, style, code); when "C39" obj = C39Object.new(bc_w, bc_h, style, code); end obj.SetFont(font); obj.DrawObject(xres); #use a temporary file.... tmpName = tempnam(@@k_path_cache,'img'); imagepng(obj.getImage(), tmpName); Image(tmpName, x, y, w, h, 'png'); obj.DestroyObject(); obj = nil unlink(tmpName); end |
- (Object) writeHTML(html, ln = true, fill = 0, h = 0) Also known as: write_html
Allows to preserve some HTML formatting.<br /> Supports: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, ins, del, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small
3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3464 def writeHTML(html, ln=true, fill=0, h=0) @lasth = h if h > 0 if (@lasth == 0) #set row height @lasth = @font_size * @@k_cell_height_ratio; end @href = nil @style = ""; @t_cells = [[]]; @table_id = 0; # pre calculate html.split(/(<[^>]+>)/).each do |element| if "<" == element[0,1] #Tag if (element[1, 1] == '/') closedHTMLTagCalc(element[2..-2].downcase); else #Extract attributes # get tag name tag = element.scan(/([a-zA-Z0-9]*)/).flatten.delete_if {|x| x.length == 0} tag = tag[0].to_s.downcase; # get attributes attr_array = element.scan(/([^=\s]*)=["\']?([^"\']*)["\']?/) attrs = {} attr_array.each do |name, value| attrs[name.downcase] = value; end openHTMLTagCalc(tag, attrs); end end end @table_id = 0; html.split(/(<[A-Za-z!?\/][^>]*?>)/).each do |element| if "<" == element[0,1] #Tag if (element[1, 1] == '/') closedHTMLTagHandler(element[2..-2].downcase); else #Extract attributes # get tag name tag = element.scan(/([a-zA-Z0-9]*)/).flatten.delete_if {|x| x.length == 0} tag = tag[0].to_s.downcase; # get attributes attr_array = element.scan(/([^=\s]*)=["\']?([^"\']*)["\']?/) attrs = {} attr_array.each do |name, value| attrs[name.downcase] = value; end openHTMLTagHandler(tag, attrs, fill); end else #Text if (@tdbegin) element.gsub!(/[\t\r\n\f]/, ""); @tdtext << element.gsub(/ /, " "); elsif (@href) element.gsub!(/[\t\r\n\f]/, ""); addHtmlLink(@href, element, fill); elsif (@pre_state == true and element.length > 0) Write(@lasth, unhtmlentities(element), '', fill); elsif (element.strip.length > 0) element.gsub!(/[\t\r\n\f]/, ""); element.gsub!(/ /, " "); Write(@lasth, unhtmlentities(element), '', fill); end end end if (ln) Ln(@lasth); end end |
- (Object) writeHTMLCell(w, h, x, y, html = '', border = 0, ln = 1, fill = 0) Also known as: write_html_cell
3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 |
# File 'lib/plugins/rfpdf/lib/tcpdf.rb', line 3559 def writeHTMLCell(w, h, x, y, html='', border=0, ln=1, fill=0) if (@lasth == 0) #set row height @lasth = @font_size * @@k_cell_height_ratio; end if (x == 0) x = GetX(); end if (y == 0) y = GetY(); end # get current page number pagenum = @page; SetX(x); SetY(y); if (w == 0) w = @fw - x - @r_margin; end b=0; if (border) if (border==1) border='LTRB'; b='LRT'; b2='LR'; elsif border.is_a?(String) b2=''; if (border.include?('L')) b2<<'L'; end if (border.include?('R')) b2<<'R'; end b=(border.include?('T')) ? b2 + 'T' : b2; end end # store original margin values l_margin = @l_margin; r_margin = @r_margin; # set new margin values SetLeftMargin(x); SetRightMargin(@fw - x - w); # calculate remaining vertical space on page restspace = GetPageHeight() - GetY() - GetBreakMargin(); writeHTML(html, true, fill); # write html text SetX(x) currentY = GetY(); @auto_page_break = false; # check if a new page has been created if (@page > pagenum) # design a cell around the text on first page currentpage = @page; @page = pagenum; SetY(GetPageHeight() - restspace - GetBreakMargin()); SetX(x) Cell(w, restspace - 1, "", b, 0, 'L', 0); b = b2; @page += 1; while @page < currentpage SetY(@t_margin); # put cursor at the beginning of text SetX(x) Cell(w, @page_break_trigger - @t_margin, "", b, 0, 'L', 0); @page += 1; end if (border.is_a?(String) and border.include?('B')) b<<'B'; end # design a cell around the text on last page SetY(@t_margin); # put cursor at the beginning of text SetX(x) Cell(w, currentY - @t_margin, "", b, 0, 'L', 0); else SetY(y); # put cursor at the beginning of text # design a cell around the text SetX(x) Cell(w, [h, (currentY - y)].max, "", border, 0, 'L', 0); end @auto_page_break = true; # restore original margin values SetLeftMargin(l_margin); SetRightMargin(r_margin); @lasth = h # move cursor to specified position if (ln == 0) # go to the top-right of the cell @x = x + w; @y = y; elsif (ln == 1) # go to the beginning of the next line @x = @l_margin; @y = currentY; elsif (ln == 2) # go to the bottom-left of the cell (below) @x = x; @y = currentY; end end |