• We just launched and are currently in beta. Join us as we build and grow the community.

Convert HTML/PHP into PDF using PHP

rafin103

Machine Learning Security Tester
Divine
R Rep
0
0
0
Rep
0
R Vouches
0
0
0
Vouches
0
Posts
168
Likes
112
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this simple code, it will show on how to convert html/php into pdf. just down the file and follow the instructions below.

Creating Our index.php page

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html

    xmlns=

    "http://www.w3.org/1999/xhtml"

    >
  3. <head

    >
  4. <meta

    http-equiv

    =

    "Content-Type"

    content

    =

    "text/html; charset=utf-8"

    /

    >
  5. <title

    >

    Untitled Document</

    title

    >
  6. <script

    src

    =

    "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"

    ></

    script

    >
  7. </

    head

    >
  8. <body

    >


  9. <div

    class

    =

    "floatL cont_lft_side"

    >


  10. <p

    >

    Converting HTML to PDF</

    p

    >


  11. <div

    style

    =

    "width:448px; margin:auto;"

    ></

    div

    >
  12. <form

    method

    =

    "POST"

    action

    =

    "generatePdf.php"

    id

    =

    "frmCtnt"

    name

    =

    "frmCtnt"

    >

  13. <div

    class

    =

    "txt_stl"

    >
  14. <input

    type

    =

    "text"

    value

    =

    "Enter Your Full Name"

    name

    =

    "name"

    onblur

    =

    "if(this.value=='')this.value=this.defaultValue;"

    onfocus

    =

    "if(this.value==this.defaultValue)this.value='';"

    >
  15. </

    div

    >
  16. <br

    >
  17. <div

    class

    =

    "txt_stl"

    >
  18. <input

    type

    =

    "text"

    value

    =

    "Enter Your Email Id"

    name

    =

    "email"

    onblur

    =

    "if(this.value=='')this.value=this.defaultValue;"

    onfocus

    =

    "if(this.value==this.defaultValue)this.value='';"

    >
  19. </

    div

    >
  20. <br

    >
  21. <div

    class

    =

    "txt_stl"

    >
  22. <input

    type

    =

    "text"

    value

    =

    "Enter Your Contact Number"

    name

    =

    "mobile"

    onblur

    =

    "if(this.value=='')this.value=this.defaultValue;"

    onfocus

    =

    "if(this.value==this.defaultValue)this.value='';"

    >
  23. </

    div

    >
  24. <br

    >
  25. <div

    class

    =

    "txt_stl"

    >
  26. <textarea

    onblur

    =

    "if(this.value=='')this.value=this.defaultValue;"

    onfocus

    =

    "if(this.value==this.defaultValue)this.value='';"

    rows

    =

    ""

    cols

    =

    ""

    name

    =

    "comment"

    >

    Please Write your Query or Comment here.</

    textarea

    >
  27. </

    div

    >
  28. <br

    >
  29. <input

    class

    =

    "or_btn_icon"

    type

    =

    "submit"

    value

    =

    "Submit"

    >

  30. </

    form

    >
  31. </

    div

    >



  32. </

    body

    >
  33. </

    html

    >



  34. <script

    type

    =

    "text/javascript"

    >

  35. var _gaq = _gaq || [];
  36. _gaq.push(['_setAccount', 'UA-38304687-1']);
  37. _gaq.push(['_trackPageview']);

  38. (function() {
  39. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  40. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  41. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  42. })();

  43. </

    script

    >

