Method: TCPDF#initialize

Defined in:
lib/tcpdf.rb

#initialize(orientation = 'P', unit = 'mm', format = 'A4', unicode = true, encoding = "UTF-8", diskcache = false) ⇒ TCPDF

This is the class constructor. It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).

@param string :orientation

page orientation. Possible values are (case insensitive):

  • P or Portrait (default)

  • L or Landscape

@param string :unit

User measure unit. Possible values are:

  • pt: point

  • mm: millimeter (default)

  • cm: centimeter

  • in: inch

A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.

@param mixed :format

The format used for pages. It can be either: A string indicating the page format:

  • 4A0,2A0,A0,A1,A2,A3,A4 (default),A5,A6,A7,A8,A9,A10

  • B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10

  • C0,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10

  • RA0,RA1,RA2,RA3,RA4

  • SRA0,SRA1,SRA2,SRA3,SRA4

  • LETTER,LEGAL,EXECUTIVE,FOLIO

An array containing page measures and advanced options: see setPageFormat()

@param boolean :unicode

TRUE means that the input text is unicode (default = true)

@param String :encoding

charset encoding; default is UTF-8

@param boolean :diskcache

if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).

@access public

Since:

  • 1.0



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/tcpdf.rb', line 233

def initialize(orientation = 'P',  unit = 'mm', format = 'A4', unicode = true, encoding = "UTF-8", diskcache = false)
  
  # Set internal character encoding to ASCII#
  #FIXME 2007-05-25 (EJM) Level=0 - 
  # if (respond_to?("mb_internal_encoding") and mb_internal_encoding())
  #   @internal_encoding = mb_internal_encoding();
  #   mb_internal_encoding("ASCII");
  # }

  @@k_path_cache = Rails.root.join('tmp').to_s
  @@k_path_main = Rails.root.join('tmp').to_s
  @@k_path_url = Rails.root.join('tmp').to_s

  # set disk caching
  @diskcache = diskcache ? true : false
 
  # set language direction
  @rtl = false
  @tmprtl = false

  @x ||= 0 
  @y ||= 0 

  #######################
  @offsets ||= []

  @alias_nb_pages = '{nb}'
  @alias_num_page = '{pnb}'
  @img_scale ||= 1
  @r_margin ||= 0
  @l_margin ||= 0
  @page_annots ||= []

  @header_font ||= ['', '', 10]
  @footer_font ||= ['', '', 8]
  @l ||= {}

  @header_margin ||= 10
  @footer_margin ||= 10

  @barcode ||= false
  @print_header ||= true
  @print_footer ||= true
  @header_width ||= 0
   ||= ""
  @header_logo_width ||= 30
  @header_title ||= ""
  @header_string ||= ""
  @default_table_columns ||= 4
  @listordered ||= []
  @listcount ||= []
  @listindent ||= 0
  @listindentlevel ||= 0
  @lispacer ||= ""

  # bookmark
  @outlines ||= []

  # --- javascript and form ---
  @javascript ||= ''
  @js_objects ||= []

  @dpi = 72.0
  @newpagegroup ||= []
  @pagegroups ||= {}
  @visibility ||= 'all'
  @cell_height_ratio = @@k_cell_height_ratio
  @viewer_preferences ||= {}

  @intmrk ||= []
  @cntmrk ||= []
  @footerpos ||= []
  @footerlen ||= []
  @newline ||= true
  @endlinex ||= 0

  @open_marked_content ||= false
  @htmlvspace ||= 0
  @spot_colors ||= {}
  @lisymbol ||= ''
  @epsmarker ||= 'x#!#EPS#!#x'
  @transfmatrix ||= []
  @transfmatrix_key ||= 0
  @booklet ||= false
  @feps ||= 0.005
  @tagvspaces ||= {}
  @customlistindent ||= -1
  @opencell = true
  @embeddedfiles ||= {}

  @html_link_color_array ||= [0, 0, 255]
  @html_link_font_style ||= 'U'
  @numpages ||= 0
  @pagelen ||= []
  @numimages ||= 0
  @imagekeys ||= []
  @bufferlen ||= 0

  @numfonts ||= 0
  @fontkeys ||= []
  @font_obj_ids ||= {}
  @pageopen ||= []
  @default_monospaced_font = 'courier'


  @cache_file_length = {}
  @thead ||= ''
  @thead_margins ||= {}
  @cache_utf8_string_to_array = {}
  @cache_maxsize_utf8_string_to_array = 8
  @cache_size_utf8_string_to_array = 0
  
  @signature_data ||= {}
  @sig_annot_ref ||= '***SIGANNREF*** 0 R'
  @page_obj_id ||= []
  @embedded_start_obj_id ||= 100000
  @form_obj_id ||= []
  @apxo_start_obj_id ||= 400000
  @apxo_obj_id ||= 400000
  @annotation_fonts ||= {}
  @radiobutton_groups ||= []
  @radio_groups ||= []
  @textindent ||= 0

  @start_transaction_y ||= 0
  @in_thead ||= false
  @columns ||= []
  @num_columns ||= 0
  @current_column ||= 0
  @column_start_page ||= 0

  # Text rendering mode: 
  # 0 = Fill text;
  # 1 =            Stroke text;
  # 2 = Fill, then stroke text;
  # 3 = Neither fill nor stroke text (invisible);
  # 4 =              Fill text and add to path for clipping;
  # 5 =            Stroke text and add to path for clipping;
  # 6 = Fill, then stroke text and add to path for clipping;
  # 7 = Add text to path for clipping.
  @textrendermode ||= 0
  @textstrokewidth ||= 0

  @pdfunit ||= 'mm'
  @tocpage ||= false

  #######################

  #Some checks
  dochecks();
  
  begin
    @@decoder = HTMLEntities.new 
  rescue
    @@decoder = nil
  end
  
  #Initialization of properties
  @is_unicode = unicode
  @page ||= 0
  @transfmrk ||= []
  @pagedim ||= []
  @n ||= 2
  if @diskcache
    @buffer ||= nil
  else
    @buffer ||= ''
  end
  @pages ||= []
  @prev_pages ||= []
  @state ||= 0
  @fonts ||= {}
  @font_files ||= {}
  @diffs ||= []
  @images ||= {}
  @links ||= []
  @gradients ||= []
  @in_footer ||= false
  @lasth ||= 0
  @font_family ||= 'helvetica'
  @font_style ||= ''
  @font_size_pt ||= 12
  @underline ||= false
  @overline ||= false
  @linethrough ||= false
  @draw_color ||= '0 G'
  @fill_color ||= '0 g'
  @text_color ||= '0 g'
  @color_flag ||= false

  # encryption values
  @encrypted ||= false
  @last_enc_key ||= ''
   
  # Standard Unicode fonts
  @core_fonts = {
  'courier'=>'Courier',
  'courierB'=>'Courier-Bold',
  'courierI'=>'Courier-Oblique',
  'courierBI'=>'Courier-BoldOblique',
  'helvetica'=>'Helvetica',
  'helveticaB'=>'Helvetica-Bold',
  'helveticaI'=>'Helvetica-Oblique',
  'helveticaBI'=>'Helvetica-BoldOblique',
  'times'=>'Times-Roman',
  'timesB'=>'Times-Bold',
  'timesI'=>'Times-Italic',
  'timesBI'=>'Times-BoldItalic',
  'symbol'=>'Symbol',
  'zapfdingbats'=>'ZapfDingbats'}

  # Set scale factor
  setPageUnit(unit)
  # set page format and orientation
  setPageFormat(format, orientation)
  # Page margins (1 cm)
  margin = 28.35/@k
  SetMargins(margin, margin)
  #Interior cell margin (1 mm)
  @c_margin = margin / 10
  #Line width (0.2 mm)
  @line_width = 0.57 / @k
  @linestyle_width ||= sprintf('%.2f w', (@line_width * @k))
  @linestyle_cap ||= '0 J'
  @linestyle_join ||= '0 j'
  @linestyle_dash ||= '[] 0 d'
  #Automatic page break
  SetAutoPageBreak(true, 2 * margin)
  #Full width display mode
  SetDisplayMode('fullwidth')
  #Compression
  SetCompression(true)
  #Set default PDF version number
  @pdf_version ||= "1.7"
  @encoding = encoding
  @href ||= {}
  @fontlist ||= []
  getFontsList()
  @fgcolor = ActiveSupport::OrderedHash.new
  @fgcolor['R'] = 0
  @fgcolor['G'] = 0
  @fgcolor['B'] = 0
  @strokecolor = ActiveSupport::OrderedHash.new
  @strokecolor['R'] = 0
  @strokecolor['G'] = 0
  @strokecolor['B'] = 0
  @bgcolor = ActiveSupport::OrderedHash.new
  @bgcolor['R'] = 255
  @bgcolor['G'] = 255
  @bgcolor['B'] = 255
  @extgstates ||= []

  # user's rights
  @sign ||= false
  @ur = false
  @ur_document = "/FullSave"
  @ur_annots = "/Create/Delete/Modify/Copy/Import/Export"
  @ur_form = "/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate"
  @ur_signature = "/Modify"

  # set default JPEG quality
  @jpeg_quality ||= 75

  # initialize some settings
#    utf8Bidi([''], '')
  # set default font
  SetFont(@font_family, @font_style, @font_size_pt)

  @annots_start_obj_id ||= 200000
  @annot_obj_id ||= @annots_start_obj_id
  @curr_annot_obj_id ||= @annots_start_obj_id
  @apxo_obj_id ||= @apxo_start_obj_id
end