Method: FPDF#initialize

Defined in:
lib/fpdf.rb

#initialize(orientation = 'P', unit = 'mm', format = 'A4') ⇒ FPDF

Returns a new instance of FPDF.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/fpdf.rb', line 54

def initialize(orientation='P', unit='mm', format='A4')
    # Initialization of properties
    @page=0
    @n=2
    @buffer=''
    @pages=[]
    @OrientationChanges=[]
    @state=0
    @fonts={}
    @FontFiles={}
    @diffs=[]
    @images={}
    @links=[]
    @PageLinks={}
    @InFooter=false
    @FontFamily=''
    @FontStyle=''
    @FontSizePt=12
    @underline= false
    @DrawColor='0 G'
    @FillColor='0 g'
    @TextColor='0 g'
    @ColorFlag=false
    @ws=0
    @offsets=[]

    # Standard fonts
    @CoreFonts={}
    @CoreFonts['courier']='Courier'
    @CoreFonts['courierB']='Courier-Bold'
    @CoreFonts['courierI']='Courier-Oblique'
    @CoreFonts['courierBI']='Courier-BoldOblique'
    @CoreFonts['helvetica']='Helvetica'
    @CoreFonts['helveticaB']='Helvetica-Bold'
    @CoreFonts['helveticaI']='Helvetica-Oblique'
    @CoreFonts['helveticaBI']='Helvetica-BoldOblique'
    @CoreFonts['times']='Times-Roman'
    @CoreFonts['timesB']='Times-Bold'
    @CoreFonts['timesI']='Times-Italic'
    @CoreFonts['timesBI']='Times-BoldItalic'
    @CoreFonts['symbol']='Symbol'
    @CoreFonts['zapfdingbats']='ZapfDingbats'

    # Scale factor
    if unit=='pt'
        @k=1
    elsif unit=='mm'
        @k=72/25.4
    elsif unit=='cm'
        @k=72/2.54;
    elsif unit=='in'
        @k=72
    else
        raise 'Incorrect unit: '+unit
    end

    # Page format
    if format.is_a? String
        format.downcase!
        if format=='a3'
            format=[841.89,1190.55]
        elsif format=='a4'
            format=[595.28,841.89]
        elsif format=='a5'
            format=[420.94,595.28]
        elsif format=='letter'
            format=[612,792]
        elsif format=='legal'
            format=[612,1008]
        else
            raise 'Unknown page format: '+format
        end
        @fwPt,@fhPt=format
    else
        @fwPt=format[0]*@k
        @fhPt=format[1]*@k
    end
    @fw=@fwPt/@k;
    @fh=@fhPt/@k;

    # Page orientation
    orientation.downcase!
    if orientation=='p' or orientation=='portrait'
        @DefOrientation='P'
        @wPt=@fwPt
        @hPt=@fhPt
    elsif orientation=='l' or orientation=='landscape'
        @DefOrientation='L'
        @wPt=@fhPt
        @hPt=@fwPt
    else
        raise 'Incorrect orientation: '+orientation
    end
    @CurOrientation=@DefOrientation
    @w=@wPt/@k
    @h=@hPt/@k

    # Page margins (1 cm)
    margin=28.35/@k
    SetMargins(margin,margin)
    # Interior cell margin (1 mm)
    @cMargin=margin/10
    # Line width (0.2 mm)
    @LineWidth=0.567/@k
    # Automatic page break
    SetAutoPageBreak(true,2*margin)
    # Full width display mode
    SetDisplayMode('fullwidth')
    # Enable compression
    SetCompression(true)
    # Set default PDF version number
    @PDFVersion='1.3'
end