Creating Our fpdf.php page

  1. <?php
  2. /*******************************************************************************
  3. * FPDF *
  4. * *
  5. * Version: 1.7 *
  6. * Date: 2011-06-18 *
  7. * Author: Olivier PLATHEY *
  8. *******************************************************************************/

  9. define

    (

    'FPDF_VERSION'

    ,

    '1.7'

    )

    ;

  10. class

    FPDF
  11. {
  12. var

    $page

    ;

    // current page number
  13. var

    $n

    ;

    // current object number
  14. var

    $offsets

    ;

    // array of object offsets
  15. var

    $buffer

    ;

    // buffer holding in-memory PDF
  16. var

    $pages

    ;

    // array containing pages
  17. var

    $state

    ;

    // current document state
  18. var

    $compress

    ;

    // compression flag
  19. var

    $k

    ;

    // scale factor (number of points in user unit)
  20. var

    $DefOrientation

    ;

    // default orientation
  21. var

    $CurOrientation

    ;

    // current orientation
  22. var

    $StdPageSizes

    ;

    // standard page sizes
  23. var

    $DefPageSize

    ;

    // default page size
  24. var

    $CurPageSize

    ;

    // current page size
  25. var

    $PageSizes

    ;

    // used for pages with non default sizes or orientations
  26. var

    $wPt

    ,

    $hPt

    ;

    // dimensions of current page in points
  27. var

    $w

    ,

    $h

    ;

    // dimensions of current page in user unit
  28. var

    $lMargin

    ;

    // left margin
  29. var

    $tMargin

    ;

    // top margin
  30. var

    $rMargin

    ;

    // right margin
  31. var

    $bMargin

    ;

    // page break margin
  32. var

    $cMargin

    ;

    // cell margin
  33. var

    $x

    ,

    $y

    ;

    // current position in user unit
  34. var

    $lasth

    ;

    // height of last printed cell
  35. var

    $LineWidth

    ;

    // line width in user unit
  36. var

    $fontpath

    ;

    // path containing fonts
  37. var

    $CoreFonts

    ;

    // array of core font names
  38. var

    $fonts

    ;

    // array of used fonts
  39. var

    $FontFiles

    ;

    // array of font files
  40. var

    $diffs

    ;

    // array of encoding differences
  41. var

    $FontFamily

    ;

    // current font family
  42. var

    $FontStyle

    ;

    // current font style
  43. var

    $underline

    ;

    // underlining flag
  44. var

    $CurrentFont

    ;

    // current font info
  45. var

    $FontSizePt

    ;

    // current font size in points
  46. var

    $FontSize

    ;

    // current font size in user unit
  47. var

    $DrawColor

    ;

    // commands for drawing color
  48. var

    $FillColor

    ;

    // commands for filling color
  49. var

    $TextColor

    ;

    // commands for text color
  50. var

    $ColorFlag

    ;

    // indicates whether fill and text colors are different
  51. var

    $ws

    ;

    // word spacing
  52. var

    $images

    ;

    // array of used images
  53. var

    $PageLinks

    ;

    // array of links in pages
  54. var

    $links

    ;

    // array of internal links
  55. var

    $AutoPageBreak

    ;

    // automatic page breaking
  56. var

    $PageBreakTrigger

    ;

    // threshold used to trigger page breaks
  57. var

    $InHeader

    ;

    // flag set when processing header
  58. var

    $InFooter

    ;

    // flag set when processing footer
  59. var

    $ZoomMode

    ;

    // zoom display mode
  60. var

    $LayoutMode

    ;

    // layout display mode
  61. var

    $title

    ;

    // title
  62. var

    $subject

    ;

    // subject
  63. var

    $author

    ;

    // author
  64. var

    $keywords

    ;

    // keywords
  65. var

    $creator

    ;

    // creator
  66. var

    $AliasNbPages

    ;

    // alias for total number of pages
  67. var

    $PDFVersion

    ;

    // PDF version number

  68. /*******************************************************************************
  69. * *
  70. * Public methods *
  71. * *
  72. *******************************************************************************/
  73. function

    FPDF(

    $orientation

    =

    'P'

    ,

    $unit

    =

    'mm'

    ,

    $size

    =

    'A4'

    )
  74. {
  75. // Some checks
  76. $this

    ->

    _dochecks(

    )

    ;
  77. // Initialization of properties
  78. $this

    ->

    page

    =

    0

    ;
  79. $this

    ->

    n

    =

    2

    ;
  80. $this

    ->

    buffer

    =

    ''

    ;
  81. $this

    ->

    pages

    =

    array

    (

    )

    ;
  82. $this

    ->

    PageSizes

    =

    array

    (

    )

    ;
  83. $this

    ->

    state

    =

    0

    ;
  84. $this

    ->

    fonts

    =

    array

    (

    )

    ;
  85. $this

    ->

    FontFiles

    =

    array

    (

    )

    ;
  86. $this

    ->

    diffs

    =

    array

    (

    )

    ;
  87. $this

    ->

    images

    =

    array

    (

    )

    ;
  88. $this

    ->

    links

    =

    array

    (

    )

    ;
  89. $this

    ->

    InHeader

    =

    false

    ;
  90. $this

    ->

    InFooter

    =

    false

    ;
  91. $this

    ->

    lasth

    =

    0

    ;
  92. $this

    ->

    FontFamily

    =

    ''

    ;
  93. $this

    ->

    FontStyle

    =

    ''

    ;
  94. $this

    ->

    FontSizePt

    =

    12

    ;
  95. $this

    ->

    underline

    =

    false

    ;
  96. $this

    ->

    DrawColor

    =

    '0 G'

    ;
  97. $this

    ->

    FillColor

    =

    '0 g'

    ;
  98. $this

    ->

    TextColor

    =

    '0 g'

    ;
  99. $this

    ->

    ColorFlag

    =

    false

    ;
  100. $this

    ->

    ws

    =

    0

    ;
  101. // Font path
  102. if

    (

    defined

    (

    'FPDF_FONTPATH'

    )

    )
  103. {
  104. $this

    ->

    fontpath

    =

    FPDF_FONTPATH;
  105. if

    (

    substr

    (

    $this

    ->

    fontpath

    ,-

    1

    )

    !=

    '/'

    &&

    substr

    (

    $this

    ->

    fontpath

    ,-

    1

    )

    !=

    '\\'

    )
  106. $this

    ->

    fontpath

    .=

    '/'

    ;
  107. }
  108. elseif

    (

    is_dir

    (

    dirname

    (

    __FILE__

    )

    .

    '/font'

    )

    )
  109. $this

    ->

    fontpath

    =

    dirname

    (

    __FILE__

    )

    .

    '/font/'

    ;
  110. else
  111. $this

    ->

    fontpath

    =

    ''

    ;
  112. // Core fonts
  113. $this

    ->

    CoreFonts

    =

    array

    (

    'courier'

    ,

    'helvetica'

    ,

    'times'

    ,

    'symbol'

    ,

    'zapfdingbats'

    )

    ;
  114. // Scale factor
  115. if

    (

    $unit

    ==

    'pt'

    )
  116. $this

    ->

    k

    =

    1

    ;
  117. elseif

    (

    $unit

    ==

    'mm'

    )
  118. $this

    ->

    k

    =

    72

    /

    25.4

    ;
  119. elseif

    (

    $unit

    ==

    'cm'

    )
  120. $this

    ->

    k

    =

    72

    /

    2.54

    ;
  121. elseif

    (

    $unit

    ==

    'in'

    )
  122. $this

    ->

    k

    =

    72

    ;
  123. else
  124. $this

    ->

    Error

    (

    'Incorrect unit: '

    .

    $unit

    )

    ;
  125. // Page sizes
  126. $this

    ->

    StdPageSizes

    =

    array

    (

    'a3'

    =>

    array

    (

    841.89

    ,

    1190.55

    )

    ,

    'a4'

    =>

    array

    (

    595.28

    ,

    841.89

    )

    ,

    'a5'

    =>

    array

    (

    420.94

    ,

    595.28

    )

    ,
  127. 'letter'

    =>

    array

    (

    612

    ,

    792

    )

    ,

    'legal'

    =>

    array

    (

    612

    ,

    1008

    )

    )

    ;
  128. $size

    =

    $this

    ->

    _getpagesize(

    $size

    )

    ;
  129. $this

    ->

    DefPageSize

    =

    $size

    ;
  130. $this

    ->

    CurPageSize

    =

    $size

    ;
  131. // Page orientation
  132. $orientation

    =

    strtolower

    (

    $orientation

    )

    ;
  133. if

    (

    $orientation

    ==

    'p'

    ||

    $orientation

    ==

    'portrait'

    )
  134. {
  135. $this

    ->

    DefOrientation

    =

    'P'

    ;
  136. $this

    ->

    w

    =

    $size

    [

    0

    ]

    ;
  137. $this

    ->

    h

    =

    $size

    [

    1

    ]

    ;
  138. }
  139. elseif

    (

    $orientation

    ==

    'l'

    ||

    $orientation

    ==

    'landscape'

    )
  140. {
  141. $this

    ->

    DefOrientation

    =

    'L'

    ;
  142. $this

    ->

    w

    =

    $size

    [

    1

    ]

    ;
  143. $this

    ->

    h

    =

    $size

    [

    0

    ]

    ;
  144. }
  145. else
  146. $this

    ->

    Error

    (

    'Incorrect orientation: '

    .

    $orientation

    )

    ;
  147. $this

    ->

    CurOrientation

    =

    $this

    ->

    DefOrientation

    ;
  148. $this

    ->

    wPt

    =

    $this

    ->

    w

    *

    $this

    ->

    k

    ;
  149. $this

    ->

    hPt

    =

    $this

    ->

    h

    *

    $this

    ->

    k

    ;
  150. // Page margins (1 cm)
  151. $margin

    =

    28.35

    /

    $this

    ->

    k

    ;
  152. $this

    ->

    SetMargins

    (

    $margin

    ,

    $margin

    )

    ;
  153. // Interior cell margin (1 mm)
  154. $this

    ->

    cMargin

    =

    $margin

    /

    10

    ;
  155. // Line width (0.2 mm)
  156. $this

    ->

    LineWidth

    =

    .567

    /

    $this

    ->

    k

    ;
  157. // Automatic page break
  158. $this

    ->

    SetAutoPageBreak

    (

    true

    ,

    2

    *

    $margin

    )

    ;
  159. // Default display mode
  160. $this

    ->

    SetDisplayMode

    (

    'default'

    )

    ;
  161. // Enable compression
  162. $this

    ->

    SetCompression

    (

    true

    )

    ;
  163. // Set default PDF version number
  164. $this

    ->

    PDFVersion

    =

    '1.3'

    ;
  165. }

  166. function

    SetMargins(

    $left

    ,

    $top

    ,

    $right

    =

    null

    )
  167. {
  168. // Set left, top and right margins
  169. $this

    ->

    lMargin

    =

    $left

    ;
  170. $this

    ->

    tMargin

    =

    $top

    ;
  171. if

    (

    $right

    ===

    null

    )
  172. $right

    =

    $left

    ;
  173. $this

    ->

    rMargin

    =

    $right

    ;
  174. }

  175. function

    SetLeftMargin(

    $margin

    )
  176. {
  177. // Set left margin
  178. $this

    ->

    lMargin

    =

    $margin

    ;
  179. if

    (

    $this

    ->

    page

    >

    0

    &&

    $this

    ->

    x

    <

    $margin

    )
  180. $this

    ->

    x

    =

    $margin

    ;
  181. }

  182. function

    SetTopMargin(

    $margin

    )
  183. {
  184. // Set top margin
  185. $this

    ->

    tMargin

    =

    $margin

    ;
  186. }

  187. function

    SetRightMargin(

    $margin

    )
  188. {
  189. // Set right margin
  190. $this

    ->

    rMargin

    =

    $margin

    ;
  191. }

  192. function

    SetAutoPageBreak(

    $auto

    ,

    $margin

    =

    0

    )
  193. {
  194. // Set auto page break mode and triggering margin
  195. $this

    ->

    AutoPageBreak

    =

    $auto

    ;
  196. $this

    ->

    bMargin

    =

    $margin

    ;
  197. $this

    ->

    PageBreakTrigger

    =

    $this

    ->

    h

    -

    $margin

    ;
  198. }

  199. function

    SetDisplayMode(

    $zoom

    ,

    $layout

    =

    'default'

    )
  200. {
  201. // Set display mode in viewer
  202. if

    (

    $zoom

    ==

    'fullpage'

    ||

    $zoom

    ==

    'fullwidth'

    ||

    $zoom

    ==

    'real'

    ||

    $zoom

    ==

    'default'

    ||

    !

    is_string

    (

    $zoom

    )

    )
  203. $this

    ->

    ZoomMode

    =

    $zoom

    ;
  204. else
  205. $this

    ->

    Error

    (

    'Incorrect zoom display mode: '

    .

    $zoom

    )

    ;
  206. if

    (

    $layout

    ==

    'single'

    ||

    $layout

    ==

    'continuous'

    ||

    $layout

    ==

    'two'

    ||

    $layout

    ==

    'default'

    )
  207. $this

    ->

    LayoutMode

    =

    $layout

    ;
  208. else
  209. $this

    ->

    Error

    (

    'Incorrect layout display mode: '

    .

    $layout

    )

    ;
  210. }

  211. function

    SetCompression(

    $compress

    )
  212. {
  213. // Set page compression
  214. if

    (

    function_exists

    (

    'gzcompress'

    )

    )
  215. $this

    ->

    compress

    =

    $compress

    ;
  216. else
  217. $this

    ->

    compress

    =

    false

    ;
  218. }

  219. function

    SetTitle(

    $title

    ,

    $isUTF8

    =

    false

    )
  220. {
  221. // Title of document
  222. if

    (

    $isUTF8

    )
  223. $title

    =

    $this

    ->

    _UTF8toUTF16(

    $title

    )

    ;
  224. $this

    ->

    title

    =

    $title

    ;
  225. }

  226. function

    SetSubject(

    $subject

    ,

    $isUTF8

    =

    false

    )
  227. {
  228. // Subject of document
  229. if

    (

    $isUTF8

    )
  230. $subject

    =

    $this

    ->

    _UTF8toUTF16(

    $subject

    )

    ;
  231. $this

    ->

    subject

    =

    $subject

    ;
  232. }

  233. function

    SetAuthor(

    $author

    ,

    $isUTF8

    =

    false

    )
  234. {
  235. // Author of document
  236. if

    (

    $isUTF8

    )
  237. $author

    =

    $this

    ->

    _UTF8toUTF16(

    $author

    )

    ;
  238. $this

    ->

    author

    =

    $author

    ;
  239. }

  240. function

    SetKeywords(

    $keywords

    ,

    $isUTF8

    =

    false

    )
  241. {
  242. // Keywords of document
  243. if

    (

    $isUTF8

    )
  244. $keywords

    =

    $this

    ->

    _UTF8toUTF16(

    $keywords

    )

    ;
  245. $this

    ->

    keywords

    =

    $keywords

    ;
  246. }

  247. function

    SetCreator(

    $creator

    ,

    $isUTF8

    =

    false

    )
  248. {
  249. // Creator of document
  250. if

    (

    $isUTF8

    )
  251. $creator

    =

    $this

    ->

    _UTF8toUTF16(

    $creator

    )

    ;
  252. $this

    ->

    creator

    =

    $creator

    ;
  253. }

  254. function

    AliasNbPages(

    $alias

    =

    '{nb}'

    )
  255. {
  256. // Define an alias for total number of pages
  257. $this

    ->

    AliasNbPages

    =

    $alias

    ;
  258. }

  259. function

    Error(

    $msg

    )
  260. {
  261. // Fatal error
  262. die

    (

    '<b>FPDF error:</b> '

    .

    $msg

    )

    ;
  263. }

  264. function

    Open(

    )
  265. {
  266. // Begin document
  267. $this

    ->

    state

    =

    1

    ;
  268. }

  269. function

    Close(

    )
  270. {
  271. // Terminate document
  272. if

    (

    $this

    ->

    state

    ==

    3

    )
  273. return

    ;
  274. if

    (

    $this

    ->

    page

    ==

    0

    )
  275. $this

    ->

    AddPage

    (

    )

    ;
  276. // Page footer
  277. $this

    ->

    InFooter

    =

    true

    ;
  278. $this

    ->

    Footer

    (

    )

    ;
  279. $this

    ->

    InFooter

    =

    false

    ;
  280. // Close page
  281. $this

    ->

    _endpage(

    )

    ;
  282. // Close document
  283. $this

    ->

    _enddoc(

    )

    ;
  284. }

  285. function

    AddPage(

    $orientation

    =

    ''

    ,

    $size

    =

    ''

    )
  286. {
  287. // Start a new page
  288. if

    (

    $this

    ->

    state

    ==

    0

    )
  289. $this

    ->

    Open

    (

    )

    ;
  290. $family

    =

    $this

    ->

    FontFamily

    ;
  291. $style

    =

    $this

    ->

    FontStyle

    .

    (

    $this

    ->

    underline

    ? 'U'

    :

    ''

    )

    ;
  292. $fontsize

    =

    $this

    ->

    FontSizePt

    ;
  293. $lw

    =

    $this

    ->

    LineWidth

    ;
  294. $dc

    =

    $this

    ->

    DrawColor

    ;
  295. $fc

    =

    $this

    ->

    FillColor

    ;
  296. $tc

    =

    $this

    ->

    TextColor

    ;
  297. $cf

    =

    $this

    ->

    ColorFlag

    ;
  298. if

    (

    $this

    ->

    page

    >

    0

    )
  299. {
  300. // Page footer
  301. $this

    ->

    InFooter

    =

    true

    ;
  302. $this

    ->

    Footer

    (

    )

    ;
  303. $this

    ->

    InFooter

    =

    false

    ;
  304. // Close page
  305. $this

    ->

    _endpage(

    )

    ;
  306. }
  307. // Start new page
  308. $this

    ->

    _beginpage(

    $orientation

    ,

    $size

    )

    ;
  309. // Set line cap style to square
  310. $this

    ->

    _out(

    '2 J'

    )

    ;
  311. // Set line width
  312. $this

    ->

    LineWidth

    =

    $lw

    ;
  313. $this

    ->

    _out(

    sprintf

    (

    '%.2F w'

    ,

    $lw

    *

    $this

    ->

    k

    )

    )

    ;
  314. // Set font
  315. if

    (

    $family

    )
  316. $this

    ->

    SetFont

    (

    $family

    ,

    $style

    ,

    $fontsize

    )

    ;
  317. // Set colors
  318. $this

    ->

    DrawColor

    =

    $dc

    ;
  319. if

    (

    $dc

    !=

    '0 G'

    )
  320. $this

    ->

    _out(

    $dc

    )

    ;
  321. $this

    ->

    FillColor

    =

    $fc

    ;
  322. if

    (

    $fc

    !=

    '0 g'

    )
  323. $this

    ->

    _out(

    $fc

    )

    ;
  324. $this

    ->

    TextColor

    =

    $tc

    ;
  325. $this

    ->

    ColorFlag

    =

    $cf

    ;
  326. // Page header
  327. $this

    ->

    InHeader

    =

    true

    ;
  328. $this

    ->

    Header

    (

    )

    ;
  329. $this

    ->

    InHeader

    =

    false

    ;
  330. // Restore line width
  331. if

    (

    $this

    ->

    LineWidth

    !=

    $lw

    )
  332. {
  333. $this

    ->

    LineWidth

    =

    $lw

    ;
  334. $this

    ->

    _out(

    sprintf

    (

    '%.2F w'

    ,

    $lw

    *

    $this

    ->

    k

    )

    )

    ;
  335. }
  336. // Restore font
  337. if

    (

    $family

    )
  338. $this

    ->

    SetFont

    (

    $family

    ,

    $style

    ,

    $fontsize

    )

    ;
  339. // Restore colors
  340. if

    (

    $this

    ->

    DrawColor

    !=

    $dc

    )
  341. {
  342. $this

    ->

    DrawColor

    =

    $dc

    ;
  343. $this

    ->

    _out(

    $dc

    )

    ;
  344. }
  345. if

    (

    $this

    ->

    FillColor

    !=

    $fc

    )
  346. {
  347. $this

    ->

    FillColor

    =

    $fc

    ;
  348. $this

    ->

    _out(

    $fc

    )

    ;
  349. }
  350. $this

    ->

    TextColor

    =

    $tc

    ;
  351. $this

    ->

    ColorFlag

    =

    $cf

    ;
  352. }

  353. function

    Header

    (

    )
  354. {
  355. // To be implemented in your own inherited class
  356. }

  357. function

    Footer(

    )
  358. {
  359. // To be implemented in your own inherited class
  360. }

  361. function

    PageNo(

    )
  362. {
  363. // Get current page number
  364. return

    $this

    ->

    page

    ;
  365. }

  366. function

    SetDrawColor(

    $r

    ,

    $g

    =

    null

    ,

    $b

    =

    null

    )
  367. {
  368. // Set color for all stroking operations
  369. if

    (

    (

    $r

    ==

    0

    &&

    $g

    ==

    0

    &&

    $b

    ==

    0

    )

    ||

    $g

    ===

    null

    )
  370. $this

    ->

    DrawColor

    =

    sprintf

    (

    '%.3F G'

    ,

    $r

    /

    255

    )

    ;
  371. else
  372. $this

    ->

    DrawColor

    =

    sprintf

    (

    '%.3F %.3F %.3F RG'

    ,

    $r

    /

    255

    ,

    $g

    /

    255

    ,

    $b

    /

    255

    )

    ;
  373. if

    (

    $this

    ->

    page

    >

    0

    )
  374. $this

    ->

    _out(

    $this

    ->

    DrawColor

    )

    ;
  375. }

  376. function

    SetFillColor(

    $r

    ,

    $g

    =

    null

    ,

    $b

    =

    null

    )
  377. {
  378. // Set color for all filling operations
  379. if

    (

    (

    $r

    ==

    0

    &&

    $g

    ==

    0

    &&

    $b

    ==

    0

    )

    ||

    $g

    ===

    null

    )
  380. $this

    ->

    FillColor

    =

    sprintf

    (

    '%.3F g'

    ,

    $r

    /

    255

    )

    ;
  381. else
  382. $this

    ->

    FillColor

    =

    sprintf

    (

    '%.3F %.3F %.3F rg'

    ,

    $r

    /

    255

    ,

    $g

    /

    255

    ,

    $b

    /

    255

    )

    ;
  383. $this

    ->

    ColorFlag

    =

    (

    $this

    ->

    FillColor

    !=

    $this

    ->

    TextColor

    )

    ;
  384. if

    (

    $this

    ->

    page

    >

    0

    )
  385. $this

    ->

    _out(

    $this

    ->

    FillColor

    )

    ;
  386. }

  387. function

    SetTextColor(

    $r

    ,

    $g

    =

    null

    ,

    $b

    =

    null

    )
  388. {
  389. // Set color for text
  390. if

    (

    (

    $r

    ==

    0

    &&

    $g

    ==

    0

    &&

    $b

    ==

    0

    )

    ||

    $g

    ===

    null

    )
  391. $this

    ->

    TextColor

    =

    sprintf

    (

    '%.3F g'

    ,

    $r

    /

    255

    )

    ;
  392. else
  393. $this

    ->

    TextColor

    =

    sprintf

    (

    '%.3F %.3F %.3F rg'

    ,

    $r

    /

    255

    ,

    $g

    /

    255

    ,

    $b

    /

    255

    )

    ;
  394. $this

    ->

    ColorFlag

    =

    (

    $this

    ->

    FillColor

    !=

    $this

    ->

    TextColor

    )

    ;
  395. }

  396. function

    GetStringWidth(

    $s

    )
  397. {
  398. // Get width of a string in the current font
  399. $s

    =

    (

    string)

    $s

    ;
  400. $cw

    =

    &

    $this

    ->

    CurrentFont

    [

    'cw'

    ]

    ;
  401. $w

    =

    0

    ;
  402. $l

    =

    strlen

    (

    $s

    )

    ;
  403. for

    (

    $i

    =

    0

    ;

    $i

    <

    $l

    ;

    $i

    ++

    )
  404. $w

    +=

    $cw

    [

    $s

    [

    $i

    ]

    ]

    ;
  405. return

    $w

    *

    $this

    ->

    FontSize

    /

    1000

    ;
  406. }

  407. function

    SetLineWidth(

    $width

    )
  408. {
  409. // Set line width
  410. $this

    ->

    LineWidth

    =

    $width

    ;
  411. if

    (

    $this

    ->

    page

    >

    0

    )
  412. $this

    ->

    _out(

    sprintf

    (

    '%.2F w'

    ,

    $width

    *

    $this

    ->

    k

    )

    )

    ;
  413. }

  414. function

    Line(

    $x1

    ,

    $y1

    ,

    $x2

    ,

    $y2

    )
  415. {
  416. // Draw a line
  417. $this

    ->

    _out(

    sprintf

    (

    '%.2F %.2F m %.2F %.2F l S'

    ,

    $x1

    *

    $this

    ->

    k

    ,

    (

    $this

    ->

    h

    -

    $y1

    )

    *

    $this

    ->

    k

    ,

    $x2

    *

    $this

    ->

    k

    ,

    (

    $this

    ->

    h

    -

    $y2

    )

    *

    $this

    ->

    k

    )

    )

    ;
  418. }

  419. function

    Rect(

    $x

    ,

    $y

    ,

    $w

    ,

    $h

    ,

    $style

    =

    ''

    )
  420. {
  421. // Draw a rectangle
  422. if

    (

    $style

    ==

    'F'

    )
  423. $op

    =

    'f'

    ;
  424. elseif

    (

    $style

    ==

    'FD'

    ||

    $style

    ==

    'DF'

    )
  425. $op

    =

    'B'

    ;
  426. else
  427. $op

    =

    'S'

    ;
  428. $this

    ->

    _out(

    sprintf

    (

    '%.2F %.2F %.2F %.2F re %s'

    ,

    $x

    *

    $this

    ->

    k

    ,

    (

    $this

    ->

    h

    -

    $y

    )

    *

    $this

    ->

    k

    ,

    $w

    *

    $this

    ->

    k

    ,-

    $h

    *

    $this

    ->

    k

    ,

    $op

    )

    )

    ;
  429. }

  430. function

    AddFont(

    $family

    ,

    $style

    =

    ''

    ,

    $file

    =

    ''

    )
  431. {
  432. // Add a TrueType, OpenType or Type1 font
  433. $family

    =

    strtolower

    (

    $family

    )

    ;
  434. if

    (

    $file

    ==

    ''

    )
  435. $file

    =

    str_replace

    (

    ' '

    ,

    ''

    ,

    $family

    )

    .

    strtolower

    (

    $style

    )

    .

    '.php'

    ;
  436. $style

    =

    strtoupper

    (

    $style

    )

    ;
  437. if

    (

    $style

    ==

    'IB'

    )
  438. $style

    =

    'BI'

    ;
  439. $fontkey

    =

    $family

    .

    $style

    ;
  440. if

    (

    isset

    (

    $this

    ->

    fonts

    [

    $fontkey

    ]

    )

    )
  441. return

    ;
  442. $info

    =

    $this

    ->

    _loadfont(

    $file

    )

    ;
  443. $info

    [

    'i'

    ]

    =

    count

    (

    $this

    ->

    fonts

    )

    +

    1

    ;
  444. if

    (

    !

    empty

    (

    $info

    [

    'diff'

    ]

    )

    )
  445. {
  446. // Search existing encodings
  447. $n

    =

    array_search

    (

    $info

    [

    'diff'

    ]

    ,

    $this

    ->

    diffs

    )

    ;
  448. if

    (

    !

    $n

    )
  449. {
  450. $n

    =

    count

    (

    $this

    ->

    diffs

    )

    +

    1

    ;
  451. $this

    ->

    diffs

    [

    $n

    ]

    =

    $info

    [

    'diff'

    ]

    ;
  452. }
  453. $info

    [

    'diffn'

    ]

    =

    $n

    ;
  454. }
  455. if

    (

    !

    empty

    (

    $info

    [

    'file'

    ]

    )

    )
  456. {
  457. // Embedded font
  458. if

    (

    $info

    [

    'type'

    ]

    ==

    'TrueType'

    )
  459. $this

    ->

    FontFiles

    [

    $info

    [

    'file'

    ]

    ]

    =

    array

    (

    'length1'

    =>

    $info

    [

    'originalsize'

    ]

    )

    ;
  460. else
  461. $this

    ->

    FontFiles

    [

    $info

    [

    'file'

    ]

    ]

    =

    array

    (

    'length1'

    =>

    $info

    [

    'size1'

    ]

    ,

    'length2'

    =>

    $info

    [

    'size2'

    ]

    )

    ;
  462. }
  463. $this

    ->

    fonts

    [

    $fontkey

    ]

    =

    $info

    ;
  464. }

  465. function

    SetFont(

    $family

    ,

    $style

    =

    ''

    ,

    $size

    =

    0

    )
  466. {
  467. // Select a font; size given in points
  468. if

    (

    $family

    ==

    ''

    )
  469. $family

    =

    $this

    ->

    FontFamily

    ;
  470. else
  471. $family

    =

    strtolower

    (

    $family

    )

    ;
  472. $style

    =

    strtoupper

    (

    $style

    )

    ;
  473. if

    (

    strpos

    (

    $style

    ,

    'U'

    )

    !==

    false

    )
  474. {
  475. $this

    ->

    underline

    =

    true

    ;
  476. $style

    =

    str_replace

    (

    'U'

    ,

    ''

    ,

    $style

    )

    ;
  477. }
  478. else
  479. $this

    ->

    underline

    =

    false

    ;
  480. if

    (

    $style

    ==

    'IB'

    )
  481. $style

    =

    'BI'

    ;
  482. if

    (

    $size

    ==

    0

    )
  483. $size

    =

    $this

    ->

    FontSizePt

    ;
  484. // Test if font is already selected
  485. if

    (

    $this

    ->

    FontFamily

    ==

    $family

    &&

    $this

    ->

    FontStyle

    ==

    $style

    &&

    $this

    ->

    FontSizePt

    ==

    $size

    )
  486. return

    ;
  487. // Test if font is already loaded
  488. $fontkey

    =

    $family

    .

    $style

    ;
  489. if

    (

    !

    isset

    (

    $this

    ->

    fonts

    [

    $fontkey

    ]

    )

    )
  490. {
  491. // Test if one of the core fonts
  492. if

    (

    $family

    ==

    'arial'

    )
  493. $family

    =

    'helvetica'

    ;
  494. if

    (

    in_array

    (

    $family

    ,

    $this

    ->

    CoreFonts

    )

    )
  495. {
  496. if

    (

    $family

    ==

    'symbol'

    ||

    $family

    ==

    'zapfdingbats'

    )
  497. $style

    =

    ''

    ;
  498. $fontkey

    =

    $family

    .

    $style

    ;
  499. if

    (

    !

    isset

    (

    $this

    ->

    fonts

    [

    $fontkey

    ]

    )

    )
  500. $this

    ->

    AddFont

    (

    $family

    ,

    $style

    )

    ;
  501. }
  502. else
  503. $this

    ->

    Error

    (

    'Undefined font: '

    .

    $family

    .

    ' '

    .

    $style

    )

    ;
  504. }
  505. // Select it
  506. $this

    ->

    FontFamily

    =

    $family

    ;
  507. $this

    ->

    FontStyle

    =

    $style

    ;
  508. $this

    ->

    FontSizePt

    =

    $size

    ;
  509. $this

    ->

    FontSize

    =

    $size

    /

    $this

    ->

    k

    ;
  510. $this

    ->

    CurrentFont

    =

    &

    $this

    ->

    fonts

    [

    $fontkey

    ]

    ;
  511. if

    (

    $this

    ->

    page

    >

    0

    )
  512. $this

    ->

    _out(

    sprintf

    (

    'BT /F%d %.2F Tf ET'

    ,

    $this

    ->

    CurrentFont

    [

    'i'

    ]

    ,

    $this

    ->

    FontSizePt

    )

    )

    ;
  513. }

  514. function

    SetFontSize(

    $size

    )
  515. {
  516. // Set font size in points
  517. if

    (

    $this

    ->

    FontSizePt

    ==

    $size

    )
  518. return

    ;
  519. $this

    ->

    FontSizePt

    =

    $size

    ;
  520. $this

    ->

    FontSize

    =

    $size

    /

    $this

    ->

    k

    ;
  521. if

    (

    $this

    ->

    page

    >

    0

    )
  522. $this

    ->

    _out(

    sprintf

    (

    'BT /F%d %.2F Tf ET'

    ,

    $this

    ->

    CurrentFont

    [

    'i'

    ]

    ,

    $this

    ->

    FontSizePt

    )

    )

    ;
  523. }

  524. function

    AddLink(

    )
  525. {
  526. // Create a new internal link
  527. $n

    =

    count

    (

    $this

    ->

    links

    )

    +

    1

    ;
  528. $this

    ->

    links

    [

    $n

    ]

    =

    array

    (

    0

    ,

    0

    )

    ;
  529. return

    $n

    ;
  530. }

  531. function

    SetLink(

    $link

    ,

    $y

    =

    0

    ,

    $page

    =-

    1

    )
  532. {
  533. // Set destination of internal link
  534. if

    (

    $y

    ==-

    1

    )
  535. $y

    =

    $this

    ->

    y

    ;
  536. if

    (

    $page

    ==-

    1

    )
  537. $page

    =

    $this

    ->

    page

    ;
  538. $this

    ->

    links

    [

    $link

    ]

    =

    array

    (

    $page

    ,

    $y

    )

    ;
  539. }

  540. function

    Link

    (

    $x

    ,

    $y

    ,

    $w

    ,

    $h

    ,

    $link

    )
  541. {
  542. // Put a link on the page
  543. $this

    ->

    PageLinks

    [

    $this

    ->

    page

    ]

    [

    ]

    =

    array

    (

    $x

    *

    $this

    ->

    k

    ,

    $this

    ->

    hPt

    -

    $y

    *

    $this

    ->

    k

    ,

    $w

    *

    $this

    ->

    k

    ,

    $h

    *

    $this

    ->

    k

    ,

    $link

    )

    ;
  544. }

  545. function

    Text(

    $x

    ,

    $y

    ,

    $txt

    )
  546. {
  547. // Output a string
  548. $s

    =

    sprintf

    (

    'BT %.2F %.2F Td (%s) Tj ET'

    ,

    $x

    *

    $this

    ->

    k

    ,

    (

    $this

    ->

    h

    -

    $y

    )

    *

    $this

    ->

    k

    ,

    $this

    ->

    _escape(

    $txt

    )

    )

    ;
  549. if

    (

    $this

    ->

    underline

    &&

    $txt

    !=

    ''

    )
  550. $s

    .=

    ' '

    .

    $this

    ->

    _dounderline(

    $x

    ,

    $y

    ,

    $txt

    )

    ;
  551. if

    (

    $this

    ->

    ColorFlag

    )
  552. $s

    =

    'q '

    .

    $this

    ->

    TextColor

    .

    ' '

    .

    $s

    .

    ' Q'

    ;
  553. $this

    ->

    _out(

    $s

    )

    ;
  554. }

  555. function

    AcceptPageBreak(

    )
  556. {
  557. // Accept automatic page break or not
  558. return

    $this

    ->

    AutoPageBreak

    ;
  559. }

  560. function

    Cell(

    $w

    ,

    $h

    =

    0

    ,

    $txt

    =

    ''

    ,

    $border

    =

    0

    ,

    $ln

    =

    0

    ,

    $align

    =

    ''

    ,

    $fill

    =

    false

    ,

    $link

    =

    ''

    )
  561. {
  562. // Output a cell
  563. $k

    =

    $this

    ->

    k

    ;
  564. if

    (

    $this

    ->

    y

    +

    $h

    >

    $this

    ->

    PageBreakTrigger

    &&

    !

    $this

    ->

    InHeader

    &&

    !

    $this

    ->

    InFooter

    &&

    $this

    ->

    AcceptPageBreak

    (

    )

    )
  565. {
  566. // Automatic page break
  567. $x

    =

    $this

    ->

    x

    ;
  568. $ws

    =

    $this

    ->

    ws

    ;
  569. if

    (

    $ws

    >

    0

    )
  570. {
  571. $this

    ->

    ws

    =

    0

    ;
  572. $this

    ->

    _out(

    '0 Tw'

    )

    ;
  573. }
  574. $this

    ->

    AddPage

    (

    $this

    ->

    CurOrientation

    ,

    $this

    ->

    CurPageSize

    )

    ;
  575. $this

    ->

    x

    =

    $x

    ;
  576. if

    (

    $ws

    >

    0

    )
  577. {
  578. $this

    ->

    ws

    =

    $ws

    ;
  579. $this

    ->

    _out(

    sprintf

    (

    '%.3F Tw'

    ,

    $ws

    *

    $k

    )

    )

    ;
  580. }
  581. }
  582. if

    (

    $w

    ==

    0

    )
  583. $w

    =

    $this

    ->

    w

    -

    $this

    ->

    rMargin

    -

    $this

    ->

    x

    ;
  584. $s

    =

    ''

    ;
  585. if

    (

    $fill

    ||

    $border

    ==

    1

    )
  586. {
  587. if

    (

    $fill

    )
  588. $op

    =

    (

    $border

    ==

    1

    )

    ? 'B'

    :

    'f'

    ;
  589. else
  590. $op

    =

    'S'

    ;
  591. $s

    =

    sprintf

    (

    '%.2F %.2F %.2F %.2F re %s '

    ,

    $this

    ->

    x

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    $this

    ->

    y

    )

    *

    $k

    ,

    $w

    *

    $k

    ,-

    $h

    *

    $k

    ,

    $op

    )

    ;
  592. }
  593. if

    (

    is_string

    (

    $border

    )

    )
  594. {
  595. $x

    =

    $this

    ->

    x

    ;
  596. $y

    =

    $this

    ->

    y

    ;
  597. if

    (

    strpos

    (

    $border

    ,

    'L'

    )

    !==

    false

    )
  598. $s

    .=

    sprintf

    (

    '%.2F %.2F m %.2F %.2F l S '

    ,

    $x

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    $y

    )

    *

    $k

    ,

    $x

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    (

    $y

    +

    $h

    )

    )

    *

    $k

    )

    ;
  599. if

    (

    strpos

    (

    $border

    ,

    'T'

    )

    !==

    false

    )
  600. $s

    .=

    sprintf

    (

    '%.2F %.2F m %.2F %.2F l S '

    ,

    $x

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    $y

    )

    *

    $k

    ,

    (

    $x

    +

    $w

    )

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    $y

    )

    *

    $k

    )

    ;
  601. if

    (

    strpos

    (

    $border

    ,

    'R'

    )

    !==

    false

    )
  602. $s

    .=

    sprintf

    (

    '%.2F %.2F m %.2F %.2F l S '

    ,

    (

    $x

    +

    $w

    )

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    $y

    )

    *

    $k

    ,

    (

    $x

    +

    $w

    )

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    (

    $y

    +

    $h

    )

    )

    *

    $k

    )

    ;
  603. if

    (

    strpos

    (

    $border

    ,

    'B'

    )

    !==

    false

    )
  604. $s

    .=

    sprintf

    (

    '%.2F %.2F m %.2F %.2F l S '

    ,

    $x

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    (

    $y

    +

    $h

    )

    )

    *

    $k

    ,

    (

    $x

    +

    $w

    )

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    (

    $y

    +

    $h

    )

    )

    *

    $k

    )

    ;
  605. }
  606. if

    (

    $txt

    !==

    ''

    )
  607. {
  608. if

    (

    $align

    ==

    'R'

    )
  609. $dx

    =

    $w

    -

    $this

    ->

    cMargin

    -

    $this

    ->

    GetStringWidth

    (

    $txt

    )

    ;
  610. elseif

    (

    $align

    ==

    'C'

    )
  611. $dx

    =

    (

    $w

    -

    $this

    ->

    GetStringWidth

    (

    $txt

    )

    )

    /

    2

    ;
  612. else
  613. $dx

    =

    $this

    ->

    cMargin

    ;
  614. if

    (

    $this

    ->

    ColorFlag

    )
  615. $s

    .=

    'q '

    .

    $this

    ->

    TextColor

    .

    ' '

    ;
  616. $txt2

    =

    str_replace

    (

    ')'

    ,

    '\\)'

    ,

    str_replace

    (

    '('

    ,

    '\\('

    ,

    str_replace

    (

    '\\'

    ,

    '\\\\'

    ,

    $txt

    )

    )

    )

    ;
  617. $s

    .=

    sprintf

    (

    'BT %.2F %.2F Td (%s) Tj ET'

    ,

    (

    $this

    ->

    x

    +

    $dx

    )

    *

    $k

    ,

    (

    $this

    ->

    h

    -

    (

    $this

    ->

    y

    +

    .5

    *

    $h

    +

    .3

    *

    $this

    ->

    FontSize

    )

    )

    *

    $k

    ,

    $txt2

    )

    ;
  618. if

    (

    $this

    ->

    underline

    )
  619. $s

    .=

    ' '

    .

    $this

    ->

    _dounderline(

    $this

    ->

    x

    +

    $dx

    ,

    $this

    ->

    y

    +

    .5

    *

    $h

    +

    .3

    *

    $this

    ->

    FontSize

    ,

    $txt

    )

    ;
  620. if

    (

    $this

    ->

    ColorFlag

    )
  621. $s

    .=

    ' Q'

    ;
  622. if

    (

    $link

    )
  623. $this

    ->

    Link

    (

    $this

    ->

    x

    +

    $dx

    ,

    $this

    ->

    y

    +

    .5

    *

    $h

    -

    .5

    *

    $this

    ->

    FontSize

    ,

    $this

    ->

    GetStringWidth

    (

    $txt

    )

    ,

    $this

    ->

    FontSize

    ,

    $link

    )

    ;
  624. }
  625. if

    (

    $s

    )
  626. $this

    ->

    _out(

    $s

    )

    ;
  627. $this

    ->

    lasth

    =

    $h

    ;
  628. if

    (

    $ln

    >

    0

    )
  629. {
  630. // Go to next line
  631. $this

    ->

    y

    +=

    $h

    ;
  632. if

    (

    $ln

    ==

    1

    )
  633. $this

    ->

    x

    =

    $this

    ->

    lMargin

    ;
  634. }
  635. else
  636. $this

    ->

    x

    +=

    $w

    ;
  637. }

  638. function

    MultiCell(

    $w

    ,

    $h

    ,

    $txt

    ,

    $border

    =

    0

    ,

    $align

    =

    'J'

    ,

    $fill

    =

    false

    )
  639. {
  640. // Output text with automatic or explicit line breaks
  641. $cw

    =

    &

    $this

    ->

    CurrentFont

    [

    'cw'

    ]

    ;
  642. if

    (

    $w

    ==

    0

    )
  643. $w

    =

    $this

    ->

    w

    -

    $this

    ->

    rMargin

    -

    $this

    ->

    x

    ;
  644. $wmax

    =

    (

    $w

    -

    2

    *

    $this

    ->

    cMargin

    )

    *

    1000

    /

    $this

    ->

    FontSize

    ;
  645. $s

    =

    str_replace

    (

    "\r

    "

    ,

    ''

    ,

    $txt

    )

    ;
  646. $nb

    =

    strlen

    (

    $s

    )

    ;
  647. if

    (

    $nb

    >

    0

    &&

    $s

    [

    $nb

    -

    1

    ]

    ==

    "\n

    "

    )
  648. $nb

    --;
  649. $b

    =

    0

    ;
  650. if

    (

    $border

    )
  651. {
  652. if

    (

    $border

    ==

    1

    )
  653. {
  654. $border

    =

    'LTRB'

    ;
  655. $b

    =

    'LRT'

    ;
  656. $b2

    =

    'LR'

    ;
  657. }
  658. else
  659. {
  660. $b2

    =

    ''

    ;
  661. if

    (

    strpos

    (

    $border

    ,

    'L'

    )

    !==

    false

    )
  662. $b2

    .=

    'L'

    ;
  663. if

    (

    strpos

    (

    $border

    ,

    'R'

    )

    !==

    false

    )
  664. $b2

    .=

    'R'

    ;
  665. $b

    =

    (

    strpos

    (

    $border

    ,

    'T'

    )

    !==

    false

    )

    ? $b2

    .

    'T'

    :

    $b2

    ;
  666. }
  667. }
  668. $sep

    =

    -

    1

    ;
  669. $i

    =

    0

    ;
  670. $j

    =

    0

    ;
  671. $l

    =

    0

    ;
  672. $ns

    =

    0

    ;
  673. $nl

    =

    1

    ;
  674. while

    (

    $i

    <

    $nb

    )
  675. {
  676. // Get next character
  677. $c

    =

    $s

    [

    $i

    ]

    ;
  678. if

    (

    $c

    ==

    "\n

    "

    )
  679. {
  680. // Explicit line break
  681. if

    (

    $this

    ->

    ws

    >

    0

    )
  682. {
  683. $this

    ->

    ws

    =

    0

    ;
  684. $this

    ->

    _out(

    '0 Tw'

    )

    ;
  685. }
  686. $this

    ->

    Cell

    (

    $w

    ,

    $h

    ,

    substr

    (

    $s

    ,

    $j

    ,

    $i

    -

    $j

    )

    ,

    $b

    ,

    2

    ,

    $align

    ,

    $fill

    )

    ;
  687. $i

    ++;
  688. $sep

    =

    -

    1

    ;
  689. $j

    =

    $i

    ;
  690. $l

    =

    0

    ;
  691. $ns

    =

    0

    ;
  692. $nl

    ++;
  693. if

    (

    $border

    &&

    $nl

    ==

    2

    )
  694. $b

    =

    $b2

    ;
  695. continue

    ;
  696. }
  697. if

    (

    $c

    ==

    ' '

    )
  698. {
  699. $sep

    =

    $i

    ;
  700. $ls

    =

    $l

    ;
  701. $ns

    ++;
  702. }
  703. $l

    +=

    $cw

    [

    $c

    ]

    ;
  704. if

    (

    $l

    >

    $wmax

    )
  705. {
  706. // Automatic line break
  707. if

    (

    $sep

    ==-

    1

    )
  708. {
  709. if

    (

    $i

    ==

    $j

    )
  710. $i

    ++;
  711. if

    (

    $this

    ->

    ws

    >

    0

    )
  712. {
  713. $this

    ->

    ws

    =

    0

    ;
  714. $this

    ->

    _out(

    '0 Tw'

    )

    ;
  715. }
  716. $this

    ->

    Cell

    (

    $w

    ,

    $h

    ,

    substr

    (

    $s

    ,

    $j

    ,

    $i

    -

    $j

    )

    ,

    $b

    ,

    2

    ,

    $align

    ,

    $fill

    )

    ;
  717. }
  718. else
  719. {
  720. if

    (

    $align

    ==

    'J'

    )
  721. {
  722. $this

    ->

    ws

    =

    (

    $ns

    >

    1

    )

    ? (

    $wmax

    -

    $ls

    )

    /

    1000

    *

    $this

    ->

    FontSize

    /

    (

    $ns

    -

    1

    )

    :

    0

    ;
  723. $this

    ->

    _out(

    sprintf

    (

    '%.3F Tw'

    ,

    $this

    ->

    ws

    *

    $this

    ->

    k

    )

    )

    ;
  724. }
  725. $this

    ->

    Cell

    (

    $w

    ,

    $h

    ,

    substr

    (

    $s

    ,

    $j

    ,

    $sep

    -

    $j

    )

    ,

    $b

    ,

    2

    ,

    $align

    ,

    $fill

    )

    ;
  726. $i

    =

    $sep

    +

    1

    ;
  727. }
  728. $sep

    =

    -

    1

    ;
  729. $j

    =

    $i

    ;
  730. $l

    =

    0

    ;
  731. $ns

    =

    0

    ;
  732. $nl

    ++;
  733. if

    (

    $border

    &&

    $nl

    ==

    2

    )
  734. $b

    =

    $b2

    ;
  735. }
  736. else
  737. $i

    ++;
  738. }
  739. // Last chunk
  740. if

    (

    $this

    ->

    ws

    >

    0

    )
  741. {
  742. $this

    ->

    ws

    =

    0

    ;
  743. $this

    ->

    _out(

    '0 Tw'

    )

    ;
  744. }
  745. if

    (

    $border

    &&

    strpos

    (

    $border

    ,

    'B'

    )

    !==

    false

    )
  746. $b

    .=

    'B'

    ;
  747. $this

    ->

    Cell

    (

    $w

    ,

    $h

    ,

    substr

    (

    $s

    ,

    $j

    ,

    $i

    -

    $j

    )

    ,

    $b

    ,

    2

    ,

    $align

    ,

    $fill

    )

    ;
  748. $this

    ->

    x

    =

    $this

    ->

    lMargin

    ;
  749. }

  750. function

    Write(

    $h

    ,

    $txt

    ,

    $link

    =

    ''

    )
  751. {
  752. // Output text in flowing mode
  753. $cw

    =

    &

    $this

    ->

    CurrentFont

    [

    'cw'

    ]

    ;
  754. $w

    =

    $this

    ->

    w

    -

    $this

    ->

    rMargin

    -

    $this

    ->

    x

    ;
  755. $wmax

    =

    (

    $w

    -

    2

    *

    $this

    ->

    cMargin

    )

    *

    1000

    /

    $this

    ->

    FontSize

    ;
  756. $s

    =

    str_replace

    (

    "\r

    "

    ,

    ''

    ,

    $txt

    )

    ;
  757. $nb

    =

    strlen

    (

    $s

    )

    ;
  758. $sep

    =

    -

    1

    ;
  759. $i

    =

    0

    ;
  760. $j

    =

    0

    ;
  761. $l

    =

    0

    ;
  762. $nl

    =

    1

    ;
  763. while

    (

    $i

    <

    $nb

    )
  764. {
  765. // Get next character
  766. $c

    =

    $s

    [

    $i

    ]

    ;
  767. if

    (

    $c

    ==

    "\n

    "

    )
  768. {
  769. // Explicit line break
  770. $this

    ->

    Cell

    (

    $w

    ,

    $h

    ,

    substr

    (

    $s

    ,

    $j

    ,

    $i

    -

    $j

    )

    ,

    0

    ,

    2

    ,

    ''

    ,

    0

    ,

    $link

    )

    ;
  771. $i

    ++;
  772. $sep

    =

    -

    1

    ;
  773. $j

    =

    $i

    ;
  774. $l

    =

    0

    ;
  775. if

    (

    $nl

    ==

    1

    )
  776. {
  777. $this

    ->

    x

    =

    $this

    ->

    lMargin

    ;
  778. $w

    =

    $this

    ->

    w

    -

    $this

    ->

    rMargin

    -

    $this

    ->

    x

    ;
  779. $wmax

    =

    (

    $w

    -

    2

    *

    $this

    ->

    cMargin

    )

    *

    1000

    /

    $this

    ->

    FontSize

    ;
  780. }
  781. $nl

    ++;
  782. continue

    ;
  783. }
  784. if

    (

    $c

    ==

    ' '

    )
  785. $sep

    =

    $i

    ;
  786. $l

    +=

    $cw

    [

    $c

    ]

    ;
  787. if

    (

    $l

    >

    $wmax

    )
  788. {
  789. // Automatic line break
  790. if

    (

    $sep

    ==-

    1

    )
  791. {
  792. if

    (

    $this

    ->

    x

    >

    $this

    ->

    lMargin

    )
  793. {
  794. // Move to next line
  795. $this

    ->

    x

    =

    $this

    ->

    lMargin

    ;
  796. $this

    ->

    y

    +=

    $h

    ;
  797. $w

    =

    $this

    ->

    w

    -

    $this

    ->

    rMargin

    -

    $this

    ->

    x

    ;
  798. $wmax

    =

    (

    $w

    -

    2

    *

    $this

    ->

    cMargin

    )

    *

    1000

    /

    $this

    ->

    FontSize

    ;
  799. $i

    ++;
  800. $nl

    ++;
  801. continue

    ;
  802. }
  803. if

    (

    $i

    ==

    $j

    )
  804. $i

    ++;
  805. $this

    ->

    Cell

    (

    $w

    ,

    $h

    ,

    substr

    (

    $s

    ,

    $j

    ,

    $i

    -

    $j

    )

    ,

    0

    ,

    2

    ,

    ''

    ,

    0

    ,

    $link

    )

    ;
  806. }
  807. else
  808. {
  809. $this

    ->

    Cell

    (

    $w

    ,

    $h

    ,

    substr

    (

    $s

    ,

    $j

    ,

    $sep

    -

    $j

    )

    ,

    0

    ,

    2

    ,

    ''

    ,

    0

    ,

    $link

    )

    ;
  810. $i

    =

    $sep

    +

    1

    ;
  811. }
  812. $sep

    =

    -

    1

    ;
  813. $j

    =

    $i

    ;
  814. $l

    =

    0

    ;
  815. if

    (

    $nl

    ==

    1

    )
  816. {
  817. $this

    ->

    x

    =

    $this

    ->

    lMargin

    ;
  818. $w

    =

    $this

    ->

    w

    -

    $this

    ->

    rMargin

    -

    $this

    ->

    x

    ;
  819. $wmax

    =

    (

    $w

    -

    2

    *

    $this

    ->

    cMargin

    )

    *

    1000

    /

    $this

    ->

    FontSize

    ;
  820. }
  821. $nl

    ++;
  822. }
  823. else
  824. $i

    ++;
  825. }
  826. // Last chunk
  827. if

    (

    $i

    !=

    $j

    )
  828. $this

    ->

    Cell

    (

    $l

    /

    1000

    *

    $this

    ->

    FontSize

    ,

    $h

    ,

    substr

    (

    $s

    ,

    $j

    )

    ,

    0

    ,

    0

    ,

    ''

    ,

    0

    ,

    $link

    )

    ;
  829. }

  830. function

    Ln(

    $h

    =

    null

    )
  831. {
  832. // Line feed; default value is last cell height
  833. $this

    ->

    x

    =

    $this

    ->

    lMargin

    ;
  834. if

    (

    $h

    ===

    null

    )
  835. $this

    ->

    y

    +=

    $this

    ->

    lasth

    ;
  836. else
  837. $this

    ->

    y

    +=

    $h

    ;
  838. }

  839. function

    Image(

    $file

    ,

    $x

    =

    null

    ,

    $y

    =

    null

    ,

    $w

    =

    0

    ,

    $h

    =

    0

    ,

    $type

    =

    ''

    ,

    $link

    =

    ''

    )
  840. {
  841. // Put an image on the page
  842. if

    (

    !

    isset

    (

    $this

    ->

    images

    [

    $file

    ]

    )

    )
  843. {
  844. // First use of this image, get info
  845. if

    (

    $type

    ==

    ''

    )
  846. {
  847. $pos

    =

    strrpos

    (

    $file

    ,

    '.'

    )

    ;
  848. if

    (

    !

    $pos

    )
  849. $this

    ->

    Error

    (

    'Image file has no extension and no type was specified: '

    .

    $file

    )

    ;
  850. $type

    =

    substr

    (

    $file

    ,

    $pos

    +

    1

    )

    ;
  851. }
  852. $type

    =

    strtolower

    (

    $type

    )

    ;
  853. if

    (

    $type

    ==

    'jpeg'

    )
  854. $type

    =

    'jpg'

    ;
  855. $mtd

    =

    '_parse'

    .

    $type

    ;
  856. if

    (

    !

    method_exists

    (

    $this

    ,

    $mtd

    )

    )
  857. $this

    ->

    Error

    (

    'Unsupported image type: '

    .

    $type

    )

    ;
  858. $info

    =

    $this

    ->

    $mtd

    (

    $file

    )

    ;
  859. $info

    [

    'i'

    ]

    =

    count

    (

    $this

    ->

    images

    )

    +

    1

    ;
  860. $this

    ->

    images

    [

    $file

    ]

    =

    $info

    ;
  861. }
  862. else
  863. $info

    =

    $this

    ->

    images

    [

    $file

    ]

    ;

  864. // Automatic width and height calculation if needed
  865. if

    (

    $w

    ==

    0

    &&

    $h

    ==

    0

    )
  866. {
  867. // Put image at 96 dpi
  868. $w

    =

    -

    96

    ;
  869. $h

    =

    -

    96

    ;
  870. }
  871. if

    (

    $w

    <

    0

    )
  872. $w

    =

    -

    $info

    [

    'w'

    ]

    *

    72

    /

    $w

    /

    $this

    ->

    k

    ;
  873. if

    (

    $h

    <

    0

    )
  874. $h

    =

    -

    $info

    [

    'h'

    ]

    *

    72

    /

    $h

    /

    $this

    ->

    k

    ;
  875. if

    (

    $w

    ==

    0

    )
  876. $w

    =

    $h

    *

    $info

    [

    'w'

    ]

    /

    $info

    [

    'h'

    ]

    ;
  877. if

    (

    $h

    ==

    0

    )
  878. $h

    =

    $w

    *

    $info

    [

    'h'

    ]

    /

    $info

    [

    'w'

    ]

    ;

  879. // Flowing mode
  880. if

    (

    $y

    ===

    null

    )
  881. {
  882. if

    (

    $this

    ->

    y

    +

    $h

    >

    $this

    ->

    PageBreakTrigger

    &&

    !

    $this

    ->

    InHeader

    &&

    !

    $this

    ->

    InFooter

    &&

    $this

    ->

    AcceptPageBreak

    (

    )

    )
  883. {
  884. // Automatic page break
  885. $x2

    =

    $this

    ->

    x

    ;
  886. $this

    ->

    AddPage

    (

    $this

    ->

    CurOrientation

    ,

    $this

    ->

    CurPageSize

    )

    ;
  887. $this

    ->

    x

    =

    $x2

    ;
  888. }
  889. $y

    =

    $this

    ->

    y

    ;
  890. $this

    ->

    y

    +=

    $h

    ;
  891. }

  892. if

    (

    $x

    ===

    null

    )
  893. $x

    =

    $this

    ->

    x

    ;
  894. $this

    ->

    _out(

    sprintf

    (

    'q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q'

    ,

    $w

    *

    $this

    ->

    k

    ,

    $h

    *

    $this

    ->

    k

    ,

    $x

    *

    $this

    ->

    k

    ,

    (

    $this

    ->

    h

    -

    (

    $y

    +

    $h

    )

    )

    *

    $this

    ->

    k

    ,

    $info

    [

    'i'

    ]

    )

    )

    ;
  895. if

    (

    $link

    )
  896. $this

    ->

    Link

    (

    $x

    ,

    $y

    ,

    $w

    ,

    $h

    ,

    $link

    )

    ;
  897. }

  898. function

    GetX(

    )
  899. {
  900. // Get x position
  901. return

    $this

    ->

    x

    ;
  902. }

  903. function

    SetX(

    $x

    )
  904. {
  905. // Set x position
  906. if

    (

    $x

    >=

    0

    )
  907. $this

    ->

    x

    =

    $x

    ;
  908. else
  909. $this

    ->

    x

    =

    $this

    ->

    w

    +

    $x

    ;
  910. }

  911. function

    GetY(

    )
  912. {
  913. // Get y position
  914. return

    $this

    ->

    y

    ;
  915. }

  916. function

    SetY(

    $y

    )
  917. {
  918. // Set y position and reset x
  919. $this

    ->

    x

    =

    $this

    ->

    lMargin

    ;
  920. if

    (

    $y

    >=

    0

    )
  921. $this

    ->

    y

    =

    $y

    ;
  922. else
  923. $this

    ->

    y

    =

    $this

    ->

    h

    +

    $y

    ;
  924. }

  925. function

    SetXY(

    $x

    ,

    $y

    )
  926. {
  927. // Set x and y positions
  928. $this

    ->

    SetY

    (

    $y

    )

    ;
  929. $this

    ->

    SetX

    (

    $x

    )

    ;
  930. }

  931. function

    Output(

    $name

    =

    ''

    ,

    $dest

    =

    ''

    )
  932. {
  933. // Output PDF to some destination
  934. if

    (

    $this

    ->

    state

    <

    3

    )
  935. $this

    ->

    Close

    (

    )

    ;
  936. $dest

    =

    strtoupper

    (

    $dest

    )

    ;
  937. if

    (

    $dest

    ==

    ''

    )
  938. {
  939. if

    (

    $name

    ==

    ''

    )
  940. {
  941. $name

    =

    'doc.pdf'

    ;
  942. $dest

    =

    'I'

    ;
  943. }
  944. else
  945. $dest

    =

    'F'

    ;
  946. }
  947. switch

    (

    $dest

    )
  948. {
  949. case

    'I'

    :
  950. // Send to standard output
  951. $this

    ->

    _checkoutput(

    )

    ;
  952. if

    (

    PHP_SAPI!=

    'cli'

    )
  953. {
  954. // We send to a browser
  955. header

    (

    'Content-Type: application/pdf'

    )

    ;
  956. header

    (

    'Content-Disposition: inline; filename="'

    .

    $name

    .

    '"'

    )

    ;
  957. header

    (

    'Cache-Control: private, max-age=0, must-revalidate'

    )

    ;
  958. header

    (

    'Pragma: public'

    )

    ;
  959. }
  960. echo

    $this

    ->

    buffer

    ;
  961. break

    ;
  962. case

    'D'

    :
  963. // Download file
  964. $this

    ->

    _checkoutput(

    )

    ;
  965. header

    (

    'Content-Type: application/x-download'

    )

    ;
  966. header

    (

    'Content-Disposition: attachment; filename="'

    .

    $name

    .

    '"'

    )

    ;
  967. header

    (

    'Cache-Control: private, max-age=0, must-revalidate'

    )

    ;
  968. header

    (

    'Pragma: public'

    )

    ;
  969. echo

    $this

    ->

    buffer

    ;
  970. break

    ;
  971. case

    'F'

    :
  972. // Save to local file
  973. $f

    =

    fopen

    (

    $name

    ,

    'wb'

    )

    ;
  974. if

    (

    !

    $f

    )
  975. $this

    ->

    Error

    (

    'Unable to create output file: '

    .

    $name

    )

    ;
  976. fwrite

    (

    $f

    ,

    $this

    ->

    buffer

    ,

    strlen

    (

    $this

    ->

    buffer

    )

    )

    ;
  977. fclose

    (

    $f

    )

    ;
  978. break

    ;
  979. case

    'S'

    :
  980. // Return as a string
  981. return

    $this

    ->

    buffer

    ;
  982. default

    :
  983. $this

    ->

    Error

    (

    'Incorrect output destination: '

    .

    $dest

    )

    ;
  984. }
  985. return

    ''

    ;
  986. }

  987. /*******************************************************************************
  988. * *
  989. * Protected methods *
  990. * *
  991. *******************************************************************************/
  992. function

    _dochecks(

    )
  993. {
  994. // Check availability of %F
  995. if

    (

    sprintf

    (

    '%.1F'

    ,

    1.0

    )

    !=

    '1.0'

    )
  996. $this

    ->

    Error

    (

    'This version of PHP is not supported'

    )

    ;
  997. // Check mbstring overloading
  998. if

    (

    ini_get

    (

    'mbstring.func_overload'

    )

    &

    2

    )
  999. $this

    ->

    Error

    (

    'mbstring overloading must be disabled'

    )

    ;
  1000. // Ensure runtime magic quotes are disabled
  1001. if

    (

    get_magic_quotes_runtime

    (

    )

    )
  1002. @

    set_magic_quotes_runtime

    (

    0

    )

    ;
  1003. }

  1004. function

    _checkoutput(

    )
  1005. {
  1006. if

    (

    PHP_SAPI!=

    'cli'

    )
  1007. {
  1008. if

    (

    headers_sent

    (

    $file

    ,

    $line

    )

    )
  1009. $this

    ->

    Error

    (

    "Some data has already been output, can't send PDF file (output started at $file

    :$line

    )"

    )

    ;
  1010. }
  1011. if

    (

    ob_get_length

    (

    )

    )
  1012. {
  1013. // The output buffer is not empty
  1014. if

    (

    preg_match

    (

    '/^(\xEF\xBB\xBF)?\s*$/'

    ,

    ob_get_contents

    (

    )

    )

    )
  1015. {
  1016. // It contains only a UTF-8 BOM and/or whitespace, let's clean it
  1017. ob_clean

    (

    )

    ;
  1018. }
  1019. else
  1020. $this

    ->

    Error

    (

    "Some data has already been output, can't send PDF file"

    )

    ;
  1021. }
  1022. }

  1023. function

    _getpagesize(

    $size

    )
  1024. {
  1025. if

    (

    is_string

    (

    $size

    )

    )
  1026. {
  1027. $size

    =

    strtolower

    (

    $size

    )

    ;
  1028. if

    (

    !

    isset

    (

    $this

    ->

    StdPageSizes

    [

    $size

    ]

    )

    )
  1029. $this

    ->

    Error

    (

    'Unknown page size: '

    .

    $size

    )

    ;
  1030. $a

    =

    $this

    ->

    StdPageSizes

    [

    $size

    ]

    ;
  1031. return

    array

    (

    $a

    [

    0

    ]

    /

    $this

    ->

    k

    ,

    $a

    [

    1

    ]

    /

    $this

    ->

    k

    )

    ;
  1032. }
  1033. else
  1034. {
  1035. if

    (

    $size

    [

    0

    ]

    >

    $size

    [

    1

    ]

    )
  1036. return

    array

    (

    $size

    [

    1

    ]

    ,

    $size

    [

    0

    ]

    )

    ;
  1037. else
  1038. return

    $size

    ;
  1039. }
  1040. }

  1041. function

    _beginpage(

    $orientation

    ,

    $size

    )
  1042. {
  1043. $this

    ->

    page

    ++;
  1044. $this

    ->

    pages

    [

    $this

    ->

    page

    ]

    =

    ''

    ;
  1045. $this

    ->

    state

    =

    2

    ;
  1046. $this

    ->

    x

    =

    $this

    ->

    lMargin

    ;
  1047. $this

    ->

    y

    =

    $this

    ->

    tMargin

    ;
  1048. $this

    ->

    FontFamily

    =

    ''

    ;
  1049. // Check page size and orientation
  1050. if

    (

    $orientation

    ==

    ''

    )
  1051. $orientation

    =

    $this

    ->

    DefOrientation

    ;
  1052. else
  1053. $orientation

    =

    strtoupper

    (

    $orientation

    [

    0

    ]

    )

    ;
  1054. if

    (

    $size

    ==

    ''

    )
  1055. $size

    =

    $this

    ->

    DefPageSize

    ;
  1056. else
  1057. $size

    =

    $this

    ->

    _getpagesize(

    $size

    )

    ;
  1058. if

    (

    $orientation

    !=

    $this

    ->

    CurOrientation

    ||

    $size

    [

    0

    ]

    !=

    $this

    ->

    CurPageSize

    [

    0

    ]

    ||

    $size

    [

    1

    ]

    !=

    $this

    ->

    CurPageSize

    [

    1

    ]

    )
  1059. {
  1060. // New size or orientation
  1061. if

    (

    $orientation

    ==

    'P'

    )
  1062. {
  1063. $this

    ->

    w

    =

    $size

    [

    0

    ]

    ;
  1064. $this

    ->

    h

    =

    $size

    [

    1

    ]

    ;
  1065. }
  1066. else
  1067. {
  1068. $this

    ->

    w

    =

    $size

    [

    1

    ]

    ;
  1069. $this

    ->

    h

    =

    $size

    [

    0

    ]

    ;
  1070. }
  1071. $this

    ->

    wPt

    =

    $this

    ->

    w

    *

    $this

    ->

    k

    ;
  1072. $this

    ->

    hPt

    =

    $this

    ->

    h

    *

    $this

    ->

    k

    ;
  1073. $this

    ->

    PageBreakTrigger

    =

    $this

    ->

    h

    -

    $this

    ->

    bMargin

    ;
  1074. $this

    ->

    CurOrientation

    =

    $orientation

    ;
  1075. $this

    ->

    CurPageSize

    =

    $size

    ;
  1076. }
  1077. if

    (

    $orientation

    !=

    $this

    ->

    DefOrientation

    ||

    $size

    [

    0

    ]

    !=

    $this

    ->

    DefPageSize

    [

    0

    ]

    ||

    $size

    [

    1

    ]

    !=

    $this

    ->

    DefPageSize

    [

    1

    ]

    )
  1078. $this

    ->

    PageSizes

    [

    $this

    ->

    page

    ]

    =

    array

    (

    $this

    ->

    wPt

    ,

    $this

    ->

    hPt

    )

    ;
  1079. }

  1080. function

    _endpage(

    )
  1081. {
  1082. $this

    ->

    state

    =

    1

    ;
  1083. }

  1084. function

    _loadfont(

    $font

    )
  1085. {
  1086. // Load a font definition file from the font directory
  1087. include

    (

    $this

    ->

    fontpath

    .

    $font

    )

    ;
  1088. $a

    =

    get_defined_vars

    (

    )

    ;
  1089. if

    (

    !

    isset

    (

    $a

    [

    'name'

    ]

    )

    )
  1090. $this

    ->

    Error

    (

    'Could not include font definition file'

    )

    ;
  1091. return

    $a

    ;
  1092. }

  1093. function

    _escape(

    $s

    )
  1094. {
  1095. // Escape special characters in strings
  1096. $s

    =

    str_replace

    (

    '\\'

    ,

    '\\\\'

    ,

    $s

    )

    ;
  1097. $s

    =

    str_replace

    (

    '('

    ,

    '\\('

    ,

    $s

    )

    ;
  1098. $s

    =

    str_replace

    (

    ')'

    ,

    '\\)'

    ,

    $s

    )

    ;
  1099. $s

    =

    str_replace

    (

    "\r

    "

    ,

    '\\r'

    ,

    $s

    )

    ;
  1100. return

    $s

    ;
  1101. }

  1102. function

    _textstring(

    $s

    )
  1103. {
  1104. // Format a text string
  1105. return

    '('

    .

    $this

    ->

    _escape(

    $s

    )

    .

    ')'

    ;
  1106. }

  1107. function

    _UTF8toUTF16(

    $s

    )
  1108. {
  1109. // Convert UTF-8 to UTF-16BE with BOM
  1110. $res

    =

    "\xFE

    \xFF

    "

    ;
  1111. $nb

    =

    strlen

    (

    $s

    )

    ;
  1112. $i

    =

    0

    ;
  1113. while

    (

    $i

    <

    $nb

    )
  1114. {
  1115. $c1

    =

    ord

    (

    $s

    [

    $i

    ++

    ]

    )

    ;
  1116. if

    (

    $c1

    >=

    224

    )
  1117. {
  1118. // 3-byte character
  1119. $c2

    =

    ord

    (

    $s

    [

    $i

    ++

    ]

    )

    ;
  1120. $c3

    =

    ord

    (

    $s

    [

    $i

    ++

    ]

    )

    ;
  1121. $res

    .=

    chr

    (

    (

    (

    $c1

    &

    0x0F

    )

    <<

    4

    )

    +

    (

    (

    $c2

    &

    0x3C

    )

    >>

    2

    )

    )

    ;
  1122. $res

    .=

    chr

    (

    (

    (

    $c2

    &

    0x03

    )

    <<

    6

    )

    +

    (

    $c3

    &

    0x3F

    )

    )

    ;
  1123. }
  1124. elseif

    (

    $c1

    >=

    192

    )
  1125. {
  1126. // 2-byte character
  1127. $c2

    =

    ord

    (

    $s

    [

    $i

    ++

    ]

    )

    ;
  1128. $res

    .=

    chr

    (

    (

    $c1

    &

    0x1C

    )

    >>

    2

    )

    ;
  1129. $res

    .=

    chr

    (

    (

    (

    $c1

    &

    0x03

    )

    <<

    6

    )

    +

    (

    $c2

    &

    0x3F

    )

    )

    ;
  1130. }
  1131. else
  1132. {
  1133. // Single-byte character
  1134. $res

    .=

    "\0

    "

    .

    chr

    (

    $c1

    )

    ;
  1135. }
  1136. }
  1137. return

    $res

    ;
  1138. }

  1139. function

    _dounderline(

    $x

    ,

    $y

    ,

    $txt

    )
  1140. {
  1141. // Underline text
  1142. $up

    =

    $this

    ->

    CurrentFont

    [

    'up'

    ]

    ;
  1143. $ut

    =

    $this

    ->

    CurrentFont

    [

    'ut'

    ]

    ;
  1144. $w

    =

    $this

    ->

    GetStringWidth

    (

    $txt

    )

    +

    $this

    ->

    ws

    *

    substr_count

    (

    $txt

    ,

    ' '

    )

    ;
  1145. return

    sprintf

    (

    '%.2F %.2F %.2F %.2F re f'

    ,

    $x

    *

    $this

    ->

    k

    ,

    (

    $this

    ->

    h

    -

    (

    $y

    -

    $up

    /

    1000

    *

    $this

    ->

    FontSize

    )

    )

    *

    $this

    ->

    k

    ,

    $w

    *

    $this

    ->

    k

    ,-

    $ut

    /

    1000

    *

    $this

    ->

    FontSizePt

    )

    ;
  1146. }

  1147. function

    _parsejpg(

    $file

    )
  1148. {
  1149. // Extract info from a JPEG file
  1150. $a

    =

    getimagesize

    (

    $file

    )

    ;
  1151. if

    (

    !

    $a

    )
  1152. $this

    ->

    Error

    (

    'Missing or incorrect image file: '

    .

    $file

    )

    ;
  1153. if

    (

    $a

    [

    2

    ]

    !=

    2

    )
  1154. $this

    ->

    Error

    (

    'Not a JPEG file: '

    .

    $file

    )

    ;
  1155. if

    (

    !

    isset

    (

    $a

    [

    'channels'

    ]

    )

    ||

    $a

    [

    'channels'

    ]

    ==

    3

    )
  1156. $colspace

    =

    'DeviceRGB'

    ;
  1157. elseif

    (

    $a

    [

    'channels'

    ]

    ==

    4

    )
  1158. $colspace

    =

    'DeviceCMYK'

    ;
  1159. else
  1160. $colspace

    =

    'DeviceGray'

    ;
  1161. $bpc

    =

    isset

    (

    $a

    [

    'bits'

    ]

    )

    ? $a

    [

    'bits'

    ]

    :

    8

    ;
  1162. $data

    =

    file_get_contents

    (

    $file

    )

    ;
  1163. return

    array

    (

    'w'

    =>

    $a

    [

    0

    ]

    ,

    'h'

    =>

    $a

    [

    1

    ]

    ,

    'cs'

    =>

    $colspace

    ,

    'bpc'

    =>

    $bpc

    ,

    'f'

    =>

    'DCTDecode'

    ,

    'data'

    =>

    $data

    )

    ;
  1164. }

  1165. function

    _parsepng(

    $file

    )
  1166. {
  1167. // Extract info from a PNG file
  1168. $f

    =

    fopen

    (

    $file

    ,

    'rb'

    )

    ;
  1169. if

    (

    !

    $f

    )
  1170. $this

    ->

    Error

    (

    'Can\'t open image file: '

    .

    $file

    )

    ;
  1171. $info

    =

    $this

    ->

    _parsepngstream(

    $f

    ,

    $file

    )

    ;
  1172. fclose

    (

    $f

    )

    ;
  1173. return

    $info

    ;
  1174. }

  1175. function

    _parsepngstream(

    $f

    ,

    $file

    )
  1176. {
  1177. // Check signature
  1178. if

    (

    $this

    ->

    _readstream(

    $f

    ,

    8

    )

    !=

    chr

    (

    137

    )

    .

    'PNG'

    .

    chr

    (

    13

    )

    .

    chr

    (

    10

    )

    .

    chr

    (

    26

    )

    .

    chr

    (

    10

    )

    )
  1179. $this

    ->

    Error

    (

    'Not a PNG file: '

    .

    $file

    )

    ;

  1180. // Read header chunk
  1181. $this

    ->

    _readstream(

    $f

    ,

    4

    )

    ;
  1182. if

    (

    $this

    ->

    _readstream(

    $f

    ,

    4

    )

    !=

    'IHDR'

    )
  1183. $this

    ->

    Error

    (

    'Incorrect PNG file: '

    .

    $file

    )

    ;
  1184. $w

    =

    $this

    ->

    _readint(

    $f

    )

    ;
  1185. $h

    =

    $this

    ->

    _readint(

    $f

    )

    ;
  1186. $bpc

    =

    ord

    (

    $this

    ->

    _readstream(

    $f

    ,

    1

    )

    )

    ;
  1187. if

    (

    $bpc

    >

    8

    )
  1188. $this

    ->

    Error

    (

    '16-bit depth not supported: '

    .

    $file

    )

    ;
  1189. $ct

    =

    ord

    (

    $this

    ->

    _readstream(

    $f

    ,

    1

    )

    )

    ;
  1190. if

    (

    $ct

    ==

    0

    ||

    $ct

    ==

    4

    )
  1191. $colspace

    =

    'DeviceGray'

    ;
  1192. elseif

    (

    $ct

    ==

    2

    ||

    $ct

    ==

    6

    )
  1193. $colspace

    =

    'DeviceRGB'

    ;
  1194. elseif

    (

    $ct

    ==

    3

    )
  1195. $colspace

    =

    'Indexed'

    ;
  1196. else
  1197. $this

    ->

    Error

    (

    'Unknown color type: '

    .

    $file

    )

    ;
  1198. if

    (

    ord

    (

    $this

    ->

    _readstream(

    $f

    ,

    1

    )

    )

    !=

    0

    )
  1199. $this

    ->

    Error

    (

    'Unknown compression method: '

    .

    $file

    )

    ;
  1200. if

    (

    ord

    (

    $this

    ->

    _readstream(

    $f

    ,

    1

    )

    )

    !=

    0

    )
  1201. $this

    ->

    Error

    (

    'Unknown filter method: '

    .

    $file

    )

    ;
  1202. if

    (

    ord

    (

    $this

    ->

    _readstream(

    $f

    ,

    1

    )

    )

    !=

    0

    )
  1203. $this

    ->

    Error

    (

    'Interlacing not supported: '

    .

    $file

    )

    ;
  1204. $this

    ->

    _readstream(

    $f

    ,

    4

    )

    ;
  1205. $dp

    =

    '/Predictor 15 /Colors '

    .

    (

    $colspace

    ==

    'DeviceRGB'

    ? 3

    :

    1

    )

    .

    ' /BitsPerComponent '

    .

    $bpc

    .

    ' /Columns '

    .

    $w

    ;

  1206. // Scan chunks looking for palette, transparency and image data
  1207. $pal

    =

    ''

    ;
  1208. $trns

    =

    ''

    ;
  1209. $data

    =

    ''

    ;
  1210. do
  1211. {
  1212. $n

    =

    $this

    ->

    _readint(

    $f

    )

    ;
  1213. $type

    =

    $this

    ->

    _readstream(

    $f

    ,

    4

    )

    ;
  1214. if

    (

    $type

    ==

    'PLTE'

    )
  1215. {
  1216. // Read palette
  1217. $pal

    =

    $this

    ->

    _readstream(

    $f

    ,

    $n

    )

    ;
  1218. $this

    ->

    _readstream(

    $f

    ,

    4

    )

    ;
  1219. }
  1220. elseif

    (

    $type

    ==

    'tRNS'

    )
  1221. {
  1222. // Read transparency info
  1223. $t

    =

    $this

    ->

    _readstream(

    $f

    ,

    $n

    )

    ;
  1224. if

    (

    $ct

    ==

    0

    )
  1225. $trns

    =

    array

    (

    ord

    (

    substr

    (

    $t

    ,

    1

    ,

    1

    )

    )

    )

    ;
  1226. elseif

    (

    $ct

    ==

    2

    )
  1227. $trns

    =

    array

    (

    ord

    (

    substr

    (

    $t

    ,

    1

    ,

    1

    )

    )

    ,

    ord

    (

    substr

    (

    $t

    ,

    3

    ,

    1

    )

    )

    ,

    ord

    (

    substr

    (

    $t

    ,

    5

    ,

    1

    )

    )

    )

    ;
  1228. else
  1229. {
  1230. $pos

    =

    strpos

    (

    $t

    ,

    chr

    (

    0

    )

    )

    ;
  1231. if

    (

    $pos

    !==

    false

    )
  1232. $trns

    =

    array

    (

    $pos

    )

    ;
  1233. }
  1234. $this

    ->

    _readstream(

    $f

    ,

    4

    )

    ;
  1235. }
  1236. elseif

    (

    $type

    ==

    'IDAT'

    )
  1237. {
  1238. // Read image data block
  1239. $data

    .=

    $this

    ->

    _readstream(

    $f

    ,

    $n

    )

    ;
  1240. $this

    ->

    _readstream(

    $f

    ,

    4

    )

    ;
  1241. }
  1242. elseif

    (

    $type

    ==

    'IEND'

    )
  1243. break

    ;
  1244. else
  1245. $this

    ->

    _readstream(

    $f

    ,

    $n

    +

    4

    )

    ;
  1246. }
  1247. while

    (

    $n

    )

    ;

  1248. if

    (

    $colspace

    ==

    'Indexed'

    &&

    empty

    (

    $pal

    )

    )
  1249. $this

    ->

    Error

    (

    'Missing palette in '

    .

    $file

    )

    ;
  1250. $info

    =

    array

    (

    'w'

    =>

    $w

    ,

    'h'

    =>

    $h

    ,

    'cs'

    =>

    $colspace

    ,

    'bpc'

    =>

    $bpc

    ,

    'f'

    =>

    'FlateDecode'

    ,

    'dp'

    =>

    $dp

    ,

    'pal'

    =>

    $pal

    ,

    'trns'

    =>

    $trns

    )

    ;
  1251. if

    (

    $ct

    >=

    4

    )
  1252. {
  1253. // Extract alpha channel
  1254. if

    (

    !

    function_exists

    (

    'gzuncompress'

    )

    )
  1255. $this

    ->

    Error

    (

    'Zlib not available, can\'t handle alpha channel: '

    .

    $file

    )

    ;
  1256. $data

    =

    gzuncompress

    (

    $data

    )

    ;
  1257. $color

    =

    ''

    ;
  1258. $alpha

    =

    ''

    ;
  1259. if

    (

    $ct

    ==

    4

    )
  1260. {
  1261. // Gray image
  1262. $len

    =

    2

    *

    $w

    ;
  1263. for

    (

    $i

    =

    0

    ;

    $i

    <

    $h

    ;

    $i

    ++

    )
  1264. {
  1265. $pos

    =

    (

    1

    +

    $len

    )

    *

    $i

    ;
  1266. $color

    .=

    $data

    [

    $pos

    ]

    ;
  1267. $alpha

    .=

    $data

    [

    $pos

    ]

    ;
  1268. $line

    =

    substr

    (

    $data

    ,

    $pos

    +

    1

    ,

    $len

    )

    ;
  1269. $color

    .=

    preg_replace

    (

    '/(.)./s'

    ,

    '$1'

    ,

    $line

    )

    ;
  1270. $alpha

    .=

    preg_replace

    (

    '/.(.)/s'

    ,

    '$1'

    ,

    $line

    )

    ;
  1271. }
  1272. }
  1273. else
  1274. {
  1275. // RGB image
  1276. $len

    =

    4

    *

    $w

    ;
  1277. for

    (

    $i

    =

    0

    ;

    $i

    <

    $h

    ;

    $i

    ++

    )
  1278. {
  1279. $pos

    =

    (

    1

    +

    $len

    )

    *

    $i

    ;
  1280. $color

    .=

    $data

    [

    $pos

    ]

    ;
  1281. $alpha

    .=

    $data

    [

    $pos

    ]

    ;
  1282. $line

    =

    substr

    (

    $data

    ,

    $pos

    +

    1

    ,

    $len

    )

    ;
  1283. $color

    .=

    preg_replace

    (

    '/(.{3})./s'

    ,

    '$1'

    ,

    $line

    )

    ;
  1284. $alpha

    .=

    preg_replace

    (

    '/.{3}(.)/s'

    ,

    '$1'

    ,

    $line

    )

    ;
  1285. }
  1286. }
  1287. unset

    (

    $data

    )

    ;
  1288. $data

    =

    gzcompress

    (

    $color

    )

    ;
  1289. $info

    [

    'smask'

    ]

    =

    gzcompress

    (

    $alpha

    )

    ;
  1290. if

    (

    $this

    ->

    PDFVersion

    <

    '1.4'

    )
  1291. $this

    ->

    PDFVersion

    =

    '1.4'

    ;
  1292. }
  1293. $info

    [

    'data'

    ]

    =

    $data

    ;
  1294. return

    $info

    ;
  1295. }

  1296. function

    _readstream(

    $f

    ,

    $n

    )
  1297. {
  1298. // Read n bytes from stream
  1299. $res

    =

    ''

    ;
  1300. while

    (

    $n

    >

    0

    &&

    !

    feof

    (

    $f

    )

    )
  1301. {
  1302. $s

    =

    fread

    (

    $f

    ,

    $n

    )

    ;
  1303. if

    (

    $s

    ===

    false

    )
  1304. $this

    ->

    Error

    (

    'Error while reading stream'

    )

    ;
  1305. $n

    -=

    strlen

    (

    $s

    )

    ;
  1306. $res

    .=

    $s

    ;
  1307. }
  1308. if

    (

    $n

    >

    0

    )
  1309. $this

    ->

    Error

    (

    'Unexpected end of stream'

    )

    ;
  1310. return

    $res

    ;
  1311. }

  1312. function

    _readint(

    $f

    )
  1313. {
  1314. // Read a 4-byte integer from stream
  1315. $a

    =

    unpack

    (

    'Ni'

    ,

    $this

    ->

    _readstream(

    $f

    ,

    4

    )

    )

    ;
  1316. return

    $a

    [

    'i'

    ]

    ;
  1317. }

  1318. function

    _parsegif(

    $file

    )
  1319. {
  1320. // Extract info from a GIF file (via PNG conversion)
  1321. if

    (

    !

    function_exists

    (

    'imagepng'

    )

    )
  1322. $this

    ->

    Error

    (

    'GD extension is required for GIF support'

    )

    ;
  1323. if

    (

    !

    function_exists

    (

    'imagecreatefromgif'

    )

    )
  1324. $this

    ->

    Error

    (

    'GD has no GIF read support'

    )

    ;
  1325. $im

    =

    imagecreatefromgif

    (

    $file

    )

    ;
  1326. if

    (

    !

    $im

    )
  1327. $this

    ->

    Error

    (

    'Missing or incorrect image file: '

    .

    $file

    )

    ;
  1328. imageinterlace

    (

    $im

    ,

    0

    )

    ;
  1329. $f

    =

    @

    fopen

    (

    'php://temp'

    ,

    'rb+'

    )

    ;
  1330. if

    (

    $f

    )
  1331. {
  1332. // Perform conversion in memory
  1333. ob_start

    (

    )

    ;
  1334. imagepng

    (

    $im

    )

    ;
  1335. $data

    =

    ob_get_clean

    (

    )

    ;
  1336. imagedestroy

    (

    $im

    )

    ;
  1337. fwrite

    (

    $f

    ,

    $data

    )

    ;
  1338. rewind

    (

    $f

    )

    ;
  1339. $info

    =

    $this

    ->

    _parsepngstream(

    $f

    ,

    $file

    )

    ;
  1340. fclose

    (

    $f

    )

    ;
  1341. }
  1342. else
  1343. {
  1344. // Use temporary file
  1345. $tmp

    =

    tempnam

    (

    '.'

    ,

    'gif'

    )

    ;
  1346. if

    (

    !

    $tmp

    )
  1347. $this

    ->

    Error

    (

    'Unable to create a temporary file'

    )

    ;
  1348. if

    (

    !

    imagepng

    (

    $im

    ,

    $tmp

    )

    )
  1349. $this

    ->

    Error

    (

    'Error while saving to temporary file'

    )

    ;
  1350. imagedestroy

    (

    $im

    )

    ;
  1351. $info

    =

    $this

    ->

    _parsepng(

    $tmp

    )

    ;
  1352. unlink

    (

    $tmp

    )

    ;
  1353. }
  1354. return

    $info

    ;
  1355. }

  1356. function

    _newobj(

    )
  1357. {
  1358. // Begin a new object
  1359. $this

    ->

    n

    ++;
  1360. $this

    ->

    offsets

    [

    $this

    ->

    n

    ]

    =

    strlen

    (

    $this

    ->

    buffer

    )

    ;
  1361. $this

    ->

    _out(

    $this

    ->

    n

    .

    ' 0 obj'

    )

    ;
  1362. }

  1363. function

    _putstream(

    $s

    )
  1364. {
  1365. $this

    ->

    _out(

    'stream'

    )

    ;
  1366. $this

    ->

    _out(

    $s

    )

    ;
  1367. $this

    ->

    _out(

    'endstream'

    )

    ;
  1368. }

  1369. function

    _out(

    $s

    )
  1370. {
  1371. // Add a line to the document
  1372. if

    (

    $this

    ->

    state

    ==

    2

    )
  1373. $this

    ->

    pages

    [

    $this

    ->

    page

    ]

    .=

    $s

    .

    "\n

    "

    ;
  1374. else
  1375. $this

    ->

    buffer

    .=

    $s

    .

    "\n

    "

    ;
  1376. }

  1377. function

    _putpages(

    )
  1378. {
  1379. $nb

    =

    $this

    ->

    page

    ;
  1380. if

    (

    !

    empty

    (

    $this

    ->

    AliasNbPages

    )

    )
  1381. {
  1382. // Replace number of pages
  1383. for

    (

    $n

    =

    1

    ;

    $n

    <=

    $nb

    ;

    $n

    ++

    )
  1384. $this

    ->

    pages

    [

    $n

    ]

    =

    str_replace

    (

    $this

    ->

    AliasNbPages

    ,

    $nb

    ,

    $this

    ->

    pages

    [

    $n

    ]

    )

    ;
  1385. }
  1386. if

    (

    $this

    ->

    DefOrientation

    ==

    'P'

    )
  1387. {
  1388. $wPt

    =

    $this

    ->

    DefPageSize

    [

    0

    ]

    *

    $this

    ->

    k

    ;
  1389. $hPt

    =

    $this

    ->

    DefPageSize

    [

    1

    ]

    *

    $this

    ->

    k

    ;
  1390. }
  1391. else
  1392. {
  1393. $wPt

    =

    $this

    ->

    DefPageSize

    [

    1

    ]

    *

    $this

    ->

    k

    ;
  1394. $hPt

    =

    $this

    ->

    DefPageSize

    [

    0

    ]

    *

    $this

    ->

    k

    ;
  1395. }
  1396. $filter

    =

    (

    $this

    ->

    compress

    )

    ? '/Filter /FlateDecode '

    :

    ''

    ;
  1397. for

    (

    $n

    =

    1

    ;

    $n

    <=

    $nb

    ;

    $n

    ++

    )
  1398. {
  1399. // Page
  1400. $this

    ->

    _newobj(

    )

    ;
  1401. $this

    ->

    _out(

    '<</Type /Page'

    )

    ;
  1402. $this

    ->

    _out(

    '/Parent 1 0 R'

    )

    ;
  1403. if

    (

    isset

    (

    $this

    ->

    PageSizes

    [

    $n

    ]

    )

    )
  1404. $this

    ->

    _out(

    sprintf

    (

    '/MediaBox [0 0 %.2F %.2F]'

    ,

    $this

    ->

    PageSizes

    [

    $n

    ]

    [

    0

    ]

    ,

    $this

    ->

    PageSizes

    [

    $n

    ]

    [

    1

    ]

    )

    )

    ;
  1405. $this

    ->

    _out(

    '/Resources 2 0 R'

    )

    ;
  1406. if

    (

    isset

    (

    $this

    ->

    PageLinks

    [

    $n

    ]

    )

    )
  1407. {
  1408. // Links
  1409. $annots

    =

    '/Annots ['

    ;
  1410. foreach

    (

    $this

    ->

    PageLinks

    [

    $n

    ]

    as

    $pl

    )
  1411. {
  1412. $rect

    =

    sprintf

    (

    '%.2F %.2F %.2F %.2F'

    ,

    $pl

    [

    0

    ]

    ,

    $pl

    [

    1

    ]

    ,

    $pl

    [

    0

    ]

    +

    $pl

    [

    2

    ]

    ,

    $pl

    [

    1

    ]

    -

    $pl

    [

    3

    ]

    )

    ;
  1413. $annots

    .=

    '<</Type /Annot /Subtype /Link /Rect ['

    .

    $rect

    .

    '] /Border [0 0 0] '

    ;
  1414. if

    (

    is_string

    (

    $pl

    [

    4

    ]

    )

    )
  1415. $annots

    .=

    '/A <</S /URI /URI '

    .

    $this

    ->

    _textstring(

    $pl

    [

    4

    ]

    )

    .

    '>>>>'

    ;
  1416. else
  1417. {
  1418. $l

    =

    $this

    ->

    links

    [

    $pl

    [

    4

    ]

    ]

    ;
  1419. $h

    =

    isset

    (

    $this

    ->

    PageSizes

    [

    $l

    [

    0

    ]

    ]

    )

    ? $this

    ->

    PageSizes

    [

    $l

    [

    0

    ]

    ]

    [

    1

    ]

    :

    $hPt

    ;
  1420. $annots

    .=

    sprintf

    (

    '/Dest [%d 0 R /XYZ 0 %.2F null]>>'

    ,

    1

    +

    2

    *

    $l

    [

    0

    ]

    ,

    $h

    -

    $l

    [

    1

    ]

    *

    $this

    ->

    k

    )

    ;
  1421. }
  1422. }
  1423. $this

    ->

    _out(

    $annots

    .

    ']'

    )

    ;
  1424. }
  1425. if

    (

    $this

    ->

    PDFVersion

    >

    '1.3'

    )
  1426. $this

    ->

    _out(

    '/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>'

    )

    ;
  1427. $this

    ->

    _out(

    '/Contents '

    .

    (

    $this

    ->

    n

    +

    1

    )

    .

    ' 0 R>>'

    )

    ;
  1428. $this

    ->

    _out(

    'endobj'

    )

    ;
  1429. // Page content
  1430. $p

    =

    (

    $this

    ->

    compress

    )

    ? gzcompress

    (

    $this

    ->

    pages

    [

    $n

    ]

    )

    :

    $this

    ->

    pages

    [

    $n

    ]

    ;
  1431. $this

    ->

    _newobj(

    )

    ;
  1432. $this

    ->

    _out(

    '<<'

    .

    $filter

    .

    '/Length '

    .

    strlen

    (

    $p

    )

    .

    '>>'

    )

    ;
  1433. $this

    ->

    _putstream(

    $p

    )

    ;
  1434. $this

    ->

    _out(

    'endobj'

    )

    ;
  1435. }
  1436. // Pages root
  1437. $this

    ->

    offsets

    [

    1

    ]

    =

    strlen

    (

    $this

    ->

    buffer

    )

    ;
  1438. $this

    ->

    _out(

    '1 0 obj'

    )

    ;
  1439. $this

    ->

    _out(

    '<</Type /Pages'

    )

    ;
  1440. $kids

    =

    '/Kids ['

    ;
  1441. for

    (

    $i

    =

    0

    ;

    $i

    <

    $nb

    ;

    $i

    ++

    )
  1442. $kids

    .=

    (

    3

    +

    2

    *

    $i

    )

    .

    ' 0 R '

    ;
  1443. $this

    ->

    _out(

    $kids

    .

    ']'

    )

    ;
  1444. $this

    ->

    _out(

    '/Count '

    .

    $nb

    )

    ;
  1445. $this

    ->

    _out(

    sprintf

    (

    '/MediaBox [0 0 %.2F %.2F]'

    ,

    $wPt

    ,

    $hPt

    )

    )

    ;
  1446. $this

    ->

    _out(

    '>>'

    )

    ;
  1447. $this

    ->

    _out(

    'endobj'

    )

    ;
  1448. }

  1449. function

    _putfonts(

    )
  1450. {
  1451. $nf

    =

    $this

    ->

    n

    ;
  1452. foreach

    (

    $this

    ->

    diffs

    as

    $diff

    )
  1453. {
  1454. // Encodings
  1455. $this

    ->

    _newobj(

    )

    ;
  1456. $this

    ->

    _out(

    '<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['

    .

    $diff

    .

    ']>>'

    )

    ;
  1457. $this

    ->

    _out(

    'endobj'

    )

    ;
  1458. }
  1459. foreach

    (

    $this

    ->

    FontFiles

    as

    $file

    =>

    $info

    )
  1460. {
  1461. // Font file embedding
  1462. $this

    ->

    _newobj(

    )

    ;
  1463. $this

    ->

    FontFiles

    [

    $file

    ]

    [

    'n'

    ]

    =

    $this

    ->

    n

    ;
  1464. $font

    =

    file_get_contents

    (

    $this

    ->

    fontpath

    .

    $file

    ,

    true

    )

    ;
  1465. if

    (

    !

    $font

    )
  1466. $this

    ->

    Error

    (

    'Font file not found: '

    .

    $file

    )

    ;
  1467. $compressed

    =

    (

    substr

    (

    $file

    ,-

    2

    )

    ==

    '.z'

    )

    ;
  1468. if

    (

    !

    $compressed

    &&

    isset

    (

    $info

    [

    'length2'

    ]

    )

    )
  1469. $font

    =

    substr

    (

    $font

    ,

    6

    ,

    $info

    [

    'length1'

    ]

    )

    .

    substr

    (

    $font

    ,

    6

    +

    $info

    [

    'length1'

    ]

    +

    6

    ,

    $info

    [

    'length2'

    ]

    )

    ;
  1470. $this

    ->

    _out(

    '<</Length '

    .

    strlen

    (

    $font

    )

    )

    ;
  1471. if

    (

    $compressed

    )
  1472. $this

    ->

    _out(

    '/Filter /FlateDecode'

    )

    ;
  1473. $this

    ->

    _out(

    '/Length1 '

    .

    $info

    [

    'length1'

    ]

    )

    ;
  1474. if

    (

    isset

    (

    $info

    [

    'length2'

    ]

    )

    )
  1475. $this

    ->

    _out(

    '/Length2 '

    .

    $info

    [

    'length2'

    ]

    .

    ' /Length3 0'

    )

    ;
  1476. $this

    ->

    _out(

    '>>'

    )

    ;
  1477. $this

    ->

    _putstream(

    $font

    )

    ;
  1478. $this

    ->

    _out(

    'endobj'

    )

    ;
  1479. }
  1480. foreach

    (

    $this

    ->

    fonts

    as

    $k

    =>

    $font

    )
  1481. {
  1482. // Font objects
  1483. $this

    ->

    fonts

    [

    $k

    ]

    [

    'n'

    ]

    =

    $this

    ->

    n

    +

    1

    ;
  1484. $type

    =

    $font

    [

    'type'

    ]

    ;
  1485. $name

    =

    $font

    [

    'name'

    ]

    ;
  1486. if

    (

    $type

    ==

    'Core'

    )
  1487. {
  1488. // Core font
  1489. $this

    ->

    _newobj(

    )

    ;
  1490. $this

    ->

    _out(

    '<</Type /Font'

    )

    ;
  1491. $this

    ->

    _out(

    '/BaseFont /'

    .

    $name

    )

    ;
  1492. $this

    ->

    _out(

    '/Subtype /Type1'

    )

    ;
  1493. if

    (

    $name

    !=

    'Symbol'

    &&

    $name

    !=

    'ZapfDingbats'

    )
  1494. $this

    ->

    _out(

    '/Encoding /WinAnsiEncoding'

    )

    ;
  1495. $this

    ->

    _out(

    '>>'

    )

    ;
  1496. $this

    ->

    _out(

    'endobj'

    )

    ;
  1497. }
  1498. elseif

    (

    $type

    ==

    'Type1'

    ||

    $type

    ==

    'TrueType'

    )
  1499. {
  1500. // Additional Type1 or TrueType/OpenType font
  1501. $this

    ->

    _newobj(

    )

    ;
  1502. $this

    ->

    _out(

    '<</Type /Font'

    )

    ;
  1503. $this

    ->

    _out(

    '/BaseFont /'

    .

    $name

    )

    ;
  1504. $this

    ->

    _out(

    '/Subtype /'

    .

    $type

    )

    ;
  1505. $this

    ->

    _out(

    '/FirstChar 32 /LastChar 255'

    )

    ;
  1506. $this

    ->

    _out(

    '/Widths '

    .

    (

    $this

    ->

    n

    +

    1

    )

    .

    ' 0 R'

    )

    ;
  1507. $this

    ->

    _out(

    '/FontDescriptor '

    .

    (

    $this

    ->

    n

    +

    2

    )

    .

    ' 0 R'

    )

    ;
  1508. if

    (

    isset

    (

    $font

    [

    'diffn'

    ]

    )

    )
  1509. $this

    ->

    _out(

    '/Encoding '

    .

    (

    $nf

    +

    $font

    [

    'diffn'

    ]

    )

    .

    ' 0 R'

    )

    ;
  1510. else
  1511. $this

    ->

    _out(

    '/Encoding /WinAnsiEncoding'

    )

    ;
  1512. $this

    ->

    _out(

    '>>'

    )

    ;
  1513. $this

    ->

    _out(

    'endobj'

    )

    ;
  1514. // Widths
  1515. $this

    ->

    _newobj(

    )

    ;
  1516. $cw

    =

    &

    $font

    [

    'cw'

    ]

    ;
  1517. $s

    =

    '['

    ;
  1518. for

    (

    $i

    =

    32

    ;

    $i

    <=

    255

    ;

    $i

    ++

    )
  1519. $s

    .=

    $cw

    [

    chr

    (

    $i

    )

    ]

    .

    ' '

    ;
  1520. $this

    ->

    _out(

    $s

    .

    ']'

    )

    ;
  1521. $this

    ->

    _out(

    'endobj'

    )

    ;
  1522. // Descriptor
  1523. $this

    ->

    _newobj(

    )

    ;
  1524. $s

    =

    '<</Type /FontDescriptor /FontName /'

    .

    $name

    ;
  1525. foreach

    (

    $font

    [

    'desc'

    ]

    as

    $k

    =>

    $v

    )
  1526. $s

    .=

    ' /'

    .

    $k

    .

    ' '

    .

    $v

    ;
  1527. if

    (

    !

    empty

    (

    $font

    [

    'file'

    ]

    )

    )
  1528. $s

    .=

    ' /FontFile'

    .

    (

    $type

    ==

    'Type1'

    ? ''

    :

    '2'

    )

    .

    ' '

    .

    $this

    ->

    FontFiles

    [

    $font

    [

    'file'

    ]

    ]

    [

    'n'

    ]

    .

    ' 0 R'

    ;
  1529. $this

    ->

    _out(

    $s

    .

    '>>'

    )

    ;
  1530. $this

    ->

    _out(

    'endobj'

    )

    ;
  1531. }
  1532. else
  1533. {
  1534. // Allow for additional types
  1535. $mtd

    =

    '_put'

    .

    strtolower

    (

    $type

    )

    ;
  1536. if

    (

    !

    method_exists

    (

    $this

    ,

    $mtd

    )

    )
  1537. $this

    ->

    Error

    (

    'Unsupported font type: '

    .

    $type

    )

    ;
  1538. $this

    ->

    $mtd

    (

    $font

    )

    ;
  1539. }
  1540. }
  1541. }

  1542. function

    _putimages(

    )
  1543. {
  1544. foreach

    (

    array_keys

    (

    $this

    ->

    images

    )

    as

    $file

    )
  1545. {
  1546. $this

    ->

    _putimage(

    $this

    ->

    images

    [

    $file

    ]

    )

    ;
  1547. unset

    (

    $this

    ->

    images

    [

    $file

    ]

    [

    'data'

    ]

    )

    ;
  1548. unset

    (

    $this

    ->

    images

    [

    $file

    ]

    [

    'smask'

    ]

    )

    ;
  1549. }
  1550. }

  1551. function

    _putimage(

    &

    $info

    )
  1552. {
  1553. $this

    ->

    _newobj(

    )

    ;
  1554. $info

    [

    'n'

    ]

    =

    $this

    ->

    n

    ;
  1555. $this

    ->

    _out(

    '<</Type /XObject'

    )

    ;
  1556. $this

    ->

    _out(

    '/Subtype /Image'

    )

    ;
  1557. $this

    ->

    _out(

    '/Width '

    .

    $info

    [

    'w'

    ]

    )

    ;
  1558. $this

    ->

    _out(

    '/Height '

    .

    $info

    [

    'h'

    ]

    )

    ;
  1559. if

    (

    $info

    [

    'cs'

    ]

    ==

    'Indexed'

    )
  1560. $this

    ->

    _out(

    '/ColorSpace [/Indexed /DeviceRGB '

    .

    (

    strlen

    (

    $info

    [

    'pal'

    ]

    )

    /

    3

    -

    1

    )

    .

    ' '

    .

    (

    $this

    ->

    n

    +

    1

    )

    .

    ' 0 R]'

    )

    ;
  1561. else
  1562. {
  1563. $this

    ->

    _out(

    '/ColorSpace /'

    .

    $info

    [

    'cs'

    ]

    )

    ;
  1564. if

    (

    $info

    [

    'cs'

    ]

    ==

    'DeviceCMYK'

    )
  1565. $this

    ->

    _out(

    '/Decode [1 0 1 0 1 0 1 0]'

    )

    ;
  1566. }
  1567. $this

    ->

    _out(

    '/BitsPerComponent '

    .

    $info

    [

    'bpc'

    ]

    )

    ;
  1568. if

    (

    isset

    (

    $info

    [

    'f'

    ]

    )

    )
  1569. $this

    ->

    _out(

    '/Filter /'

    .

    $info

    [

    'f'

    ]

    )

    ;
  1570. if

    (

    isset

    (

    $info

    [

    'dp'

    ]

    )

    )
  1571. $this

    ->

    _out(

    '/DecodeParms <<'

    .

    $info

    [

    'dp'

    ]

    .

    '>>'

    )

    ;
  1572. if

    (

    isset

    (

    $info

    [

    'trns'

    ]

    )

    &&

    is_array

    (

    $info

    [

    'trns'

    ]

    )

    )
  1573. {
  1574. $trns

    =

    ''

    ;
  1575. for

    (

    $i

    =

    0

    ;

    $i

    <

    count

    (

    $info

    [

    'trns'

    ]

    )

    ;

    $i

    ++

    )
  1576. $trns

    .=

    $info

    [

    'trns'

    ]

    [

    $i

    ]

    .

    ' '

    .

    $info

    [

    'trns'

    ]

    [

    $i

    ]

    .

    ' '

    ;
  1577. $this

    ->

    _out(

    '/Mask ['

    .

    $trns

    .

    ']'

    )

    ;
  1578. }
  1579. if

    (

    isset

    (

    $info

    [

    'smask'

    ]

    )

    )
  1580. $this

    ->

    _out(

    '/SMask '

    .

    (

    $this

    ->

    n

    +

    1

    )

    .

    ' 0 R'

    )

    ;
  1581. $this

    ->

    _out(

    '/Length '

    .

    strlen

    (

    $info

    [

    'data'

    ]

    )

    .

    '>>'

    )

    ;
  1582. $this

    ->

    _putstream(

    $info

    [

    'data'

    ]

    )

    ;
  1583. $this

    ->

    _out(

    'endobj'

    )

    ;
  1584. // Soft mask
  1585. if

    (

    isset

    (

    $info

    [

    'smask'

    ]

    )

    )
  1586. {
  1587. $dp

    =

    '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns '

    .

    $info

    [

    'w'

    ]

    ;
  1588. $smask

    =

    array

    (

    'w'

    =>

    $info

    [

    'w'

    ]

    ,

    'h'

    =>

    $info

    [

    'h'

    ]

    ,

    'cs'

    =>

    'DeviceGray'

    ,

    'bpc'

    =>

    8

    ,

    'f'

    =>

    $info

    [

    'f'

    ]

    ,

    'dp'

    =>

    $dp

    ,

    'data'

    =>

    $info

    [

    'smask'

    ]

    )

    ;
  1589. $this

    ->

    _putimage(

    $smask

    )

    ;
  1590. }
  1591. // Palette
  1592. if

    (

    $info

    [

    'cs'

    ]

    ==

    'Indexed'

    )
  1593. {
  1594. $filter

    =

    (

    $this

    ->

    compress

    )

    ? '/Filter /FlateDecode '

    :

    ''

    ;
  1595. $pal

    =

    (

    $this

    ->

    compress

    )

    ? gzcompress

    (

    $info

    [

    'pal'

    ]

    )

    :

    $info

    [

    'pal'

    ]

    ;
  1596. $this

    ->

    _newobj(

    )

    ;
  1597. $this

    ->

    _out(

    '<<'

    .

    $filter

    .

    '/Length '

    .

    strlen

    (

    $pal

    )

    .

    '>>'

    )

    ;
  1598. $this

    ->

    _putstream(

    $pal

    )

    ;
  1599. $this

    ->

    _out(

    'endobj'

    )

    ;
  1600. }
  1601. }

  1602. function

    _putxobjectdict(

    )
  1603. {
  1604. foreach

    (

    $this

    ->

    images

    as

    $image

    )
  1605. $this

    ->

    _out(

    '/I'

    .

    $image

    [

    'i'

    ]

    .

    ' '

    .

    $image

    [

    'n'

    ]

    .

    ' 0 R'

    )

    ;
  1606. }

  1607. function

    _putresourcedict(

    )
  1608. {
  1609. $this

    ->

    _out(

    '/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'

    )

    ;
  1610. $this

    ->

    _out(

    '/Font <<'

    )

    ;
  1611. foreach

    (

    $this

    ->

    fonts

    as

    $font

    )
  1612. $this

    ->

    _out(

    '/F'

    .

    $font

    [

    'i'

    ]

    .

    ' '

    .

    $font

    [

    'n'

    ]

    .

    ' 0 R'

    )

    ;
  1613. $this

    ->

    _out(

    '>>'

    )

    ;
  1614. $this

    ->

    _out(

    '/XObject <<'

    )

    ;
  1615. $this

    ->

    _putxobjectdict(

    )

    ;
  1616. $this

    ->

    _out(

    '>>'

    )

    ;
  1617. }

  1618. function

    _putresources(

    )
  1619. {
  1620. $this

    ->

    _putfonts(

    )

    ;
  1621. $this

    ->

    _putimages(

    )

    ;
  1622. // Resource dictionary
  1623. $this

    ->

    offsets

    [

    2

    ]

    =

    strlen

    (

    $this

    ->

    buffer

    )

    ;
  1624. $this

    ->

    _out(

    '2 0 obj'

    )

    ;
  1625. $this

    ->

    _out(

    '<<'

    )

    ;
  1626. $this

    ->

    _putresourcedict(

    )

    ;
  1627. $this

    ->

    _out(

    '>>'

    )

    ;
  1628. $this

    ->

    _out(

    'endobj'

    )

    ;
  1629. }

  1630. function

    _putinfo(

    )
  1631. {
  1632. $this

    ->

    _out(

    '/Producer '

    .

    $this

    ->

    _textstring(

    'FPDF '

    .

    FPDF_VERSION)

    )

    ;
  1633. if

    (

    !

    empty

    (

    $this

    ->

    title

    )

    )
  1634. $this

    ->

    _out(

    '/Title '

    .

    $this

    ->

    _textstring(

    $this

    ->

    title

    )

    )

    ;
  1635. if

    (

    !

    empty

    (

    $this

    ->

    subject

    )

    )
  1636. $this

    ->

    _out(

    '/Subject '

    .

    $this

    ->

    _textstring(

    $this

    ->

    subject

    )

    )

    ;
  1637. if

    (

    !

    empty

    (

    $this

    ->

    author

    )

    )
  1638. $this

    ->

    _out(

    '/Author '

    .

    $this

    ->

    _textstring(

    $this

    ->

    author

    )

    )

    ;
  1639. if

    (

    !

    empty

    (

    $this

    ->

    keywords

    )

    )
  1640. $this

    ->

    _out(

    '/Keywords '

    .

    $this

    ->

    _textstring(

    $this

    ->

    keywords

    )

    )

    ;
  1641. if

    (

    !

    empty

    (

    $this

    ->

    creator

    )

    )
  1642. $this

    ->

    _out(

    '/Creator '

    .

    $this

    ->

    _textstring(

    $this

    ->

    creator

    )

    )

    ;
  1643. $this

    ->

    _out(

    '/CreationDate '

    .

    $this

    ->

    _textstring(

    'D:'

    .@

    date

    (

    'YmdHis'

    )

    )

    )

    ;
  1644. }

  1645. function

    _putcatalog(

    )
  1646. {
  1647. $this

    ->

    _out(

    '/Type /Catalog'

    )

    ;
  1648. $this

    ->

    _out(

    '/Pages 1 0 R'

    )

    ;
  1649. if

    (

    $this

    ->

    ZoomMode

    ==

    'fullpage'

    )
  1650. $this

    ->

    _out(

    '/OpenAction [3 0 R /Fit]'

    )

    ;
  1651. elseif

    (

    $this

    ->

    ZoomMode

    ==

    'fullwidth'

    )
  1652. $this

    ->

    _out(

    '/OpenAction [3 0 R /FitH null]'

    )

    ;
  1653. elseif

    (

    $this

    ->

    ZoomMode

    ==

    'real'

    )
  1654. $this

    ->

    _out(

    '/OpenAction [3 0 R /XYZ null null 1]'

    )

    ;
  1655. elseif

    (

    !

    is_string

    (

    $this

    ->

    ZoomMode

    )

    )
  1656. $this

    ->

    _out(

    '/OpenAction [3 0 R /XYZ null null '

    .

    sprintf

    (

    '%.2F'

    ,

    $this

    ->

    ZoomMode

    /

    100

    )

    .

    ']'

    )

    ;
  1657. if

    (

    $this

    ->

    LayoutMode

    ==

    'single'

    )
  1658. $this

    ->

    _out(

    '/PageLayout /SinglePage'

    )

    ;
  1659. elseif

    (

    $this

    ->

    LayoutMode

    ==

    'continuous'

    )
  1660. $this

    ->

    _out(

    '/PageLayout /OneColumn'

    )

    ;
  1661. elseif

    (

    $this

    ->

    LayoutMode

    ==

    'two'

    )
  1662. $this

    ->

    _out(

    '/PageLayout /TwoColumnLeft'

    )

    ;
  1663. }

  1664. function

    _putheader(

    )
  1665. {
  1666. $this

    ->

    _out(

    '%PDF-'

    .

    $this

    ->

    PDFVersion

    )

    ;
  1667. }

  1668. function

    _puttrailer(

    )
  1669. {
  1670. $this

    ->

    _out(

    '/Size '

    .

    (

    $this

    ->

    n

    +

    1

    )

    )

    ;
  1671. $this

    ->

    _out(

    '/Root '

    .

    $this

    ->

    n

    .

    ' 0 R'

    )

    ;
  1672. $this

    ->

    _out(

    '/Info '

    .

    (

    $this

    ->

    n

    -

    1

    )

    .

    ' 0 R'

    )

    ;
  1673. }

  1674. function

    _enddoc(

    )
  1675. {
  1676. $this

    ->

    _putheader(

    )

    ;
  1677. $this

    ->

    _putpages(

    )

    ;
  1678. $this

    ->

    _putresources(

    )

    ;
  1679. // Info
  1680. $this

    ->

    _newobj(

    )

    ;
  1681. $this

    ->

    _out(

    '<<'

    )

    ;
  1682. $this

    ->

    _putinfo(

    )

    ;
  1683. $this

    ->

    _out(

    '>>'

    )

    ;
  1684. $this

    ->

    _out(

    'endobj'

    )

    ;
  1685. // Catalog
  1686. $this

    ->

    _newobj(

    )

    ;
  1687. $this

    ->

    _out(

    '<<'

    )

    ;
  1688. $this

    ->

    _putcatalog(

    )

    ;
  1689. $this

    ->

    _out(

    '>>'

    )

    ;
  1690. $this

    ->

    _out(

    'endobj'

    )

    ;
  1691. // Cross-ref
  1692. $o

    =

    strlen

    (

    $this

    ->

    buffer

    )

    ;
  1693. $this

    ->

    _out(

    'xref'

    )

    ;
  1694. $this

    ->

    _out(

    '0 '

    .

    (

    $this

    ->

    n

    +

    1

    )

    )

    ;
  1695. $this

    ->

    _out(

    '0000000000 65535 f '

    )

    ;
  1696. for

    (

    $i

    =

    1

    ;

    $i

    <=

    $this

    ->

    n

    ;

    $i

    ++

    )
  1697. $this

    ->

    _out(

    sprintf

    (

    '%010d 00000 n '

    ,

    $this

    ->

    offsets

    [

    $i

    ]

    )

    )

    ;
  1698. // Trailer
  1699. $this

    ->

    _out(

    'trailer'

    )

    ;
  1700. $this

    ->

    _out(

    '<<'

    )

    ;
  1701. $this

    ->

    _puttrailer(

    )

    ;
  1702. $this

    ->

    _out(

    '>>'

    )

    ;
  1703. $this

    ->

    _out(

    'startxref'

    )

    ;
  1704. $this

    ->

    _out(

    $o

    )

    ;
  1705. $this

    ->

    _out(

    '%%EOF'

    )

    ;
  1706. $this

    ->

    state

    =

    3

    ;
  1707. }
  1708. // End of class
  1709. }

  1710. // Handle special IE contype request
  1711. if

    (

    isset

    (

    $_SERVER

    [

    'HTTP_USER_AGENT'

    ]

    )

    &&

    $_SERVER

    [

    'HTTP_USER_AGENT'

    ]

    ==

    'contype'

    )
  1712. {
  1713. header

    (

    'Content-Type: application/pdf'

    )

    ;
  1714. exit

    ;
  1715. }

  1716. ?>

Creating Our generatePdf.php

  1. <?php
  2. require

    (

    'fpdf.php'

    )

    ;


  3. $conect

    =

    mysql_connect

    (

    "localhost"

    ,

    "root"

    ,

    ""

    )

    ;
  4. mysql_select_db

    (

    "db_name"

    ,

    $conect

    )

    ;

  5. $sql

    =

    "INSERT INTO table_name (name, email, mobile, comment) VALUES ('"

    .

    $_POST

    [

    "name"

    ]

    .

    "', '"

    .

    $_POST

    [

    "email"

    ]

    .

    "', '"

    .

    $_POST

    [

    "mobile"

    ]

    .

    "', '"

    .

    $_POST

    [

    "comment"

    ]

    .

    "');"

    ;

  6. mysql_query

    (

    $sql

    )

    ;


  7. class

    PDF extends

    FPDF
  8. {
  9. // Page header
  10. function

    Header

    (

    )
  11. {
  12. // Logo
  13. $this

    ->

    Image

    (

    'logo.jpg'

    ,

    10

    ,

    6

    ,

    30

    )

    ;
  14. // Arial bold 15
  15. $this

    ->

    SetFont

    (

    'Arial'

    ,

    'B'

    ,

    15

    )

    ;
  16. // Move to the right
  17. $this

    ->

    Cell

    (

    80

    )

    ;
  18. // Title
  19. $this

    ->

    Cell

    (

    60

    ,

    10

    ,

    'Convert HTML TO PDF'

    ,

    1

    ,

    0

    ,

    'C'

    )

    ;
  20. // Line break
  21. $this

    ->

    Ln

    (

    20

    )

    ;
  22. }

  23. // Page footer
  24. function

    Footer(

    )
  25. {
  26. // Position at 1.5 cm from bottom
  27. $this

    ->

    SetY

    (

    -

    15

    )

    ;
  28. // Arial italic 8
  29. $this

    ->

    SetFont

    (

    'Arial'

    ,

    'I'

    ,

    8

    )

    ;
  30. // Page number
  31. $this

    ->

    Cell

    (

    0

    ,

    10

    ,

    'Page '

    .

    $this

    ->

    PageNo

    (

    )

    .

    '/{nb}'

    ,

    0

    ,

    0

    ,

    'C'

    )

    ;
  32. }
  33. }

  34. // Instanciation of inherited class
  35. $pdf

    =

    new

    PDF(

    )

    ;
  36. $pdf

    ->

    AliasNbPages

    (

    )

    ;
  37. $pdf

    ->

    AddPage

    (

    )

    ;
  38. $pdf

    ->

    SetFont

    (

    'Times'

    ,

    ''

    ,

    12

    )

    ;

  39. $pdf

    ->

    Cell

    (

    0

    ,

    10

    ,

    'Name : '

    .

    $_POST

    [

    "name"

    ]

    ,

    0

    ,

    1

    )

    ;
  40. $pdf

    ->

    Cell

    (

    0

    ,

    10

    ,

    'Email : '

    .

    $_POST

    [

    "email"

    ]

    ,

    0

    ,

    1

    )

    ;
  41. $pdf

    ->

    Cell

    (

    0

    ,

    10

    ,

    'Mobile : '

    .

    $_POST

    [

    "mobile"

    ]

    ,

    0

    ,

    1

    )

    ;
  42. $pdf

    ->

    Cell

    (

    0

    ,

    10

    ,

    'Comment : '

    .

    $_POST

    [

    "comment"

    ]

    ,

    0

    ,

    1

    )

    ;

  43. $pdf

    ->

    Output

    (

    )

    ;
  44. ?>

You have successfully created a program that will convert your html/php data into pdf. For suggestions feel free to comment your thoughts below for email me at @[email protected]

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

 

442,401

317,942

317,951

Top