Jump to content

Fatal error in pdf bulk invoices generation


Recommended Posts

Hi,

I'm having a problem while trying to generate bulk pdf invoices from the back-end : Orders > Invoices and then choose on the right side some orders status to generate a pdf.

For some status it works and for some its generates a blank page with the message 'fatal error' and that' all.

 

I'm using PS 1440

 

An idea ?

 

Regards

Link to comment
Share on other sites

Hi

 

There are about 64 'canceled' orders, 349 orders in shipping' (and so, shipped), 38 orders 'shipped' and 7 in 'payment accepted'.

The only PDF generated is for 'payment accepted'. When he gets the 'fatak error', the system show the message almost immediatly

It's my client who manages his statuses.

 

Thank you

Link to comment
Share on other sites

There are about 64 'canceled' orders, 349 orders in shipping' (and so, shipped), 38 orders 'shipped' and 7 in 'payment accepted'.

The only PDF generated is for 'payment accepted'. When he gets the 'fatak error', the system show the message almost immediatly

It's my client who manages his statuses.

I think that this is caused by too low value for script running (max_execution_time in php.ini). Ask phpinfo() for exact run value.

Link to comment
Share on other sites

Hi and thank you for your answers.

 

@Bill Dalton : yes the logo is in .jpg format

@tuk66 : we've noticed that all the orders before 2012, so between 2011-06 (the opening of the website) and 2012-01-15 have a 'fatal error' when we try to generate the invoice. But when we edit theses orders to see the details and we click on the shipping delivery, the PDF is generated, and when we click on Invoice to generate the invoice, we have a 'Fatal error' .

 

So, it seems it's not a PDF generating, but something tied to the invoicing ?

 

Regards

Link to comment
Share on other sites

@tuk66 : we've noticed that all the orders before 2012, so between 2011-06 (the opening of the website) and 2012-01-15 have a 'fatal error' when we try to generate the invoice. But when we edit theses orders to see the details and we click on the shipping delivery, the PDF is generated, and when we click on Invoice to generate the invoice, we have a 'Fatal error' .

I see. So it looks like corrupted data. Did you upgrade your shop recently? Is a problem with all payments and/or shippments? Maybe some SQL query fails and get the error. Do you have feedback with

@ini_set('display_errors', 'on');

settings in config.inc.php?

 

It is hard to find a reason of this error without looking at real data in the database or debugging a PDF generating process..

Link to comment
Share on other sites

Thank you.

Recently, no update have been made.

 

I think it's in /tools/fdpf/fdpf.php but, how do you do to debug PDF process ?

Where can I find the db schema of my version to see if tables are coorupted ?

 

Regards

Link to comment
Share on other sites

I think it's in /tools/fdpf/fdpf.php but, how do you do to debug PDF process ?

Where can I find the db schema of my version to see if tables are coorupted ?

You can debug PHP script on localhost, if the copy is failing too, of course. You can debug live site by inserting breaks to the code and to find the line which caused error. I think that can be corrupted data, not db schema. There can be many reasons of this. DB schema is in installation archive, the /install/sql/db.sql file.

 

I would start with debugging PDF.php script. It would be to show the reason of failing.

Link to comment
Share on other sites

I've just added some code in the /tools/fpdf/fpdf.php file and got the message code below. I think there's something to watch in the end near PageLayout /OneColumn >> endobj whicj might be the last code executed ?

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x��W�r�F}�+�1���s��o_��z�w��RB�$�����ȓ��a4�dI�Ш9����������?�w��(���P� bXo�r�ঀ��t�w �"���nW�#��ƒD!�^��i�Ë�,��L���_�2�����������ƻX������a��'�$�j{�%���L�i����C��"m�I�j�r ������CrtE��u��; 7�����8$28z-�r�]~�{E�H���Q�]/n�����}�@)mje���@�?���=����|������c�PK��r3�����+� ū����XD���R*�\ T�+:x94����&,hK�bn��6��BE�� ���#�f4+��$GJ,o�#�Gf�$<����ff�_�\�o�>�p��E�Iy`g{`�� ��챴"e��E�P�� L �w V�����J(|�E ��Ϡw>��{�!U�ߖ�EtT}�S�����G�;C�� ' g�q4}�A�}ڳ������7�6��k�eBj��������2��д�+t�oA2F(wv/�P����� �Du��u��Z�C��`&Tv8�ב4L�c�� m֧��.�����aK��ٹ��syl�SQaN�����$>o���HqBҖ����n�}��lwE����� r'��_�⓼���|#��F��=~k�Z�d����R5��T����F(?P�]�Q#�S�����^;�z�x2��Y�K�m]�푫��kC3$̉�f���E�&�M�za�=&L�/�XN*�0-�)/��8��t [sP�u�wi�W���$3������O�Q�W�:5F���F�[c�R��cj�i[���n�{�ⰱ=�����M�EV�8�4���8Z, `tH��At xD֛2��2v��� 1{�4v��!C/՜����b<6����tB�w/F��������$0�?,�t���;-~�����0[�xs�b�&ʈ��զh+X&��POa�|G:�i�`xSD|6$�h$D��"�v�M�O��Lә�fpI5�ʦ=�SL�'(3l�8��� ���_J¬��4�,����>���h�c������/S�%>_�,�!���t����� )��:��c15���~�7cUg�������(0�>Q��U���J� endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> stream ����JFIF��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90 ��C     ��C   ����"�� ���}!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ���w!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������� ?�S��(��(���IR�ݶ��Z�$�g�;x�������_R��&=>?3���O�VB�{�K��i��]+�I5�SDf���Oy��;q��ӷ�=?:ɛ������c�k*;9��e����/�� ���lR(�t1����ӣG�ٗ3f!�u9�� ��j/�ۋ�˶��j���͏ie\���Z��6�����'��F��¬+y���+��U�f�+nI6����[ͥڻ|���G�N]>�>P��T���$b��V������sV��U���9?J�k�#+U;�6V_�˛�� g�JzJ(z���_YO���?�V�H���m��k��G����B�{��cfJO NÑJo��tW/���[��_,��E���H�,��2��k��9Rv�5MKbJ(��((��(��(��(���x���\Ix�����ڴ�NUd�v��J췭���B�t��V��/�j�滾�=��~������vZ��Mq#<��ں�;]���yM�6���ǽ{*�<��9ܜ�؊�A��wK�7�j���F��w�ۏd�Z�%����T���YKV�+ ��n��I�_���C (�� (�� (�� d��~�̾�'ޤ�;��h!�x?*̲���f�>�xۣWV��n���U ��������T+��ST+v/iZ;�b8�~�m�kF�����I�ͅ��S����� �X��~��>��{W=|?"熱5����EW�QEQEW�����I�m�F����z������1�_畾H���W�D���]\~��v� �U��������a^ ����&�� x}4��[�?y����澦��Q��7�X䔽��cf��Y@�/�������2[��Zm��vP��)���՟�s�����ެ��K&�{}����ש<����ڿݩ�b���>���ۿ���i��(��)���~o�h��������UK{���.<����@�CI��Y�-��g_��Q��9F[��]�W���>�%��6����r�6�i�̿ݪq�v�^}�7y�v�͚��%qv��Sv��Ь�_�5n�fڳG��u;���Nہժ^�\u��Əz���t�J�|�)�o���C֣ԬV��o�k��_d��d��sA�c��Ve�]x�?�kV���P��ZǙ��n&O�_��Q�t��eF܌7�\��?���.dKEW�W�|`�V Z �|�bK��;/�kҵ-B+O��v� ]ϰ������_�I����2����v��'�*�%���ϡ�ZM+.�w��찭î�o�?�}+�#�ȏ�o��H��������S�0��Ɲ}p����m�m���>&���KU���"*�з�j�}��]�o���W��ƶ��"�D�B���n�B������G�����}��N��~mP��l{������W���V��.�Q4!�r�*|�{ԍH�����i�Qo�L�Ѭ;�O��S��In/�ףU�*��������㷊��Tk��ԴT�Rm7��j�rH��~Zi\�4kiٙW�w���V���<+��{�9X=-Rj̀�#�Wu�����s~��o��t��W+;R]�+��C�����E_�Ś?� J�� ���M&f�����s��+��E՟��^U�M/���o~h_~?�;��(G�teB[��Ho���**���w��\DwE"�S���wgc��_����g�`�Q�{�M���5���e��?�����ӷ����ڷ����lW��Z"����?�������M-�k��Y �+�����N\�����A��[�������Z^�����F���S�k���:޹���{����Ѯ��_5�N�y�Vn��K����P�P���t�����+U����j&�_�S�ο�5p%���^W�/���_���jz@R���f�KLV}�:�m��9[z����(6��EV�R��i�p*e��|� �q��5i��i?�E�j��=V����#�j��yM�U(�X��&�yq���2�_è�3�������wf�;��Rܤ?���D_���sơ�m�z��_VU��GK��X�~�%�7�l�o��W��P6~4�����?���-�W��эT�=~��&�e�y?�5��S�5����_�>_����^��՝6��lH���^3�}ZMF9�gڲ��e�c��98���{ú)���v���k҅:��$���M�������M�w������d�k�������-_��=���塤���\ֱ}�[��}Ut�M�i����N{�7��A���o^�.�MI��gM(C�2�����I�_!�<]l+��w��Vw���ܵ��J��A��_s���}�����v�k�y-m����T�]F��Y��-���]��V����������J�9���������Tˊ���,�q����s�Ӷ*��/�y_l���i#�fIB�����U+R�V4jI)J�]�k�cI�to�X�!ֿ����k��ż �ԟ�����m���C���������9�qr�~���ץy��T�r�S�ڏ�-9Sj�ov�g�i]_r�=�f�Ta�m�h��F���c֫��r^��e�8�=�'��8��)�*uT��k{׶�k躷������i��_��7�r���,>��B̳���m��Lz"��n��Y/���ڭ��7f�\��lב)��'(M����,���6�v�}�cW������Y��6�-��Q��`��*o����:�<�B�:ƻm��I>�cɯ5�� �3�A��AGûZ���Z�����j:�N���X�-��F���Z�\F���QT�;��?u��&��u��c��Ǥ�"K�7���+�F��3g�H�Z��Ex�)u;�|F������_��.��2Y�^e��Yɷ۸�&�)�sR�[�F�����qO��n�>�&����^X��2�������?-l��A_�i�T4��ω�o �%�����֓uh_�ʾ�#�a��z��J~���gѵ�E�i^׳��n����cO_�ꉻ��\��� �C��1����^�k�<��ލX�0�M��ot���EĎ�T�5��i�T����咹��ѱ�����/�XC������\��/�����潶p���N:+��d�̹*E��ߩ�����υs�.���+���� �|���h4���♮���ku��2��H��})�]K��{���{y���T��=P�����7mr�7�k�W�W�ܙ����=M������a�O����C�O=�c��Z~��x� ���J���jc�y��t��vW�m���ڬm�6}ߴD$���Mugi�X�ay�i${%�o��J�����J���IFѳ��┥wt�{$�����"1��X��GS�"И�m��#�yU�fn?�e|+�֩�e���d�Kqo����Ѥ�+g�Rx��v&e�I�l��-��Ϙ���?��\V�����4xt�#���8�����������F7 Z�&R\�3Iݾkے��(%n���IT��Ko��y�E�kz��=2��O�N����Q�5XE���Gj�}��MQ�o�~�ό��W�5���z���:.�7�7����?N8�k��~�Z~�5����oR�#�ڌ���uX�g��V,���2)kyn�dC��J^;5o�!N����\,������y���߽˯�i�g�woV\��\���kb_h�+*춸hwt�[��U=_T�}��t�$���*ٍ2~nG+�����Z���k����/�P���u��t�m+�2�O�M=o�U~N}Gz�+��ڴ�8hT�aU��ͷ��֖I�����s8Ԋq�Z�������jˣ^K&�alm$��]��'����Zg��O�[Zi1��_`_7S�����8�Ӂ^��ikg���vv�������i��đ�e��ݓ��Mp��Uj�[�=5�R捝�KkZ�z�����G�xKH�¾��B�;�5yn�>��D�!��+������ x6�������q��v\�nͱw7͊�%���-�z��V0���'&խ������įs���x��umk��Ceqz���D���oc�<���Y��'��/^kzբ�^E�=O�K[���ǫ��XרG�-w��ޝ]�r,v�Z.M)-[ךͿ[�N�*�[L^׭u�5��O��K�u+�ț)�<ǣ{�5�=3^�| ��_ښ���v� ��{��v�ǰ��^E�=]�������T���^���˘m���3�c$�^ ~����B2嚟3OX�hJ6ooy7n��5�+��� ;]x{]_ip[���F�>�>�3/p}��o�^�t����D�\���8c�uY$�v����l���s�z��WY��*���������t��E߽�ƽ���hૼM��I�f�W�����z�λ�yZ%�ȗM������fG���}k"��E�m͹�sSkAtY��*s_�F�*�Y��S�~!\.鿄�UH���cg6��� #��`(��x�aaO{-\�|c V�|u����+mH�!��{�%]���>=�Ѿ����}֯>���)��D��"�����w�<[��qҺx�=f[�WVo�� ��ŏּ�_�``�k}�%���C޴۪��f������軕����C�>�n�����4�uśv>*����}����:f�_y�b����r:�� �K�h�����׮�?�uzL�q�ٳ����uy�)F T�^��Rݼ��4Ѭ��gn]�b�.1�Z���� ʸ�;�?*o�^_���U-6�U���#r��=�^l�ι��E�=������A��x�H�w}��{4��8�d�){���i�qj�� ��Q[����)��L ����VQ2��� d\4�z���e�ܙ��X��K}��[�ˎ���K=S��yS|�W��~|Z��.��ԇ-liY�u�l���;�ִ��Tm�-��o�U�mpZڶ������s\�2���d�Z��/� h��ފ>���2\'ʲ7N�\Vu�����gHv��3���+���KXV(���M*qq]@��K�j����������J�&ݐ�$�t���w7a^_�^yW_*�~�y滟��z����@���?�i����ͪY,�E�vW����{���S2MR��:j�[��ċ��p�����Q�O�?��Z�cV��e�l���}O5.��-���ٯ�\n^�]܎��)kۧ�&|����ۚ��ktV����S^_�3|Ƹ�j� U����׿�ùԍ�'+#��$#]����P�ʷ�q�F �J+c�W��� a���V�s�̔����W��-y_�[;~U�&���7 cug ��.����ib�O5�o�ףS���-�y��]�ʍ��uo�ie�U�7�k��?ww̫�+/��U����R���[&��S�V�%�3��I�ٍ���٭+&8!h�i����? �&�l��/����W��QE�����[JUjta��5eͮG��/�J�76�.�q"��ڧ_��f]L�Q6ٶ��_v'�mO��M���?�$�F�"w�������F��U��0��X r����c[_g}nEi�Y!O�������2^Z�k���<��Z��r��#y��44�e_���s�����;��h!i���k���5;�B�mdUB�)��sV��[lkn��*%��朞�\�C�-vk���LG���Y��mv���Tf�מ\Jͺ�5AS�V�w9����1o��^?�ă�o������x�^K[i�o�o�^-e�^|V����Z�s�������y�����t#=9W��H哾����E����^5[��u�N׸��_v/�tg�E{F�a�aogm�o�U���{^X�ӭ-��{��TKu�g���G�OA�-:,��"��o�{bz��?M���Aum ����ƳA"�xې��A���K Z5��H*��g�/�K���V�H���b����"O�G;����w�}�����O�s�;���o�a7�}b'��R���[����Q_�S�ƴHj��N {���A��o�������ٿ�uvwU��-��c� >���ש�w�K�*������������?���T�N��e���\�����f�kƝ3NSr9�e����Ո�+��-�e���9$�[��dp�1��)�gҤ�j#tKF^��͛A-j����Z/7H����?�����ݮ����kn������Z��ԔW"��2hŸִ߱��d{;�}Z�-ռ����G�o�O�����K7�����q���P5�Ŀ3|���S^�)+is6Y�P�C6?r��r!�{��sb5K�m���v ������yn|���v�f���F�~��(�+V[_���}�w��Wm*r_�ɝ��i1y6��c������KT+ 5c��>�q��g�j��b����kС�pw�����4�G����o��|Q�-���#tVm׌���ʏ��vE����:��C߼�c������[�=N��VZ?�l�G12m��dW��� ���7u�U�n��/�b�}�������鶾o���������t������S��{v��U�moo ��pC�j#A��p��E����{��#\5>g�b�(�ϏL(����"�?�>%x^�E�#��4rOهҾ�íK�׉�ҵ���m�L�%^̿Z�$�+�W� +�V��{��������G���ڽ\5��,��'��.��Id˿��o��B��.։��o��s~"����bM;T����\�� �%����Z�������ɤ�ǫN���=�A������������׮����V�^W��5���+�z�H��r���˷�����Z��H�*XV�;f����m���w|��S[X�?����U�Q���t:E��溮^OH�v8���˺֧�m�7�����g��*M��żJۦ]ޕ�$g���|��J�����I`�wm�ڪ��s-��~~�_�i���W�O ��g$�΂���$Ui#�O�*=A�,#�_��~۾�~�ϵ��B��\��u��W\ף�"/�?��v��F�jr�B=jI5o������ڹ{�."��|��VMj[��_3uCx�}�wm��{�*�9 ����W���5 "��Ϻ�����Kի\�D~U�߶?�����y���#������=��WJ�FM���Y��}.�EM��w���^u� ���׍�|?��T��,͝�D:�{ < ��Ŀ�W��[�Ö�,�������(�)�KC�'���t�^�]ߺ��w��v�湴p0厵˷�4�E�z�j�*�]��!�u���8BA�$������os]�W峜�I�nힺI+ ��*QEQEa������g�[���/�H}A���-G�m"/����,��?����5�2����8���m���^T^���Mâ]���w��O���>ݿv�Y�!g�����?p�*����u��!�c�X��hq2x�?/���?��R����*��V��J�#�i�Uo��z�*���VS����C����K�~_�k��&��AE�l?�*�o.�����ٯ��U�vN�f��'�*��s�֪7�����f���W;u����Ջ}�\ �-z��yi���> /XObject << /I1 7 0 R >> >> endobj 8 0 obj << /Producer (FPDF 1.6) /CreationDate (D:20120510164353) >> endobj 9 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 10 0000000000 65535 f 0000001357 00000 n 0000010722 00000 n 0000000009 00000 n 0000000087 00000 n 0000001444 00000 n 0000001545 00000 n 0000001641 00000 n 0000010846 00000 n 0000010921 00000 n trailer << /Size 10 /Root 9 0 R /Info 8 0 R >> startxref 11024 %%EOF

Link to comment
Share on other sites

I've just added some code in the /tools/fpdf/fpdf.php file and got the message code below. I think there's something to watch in the end near PageLayout /OneColumn >> endobj whicj might be the last code executed ?

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x��W�r�F}�+�1���s��o_��z�.....

It looks like a normal PDF file.

Link to comment
Share on other sites

Hi,

I encouter some problems in debugging PDF.php class file. I tool the folder /tools/ from the last version of PS, the last PDF.php class and the last /admin/AdminInvoice.php file, and uploaeded them to the website, but my problem is stilel the same with a 'fatal error' when I try to generate PDF invoice for a date befor 2011-01-15 . I think this has be with order data in the db but all is correct.

 

An idea ?

 

Regards

.

Link to comment
Share on other sites

Hi,

Here's what's echoed when I try to generate a delivery or PDF invoice :

 

$family helvetica fpdf-_getfontpath fpdf-ErrorFPDF error: Undefined font: helvetica B

 

The last function before the error seems to be _getfontpath and the test of the path of helveticaB which is not good. But why helvetica B , I've echoed $family and it's equal to helvetica .

 

An idea ?

 

Regards

 

The error comes from the /tools/fpdf/fpdf.php file ; I've checked and the font files are on the server,

Link to comment
Share on other sites

Hi and thank you.

Here's th

<?php
/*******************************************************************************
* FPDF																		 *
*																			  *
* Version : 1.6															    *
* Date :    2008-08-03														 *
* Auteur :  Olivier PLATHEY												    *
*******************************************************************************/
define('FPDF_VERSION','1.6');
echo 'fpdf-11111';
class FPDF
{
var $page;			   //current page number
var $n;				  //current object number
var $offsets;		    //array of object offsets
var $buffer;			 //buffer holding in-memory PDF
var $pages;			  //array containing pages
var $state;			  //current document state
var $compress;		   //compression flag
var $k;				  //scale factor (number of points in user unit)
var $DefOrientation;	 //default orientation
var $CurOrientation;	 //current orientation
var $PageFormats;	    //available page formats
var $DefPageFormat;	  //default page format
var $CurPageFormat;	  //current page format
var $PageSizes;		  //array storing non-default page sizes
var $wPt,$hPt;		   //dimensions of current page in points
var $w,$h;			   //dimensions of current page in user unit
var $lMargin;		    //left margin
var $tMargin;		    //top margin
var $rMargin;		    //right margin
var $bMargin;		    //page break margin
var $cMargin;		    //cell margin
var $x,$y;			   //current position in user unit
var $lasth;			  //height of last printed cell
var $LineWidth;		  //line width in user unit
var $CoreFonts;		  //array of standard font names
var $fonts;			  //array of used fonts
var $FontFiles;		  //array of font files
var $diffs;			  //array of encoding differences
var $FontFamily;		 //current font family
var $FontStyle;		  //current font style
var $underline;		  //underlining flag
var $CurrentFont;	    //current font info
var $FontSizePt;		 //current font size in points
var $FontSize;		   //current font size in user unit
var $DrawColor;		  //commands for drawing color
var $FillColor;		  //commands for filling color
var $TextColor;		  //commands for text color
var $ColorFlag;		  //indicates whether fill and text colors are different
var $ws;				 //word spacing
var $images;			 //array of used images
var $PageLinks;		  //array of links in pages
var $links;			  //array of internal links
var $AutoPageBreak;	  //automatic page breaking
var $PageBreakTrigger;   //threshold used to trigger page breaks
var $InHeader;		   //flag set when processing header
var $InFooter;		   //flag set when processing footer
var $ZoomMode;		   //zoom display mode
var $LayoutMode;		 //layout display mode
var $title;			  //title
var $subject;		    //subject
var $author;			 //author
var $keywords;		   //keywords
var $creator;		    //creator
var $AliasNbPages;	   //alias for total number of pages
var $PDFVersion;		 //PDF version number
/*******************************************************************************
*																			  *
*							   Public methods								 *
*																			  *
*******************************************************************************/
function FPDF($orientation='P', $unit='mm', $format='A4')
{
//Some checks
echo 'fpdf-FPDF';
$this->_dochecks();
//Initialization of properties
$this->page=0;
$this->n=2;
$this->buffer='';
$this->pages=array();
$this->PageSizes=array();
$this->state=0;
$this->fonts=array();
$this->FontFiles=array();
$this->diffs=array();
$this->images=array();
$this->links=array();
$this->InHeader=false;
$this->InFooter=false;
$this->lasth=0;
$this->FontFamily='';
$this->FontStyle='';
$this->FontSizePt=12;
$this->underline=false;
$this->DrawColor='0 G';
$this->FillColor='0 g';
$this->TextColor='0 g';
$this->ColorFlag=false;
$this->ws=0;
//Standard fonts
$this->CoreFonts=array('courier'=>'Courier', 'courierB'=>'Courier-Bold', 'courierI'=>'Courier-Oblique', 'courierBI'=>'Courier-BoldOblique',
 'helvetica'=>'Helvetica', 'helveticaB'=>'Helvetica-Bold', 'helveticaI'=>'Helvetica-Oblique', 'helveticaBI'=>'Helvetica-BoldOblique',
 'times'=>'Times-Roman', 'timesB'=>'Times-Bold', 'timesI'=>'Times-Italic', 'timesBI'=>'Times-BoldItalic',
 'symbol'=>'Symbol', 'zapfdingbats'=>'ZapfDingbats');
//Scale factor
if($unit=='pt')
 $this->k=1;
elseif($unit=='mm')
 $this->k=72/25.4;
elseif($unit=='cm')
 $this->k=72/2.54;
elseif($unit=='in')
 $this->k=72;
else
 $this->Error('Incorrect unit: '.$unit);
//Page format
$this->PageFormats=array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28),
 'letter'=>array(612,792), 'legal'=>array(612,1008));
if(is_string($format))
 $format=$this->_getpageformat($format);
$this->DefPageFormat=$format;
$this->CurPageFormat=$format;
//Page orientation
$orientation=strtolower($orientation);
if($orientation=='p' || $orientation=='portrait')
{
 $this->DefOrientation='P';
 $this->w=$this->DefPageFormat[0];
 $this->h=$this->DefPageFormat[1];
}
elseif($orientation=='l' || $orientation=='landscape')
{
 $this->DefOrientation='L';
 $this->w=$this->DefPageFormat[1];
 $this->h=$this->DefPageFormat[0];
}
else
 $this->Error('Incorrect orientation: '.$orientation);
$this->CurOrientation=$this->DefOrientation;
$this->wPt=$this->w*$this->k;
$this->hPt=$this->h*$this->k;
//Page margins (1 cm)
$margin=28.35/$this->k;
$this->SetMargins($margin,$margin);
//Interior cell margin (1 mm)
$this->cMargin=$margin/10;
//Line width (0.2 mm)
$this->LineWidth=.567/$this->k;
//Automatic page break
$this->SetAutoPageBreak(true,2*$margin);
//Full width display mode
$this->SetDisplayMode('fullwidth');
//Enable compression
$this->SetCompression(true);
//Set default PDF version number
$this->PDFVersion='1.3';
}
function SetMargins($left, $top, $right=null)
{
echo 'fpdf-SetMargins';
//Set left, top and right margins
$this->lMargin=$left;
$this->tMargin=$top;
if($right===null)
 $right=$left;
$this->rMargin=$right;
}
function SetLeftMargin($margin)
{
//Set left margin
echo 'fpdf-SetLeftMargin';
$this->lMargin=$margin;
if($this->page>0 && $this->x<$margin)
 $this->x=$margin;
}
function SetTopMargin($margin)
{
//Set top margin
echo 'fpdf-SetTopMargin';
$this->tMargin=$margin;
}
function SetRightMargin($margin)
{
//Set right margin
echo 'fpdf-SetRightMargin';
$this->rMargin=$margin;
}
function SetAutoPageBreak($auto, $margin=0)
{
//Set auto page break mode and triggering margin
echo 'fpdf-SetAutoPageBreak';
$this->AutoPageBreak=$auto;
$this->bMargin=$margin;
$this->PageBreakTrigger=$this->h-$margin;
}
function SetDisplayMode($zoom, $layout='continuous')
{
//Set display mode in viewer
echo 'fpdf-SetDisplayMode';
if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom))
 $this->ZoomMode=$zoom;
else
 $this->Error('Incorrect zoom display mode: '.$zoom);
if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default')
 $this->LayoutMode=$layout;
else
 $this->Error('Incorrect layout display mode: '.$layout);
}
function SetCompression($compress)
{
//Set page compression
echo 'fpdf-SetCompression';
if(function_exists('gzcompress'))
 $this->compress=$compress;
else
 $this->compress=false;
}
function SetTitle($title, $isUTF8=false)
{
echo 'fpdf-SetTitle';
//Title of document
if($isUTF8)
 $title=$this->_UTF8toUTF16($title);
$this->title=$title;
}
function SetSubject($subject, $isUTF8=false)
{
//Subject of document
echo 'fpdf-SetSubject';
if($isUTF8)
 $subject=$this->_UTF8toUTF16($subject);
$this->subject=$subject;
}
function SetAuthor($author, $isUTF8=false)
{
//Author of document
echo 'fpdf-SetAuthor';
if($isUTF8)
 $author=$this->_UTF8toUTF16($author);
$this->author=$author;
}
function SetKeywords($keywords, $isUTF8=false)
{
//Keywords of document
echo 'fpdf-SetKeywords';
if($isUTF8)
 $keywords=$this->_UTF8toUTF16($keywords);
$this->keywords=$keywords;
}
function SetCreator($creator, $isUTF8=false)
{
//Creator of document
echo 'fpdf-SetCreator';
if($isUTF8)
 $creator=$this->_UTF8toUTF16($creator);
$this->creator=$creator;
}
function AliasNbPages($alias='{nb}')
{
//Define an alias for total number of pages
echo 'fpdf-AliasNbPages';
$this->AliasNbPages=$alias;
}
function Error($msg)
{
//Fatal error
echo 'fpdf-Error';
die('<b>FPDF error:</b> '.$msg);
}
function Open()
{
//Begin document
echo 'fpdf-Open';
$this->state=1;
}
function Close()
{
//Terminate document
echo 'fpdf-Close';
if($this->state==3)
 return;
if($this->page==0)
 $this->AddPage();
//Page footer
$this->InFooter=true;
$this->Footer();
$this->InFooter=false;
//Close page
$this->_endpage();
//Close document
$this->_enddoc();
}
function AddPage($orientation='', $format='')
{
//Start a new page
echo 'fpdf-AddPage';
if($this->state==0)
 $this->Open();
$family=$this->FontFamily;
$style=$this->FontStyle.($this->underline ? 'U' : '');
$size=$this->FontSizePt;
$lw=$this->LineWidth;
$dc=$this->DrawColor;
$fc=$this->FillColor;
$tc=$this->TextColor;
$cf=$this->ColorFlag;
if($this->page>0)
{
 //Page footer
 $this->InFooter=true;
 $this->Footer();
 $this->InFooter=false;
 //Close page
 $this->_endpage();
}
//Start new page
$this->_beginpage($orientation,$format);
//Set line cap style to square
$this->_out('2 J');
//Set line width
$this->LineWidth=$lw;
$this->_out(sprintf('%.2F w',$lw*$this->k));
//Set font
if($family)
 $this->SetFont($family,$style,$size);
//Set colors
$this->DrawColor=$dc;
if($dc!='0 G')
 $this->_out($dc);
$this->FillColor=$fc;
if($fc!='0 g')
 $this->_out($fc);
$this->TextColor=$tc;
$this->ColorFlag=$cf;
//Page header
$this->InHeader=true;
$this->Header();
$this->InHeader=false;
//Restore line width
if($this->LineWidth!=$lw)
{
 $this->LineWidth=$lw;
 $this->_out(sprintf('%.2F w',$lw*$this->k));
}
//Restore font
if($family)
 $this->SetFont($family,$style,$size);
//Restore colors
if($this->DrawColor!=$dc)
{
 $this->DrawColor=$dc;
 $this->_out($dc);
}
if($this->FillColor!=$fc)
{
 $this->FillColor=$fc;
 $this->_out($fc);
}
$this->TextColor=$tc;
$this->ColorFlag=$cf;
}
function Header()
{
//To be implemented in your own inherited class
}
function Footer()
{
//To be implemented in your own inherited class
}
function PageNo()
{
//Get current page number
echo 'fpdf-PageNo';
return $this->page;
}
function SetDrawColor($r, $g=null, $b=null)
{
//Set color for all stroking operations
echo 'fpdf-SetDrawColor';
if(($r==0 && $g==0 && $b==0) || $g===null)
 $this->DrawColor=sprintf('%.3F G',$r/255);
else
 $this->DrawColor=sprintf('%.3F %.3F %.3F RG',$r/255,$g/255,$b/255);
if($this->page>0)
 $this->_out($this->DrawColor);
}
function SetFillColor($r, $g=null, $b=null)
{
//Set color for all filling operations
echo 'fpdf-SetFillColor';
if(($r==0 && $g==0 && $b==0) || $g===null)
 $this->FillColor=sprintf('%.3F g',$r/255);
else
 $this->FillColor=sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255);
$this->ColorFlag=($this->FillColor!=$this->TextColor);
if($this->page>0)
 $this->_out($this->FillColor);
}
function SetTextColor($r, $g=null, $b=null)
{
//Set color for text
echo 'fpdf-SetTextColor';
if(($r==0 && $g==0 && $b==0) || $g===null)
 $this->TextColor=sprintf('%.3F g',$r/255);
else
 $this->TextColor=sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255);
$this->ColorFlag=($this->FillColor!=$this->TextColor);
}
function GetStringWidth($s)
{
//Get width of a string in the current font
echo 'fpdf-GetStringWidth';
$s=(string)$s;
$cw=&$this->CurrentFont['cw'];
$w=0;
$l=strlen($s);
for($i=0;$i<$l;$i++)
 $w+=$cw[$s[$i]];
return $w*$this->FontSize/1000;
}
function SetLineWidth($width)
{
//Set line width
echo 'fpdf-SetLineWidth';
$this->LineWidth=$width;
if($this->page>0)
 $this->_out(sprintf('%.2F w',$width*$this->k));
}
function Line($x1, $y1, $x2, $y2)
{
//Draw a line
echo 'fpdf-Line';
$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));
}
function Rect($x, $y, $w, $h, $style='')
{
//Draw a rectangle
echo 'fpdf-Rect';
if($style=='F')
 $op='f';
elseif($style=='FD' || $style=='DF')
 $op='B';
else
 $op='S';
$this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
}
function AddFont($family, $style='', $file='')
{
//Add a TrueType or Type1 font
echo 'fpdf-AddFont';
$family=strtolower($family);
if($file=='')
 $file=str_replace(' ','',$family).strtolower($style).'.php';
if($family=='arial')
 $family='helvetica';
$style=strtoupper($style);
if($style=='IB')
 $style='BI';
$fontkey=$family.$style;
if(isset($this->fonts[$fontkey]))
 return;
include($this->_getfontpath().$file);
if(!isset($name))
 $this->Error('Could not include font definition file');
$i=count($this->fonts)+1;
$this->fonts[$fontkey]=array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file);
if($diff)
{
 //Search existing encodings
 $d=0;
 $nb=count($this->diffs);
 for($i=1;$i<=$nb;$i++)
 {
  if($this->diffs[$i]==$diff)
  {
   $d=$i;
   break;
  }
 }
 if($d==0)
 {
  $d=$nb+1;
  $this->diffs[$d]=$diff;
 }
 $this->fonts[$fontkey]['diff']=$d;
}
if($file)
{
 if($type=='TrueType')
  $this->FontFiles[$file]=array('length1'=>$originalsize);
 else
  $this->FontFiles[$file]=array('length1'=>$size1, 'length2'=>$size2);
}
}
function SetFont($family, $style='', $size=0)
{
//Select a font; size given in points
echo '  fpdf-SetFont  ';
global $fpdf_charwidths;
$family=strtolower($family);
if($family=='')
 $family=$this->FontFamily;
if($family=='arial')
 $family='helvetica';
elseif($family=='symbol' || $family=='zapfdingbats')
 $style='';
$style=strtoupper($style);
if(strpos($style,'U')!==false)
{
 $this->underline=true;
 $style=str_replace('U','',$style);
}
else
 $this->underline=false;
if($style=='IB')
 $style='BI';
if($size==0)
 $size=$this->FontSizePt;
//Test if font is already selected
echo '  fpdf-SetFont-11111  ';
if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size)
 return;
//Test if used for the first time
$fontkey=$family.$style;
echo '  fpdf-SetFont-22222  ';
echo '  $fontkey  ' .$fontkey;
if(!isset($this->fonts[$fontkey]))
{
 //Check if one of the standard fonts
 echo '  fpdf-SetFont-33333  ';
 if(isset($this->CoreFonts[$fontkey]))
 {
  echo '  fpdf-SetFont-33333-OUI  ';
  if(!isset($fpdf_charwidths[$fontkey]))
  {
   //Load metric file
   $file=$family;
   //$file.=$file.'b';
   echo '  $family  ' .$file;
   if($family=='times' || $family=='helvetica')
 $file.=strtolower($style);
 echo 'lower555';
   include('$this->_getfontpath()'.$file.'.php');
 echo 'lower666';
   if(!isset($fpdf_charwidths[$fontkey]))
 $this->Error('Could not include font metric file');
  }
  $i=count($this->fonts)+1;
  $name=$this->CoreFonts[$fontkey];
  $cw=$fpdf_charwidths[$fontkey];
  $this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$name, 'up'=>-100, 'ut'=>50, 'cw'=>$cw);
 }
 else
  echo '  fpdf-SetFont-33333-NON  ';
  $this->Error('Undefined font: '.$family.' '.$style);
}
//Select it
$this->FontFamily=$family;
$this->FontStyle=$style;
$this->FontSizePt=$size;
$this->FontSize=$size/$this->k;
$this->CurrentFont=&$this->fonts[$fontkey];
if($this->page>0)
 $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
}
function SetFontSize($size)
{
//Set font size in points
echo 'fpdf-SetFontSize';
if($this->FontSizePt==$size)
 return;
$this->FontSizePt=$size;
$this->FontSize=$size/$this->k;
if($this->page>0)
 $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
}
function AddLink()
{
//Create a new internal link
echo 'fpdf-AddLink';
$n=count($this->links)+1;
$this->links[$n]=array(0, 0);
return $n;
}
function SetLink($link, $y=0, $page=-1)
{
//Set destination of internal link
echo 'fpdf-SetLink';
if($y==-1)
 $y=$this->y;
if($page==-1)
 $page=$this->page;
$this->links[$link]=array($page, $y);
}
function Link($x, $y, $w, $h, $link)
{
//Put a link on the page
echo 'fpdf-Link';
$this->PageLinks[$this->page][]=array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link);
}
function Text($x, $y, $txt)
{
echo 'fpdf-Text';
//Output a string
$s=sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
if($this->underline && $txt!='')
 $s.=' '.$this->_dounderline($x,$y,$txt);
if($this->ColorFlag)
 $s='q '.$this->TextColor.' '.$s.' Q';
$this->_out($s);
}
function AcceptPageBreak()
{
//Accept automatic page break or not
echo 'fpdf-AcceptPageBreak';
return $this->AutoPageBreak;
}
function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
{
//Output a cell
echo 'fpdf-Cell';
$k=$this->k;
if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())
{
 //Automatic page break
 $x=$this->x;
 $ws=$this->ws;
 if($ws>0)
 {
  $this->ws=0;
  $this->_out('0 Tw');
 }
 $this->AddPage($this->CurOrientation,$this->CurPageFormat);
 $this->x=$x;
 if($ws>0)
 {
  $this->ws=$ws;
  $this->_out(sprintf('%.3F Tw',$ws*$k));
 }
}
if($w==0)
 $w=$this->w-$this->rMargin-$this->x;
$s='';
if($fill || $border==1)
{
 if($fill)
  $op=($border==1) ? 'B' : 'f';
 else
  $op='S';
 $s=sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
}
if(is_string($border))
{
 $x=$this->x;
 $y=$this->y;
 if(strpos($border,'L')!==false)
  $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
 if(strpos($border,'T')!==false)
  $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
 if(strpos($border,'R')!==false)
  $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
 if(strpos($border,'B')!==false)
  $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
}
if($txt!=='')
{
 if($align=='R')
  $dx=$w-$this->cMargin-$this->GetStringWidth($txt);
 elseif($align=='C')
  $dx=($w-$this->GetStringWidth($txt))/2;
 else
  $dx=$this->cMargin;
 if($this->ColorFlag)
  $s.='q '.$this->TextColor.' ';
 $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
 $s.=sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2);
 if($this->underline)
  $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
 if($this->ColorFlag)
  $s.=' Q';
 if($link)
  $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link);
}
if($s)
 $this->_out($s);
$this->lasth=$h;
if($ln>0)
{
 //Go to next line
 $this->y+=$h;
 if($ln==1)
  $this->x=$this->lMargin;
}
else
 $this->x+=$w;
}
function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false)
{
//Output text with automatic or explicit line breaks
echo 'fpdf-MultiCell';
$cw=&$this->CurrentFont['cw'];
if($w==0)
 $w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
if($nb>0 && $s[$nb-1]=="\n")
 $nb--;
$b=0;
if($border)
{
 if($border==1)
 {
  $border='LTRB';
  $b='LRT';
  $b2='LR';
 }
 else
 {
  $b2='';
  if(strpos($border,'L')!==false)
   $b2.='L';
  if(strpos($border,'R')!==false)
   $b2.='R';
  $b=(strpos($border,'T')!==false) ? $b2.'T' : $b2;
 }
}
$sep=-1;
$i=0;
$j=0;
$l=0;
$ns=0;
$nl=1;
while($i<$nb)
{
 //Get next character
 $c=$s[$i];
 if($c=="\n")
 {
  //Explicit line break
  if($this->ws>0)
  {
   $this->ws=0;
   $this->_out('0 Tw');
  }
  $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
  $i++;
  $sep=-1;
  $j=$i;
  $l=0;
  $ns=0;
  $nl++;
  if($border && $nl==2)
   $b=$b2;
  continue;
 }
 if($c==' ')
 {
  $sep=$i;
  $ls=$l;
  $ns++;
 }
 $l+=$cw[$c];
 if($l>$wmax)
 {
  //Automatic line break
  if($sep==-1)
  {
   if($i==$j)
 $i++;
   if($this->ws>0)
   {
 $this->ws=0;
 $this->_out('0 Tw');
   }
   $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
  }
  else
  {
   if($align=='J')
   {
 $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
 $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
   }
   $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
   $i=$sep+1;
  }
  $sep=-1;
  $j=$i;
  $l=0;
  $ns=0;
  $nl++;
  if($border && $nl==2)
   $b=$b2;
 }
 else
  $i++;
}
//Last chunk
if($this->ws>0)
{
 $this->ws=0;
 $this->_out('0 Tw');
}
if($border && strpos($border,'B')!==false)
 $b.='B';
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
$this->x=$this->lMargin;
}
function Write($h, $txt, $link='')
{
//Output text in flowing mode
echo 'fpdf-Write';
$cw=&$this->CurrentFont['cw'];
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
$sep=-1;
$i=0;
$j=0;
$l=0;
$nl=1;
while($i<$nb)
{
 //Get next character
 $c=$s[$i];
 if($c=="\n")
 {
  //Explicit line break
  $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link);
  $i++;
  $sep=-1;
  $j=$i;
  $l=0;
  if($nl==1)
  {
   $this->x=$this->lMargin;
   $w=$this->w-$this->rMargin-$this->x;
   $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  }
  $nl++;
  continue;
 }
 if($c==' ')
  $sep=$i;
 $l+=$cw[$c];
 if($l>$wmax)
 {
  //Automatic line break
  if($sep==-1)
  {
   if($this->x>$this->lMargin)
   {
 //Move to next line
 $this->x=$this->lMargin;
 $this->y+=$h;
 $w=$this->w-$this->rMargin-$this->x;
 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
 $i++;
 $nl++;
 continue;
   }
   if($i==$j)
 $i++;
   $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link);
  }
  else
  {
   $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link);
   $i=$sep+1;
  }
  $sep=-1;
  $j=$i;
  $l=0;
  if($nl==1)
  {
   $this->x=$this->lMargin;
   $w=$this->w-$this->rMargin-$this->x;
   $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  }
  $nl++;
 }
 else
  $i++;
}
//Last chunk
if($i!=$j)
 $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link);
}
function Ln($h=null)
{
//Line feed; default value is last cell height
echo 'fpdf-Ln';
$this->x=$this->lMargin;
if($h===null)
 $this->y+=$this->lasth;
else
 $this->y+=$h;
}
function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='')
{
//Put an image on the page
echo 'fpdf-Image';
if(!isset($this->images[$file]))
{
 //First use of this image, get info
 if($type=='')
 {
  $pos=strrpos($file,'.');
  if(!$pos)
   $this->Error('Image file has no extension and no type was specified: '.$file);
  $type=substr($file,$pos+1);
 }
 $type=strtolower($type);
 if($type=='jpeg')
  $type='jpg';
 $mtd='_parse'.$type;
 if(!method_exists($this,$mtd))
  $this->Error('Unsupported image type: '.$type);
 $info=$this->$mtd($file);
 $info['i']=count($this->images)+1;
 $this->images[$file]=$info;
}
else
 $info=$this->images[$file];
//Automatic width and height calculation if needed
if($w==0 && $h==0)
{
 //Put image at 72 dpi
 $w=$info['w']/$this->k;
 $h=$info['h']/$this->k;
}
elseif($w==0)
 $w=$h*$info['w']/$info['h'];
elseif($h==0)
 $h=$w*$info['h']/$info['w'];
//Flowing mode
if($y===null)
{
 if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())
 {
  //Automatic page break
  $x2=$this->x;
  $this->AddPage($this->CurOrientation,$this->CurPageFormat);
  $this->x=$x2;
 }
 $y=$this->y;
 $this->y+=$h;
}
if($x===null)
 $x=$this->x;
$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']));
if($link)
 $this->Link($x,$y,$w,$h,$link);
}
function GetX()
{
//Get x position
echo 'fpdf-GetX';
return $this->x;
}
function SetX($x)
{
//Set x position
echo 'fpdf-SetX';
if($x>=0)
 $this->x=$x;
else
 $this->x=$this->w+$x;
}
function GetY()
{
//Get y position
echo 'fpdf-GetY';
return $this->y;
}
function SetY($y)
{
//Set y position and reset x
echo 'fpdf-SetY';
$this->x=$this->lMargin;
if($y>=0)
 $this->y=$y;
else
 $this->y=$this->h+$y;
}
function SetXY($x, $y)
{
//Set x and y positions
echo 'fpdf-SetXY';
$this->SetY($y);
$this->SetX($x);
}
function Output($name='', $dest='')
{
//Output PDF to some destination
echo 'fpdf-Output';
if($this->state<3)
 $this->Close();
$dest=strtoupper($dest);
if($dest=='')
{
 if($name=='')
 {
  $name='doc.pdf';
  $dest='I';
 }
 else
  $dest='F';
}
switch($dest)
{
 case 'I':
  //Send to standard output
  if(ob_get_length())
   $this->Error('Some data has already been output, can\'t send PDF file');
  if(php_sapi_name()!='cli')
  {
   //We send to a browser
   header('Content-Type: application/pdf');
   if(headers_sent())
 $this->Error('Some data has already been output, can\'t send PDF file');
   header('Content-Length: '.strlen($this->buffer));
   header('Content-Disposition: inline; filename="'.$name.'"');
   header('Cache-Control: private, max-age=0, must-revalidate');
   header('Pragma: public');
   ini_set('zlib.output_compression','0');
  }
  echo $this->buffer;
  break;
 case 'D':
  //Download file
  if(ob_get_length())
   $this->Error('Some data has already been output, can\'t send PDF file');
  header('Content-Type: application/x-download');
  if(headers_sent())
   $this->Error('Some data has already been output, can\'t send PDF file');
  header('Content-Length: '.strlen($this->buffer));
  header('Content-Disposition: attachment; filename="'.$name.'"');
  header('Cache-Control: private, max-age=0, must-revalidate');
  header('Pragma: public');
  ini_set('zlib.output_compression','0');
  echo $this->buffer;
  break;
 case 'F':
  //Save to local file
  $f=fopen($name,'wb');
  if(!$f)
   $this->Error('Unable to create output file: '.$name);
  fwrite($f,$this->buffer,strlen($this->buffer));
  fclose($f);
  break;
 case 'S':
  //Return as a string
  return $this->buffer;
 default:
  $this->Error('Incorrect output destination: '.$dest);
}
return '';
}
/*******************************************************************************
*																			  *
*							  Protected methods							   *
*																			  *
*******************************************************************************/
function _dochecks()
{
//Check availability of %F
echo 'fpdf-_dochecks';
if(sprintf('%.1F',1.0)!='1.0')
 $this->Error('This version of PHP is not supported');
//Check mbstring overloading
if(ini_get('mbstring.func_overload') & 2)
 $this->Error('mbstring overloading must be disabled');
}
function _getpageformat($format)
{
echo 'fpdf-_getpageformat';
$format=strtolower($format);
if(!isset($this->PageFormats[$format]))
 $this->Error('Unknown page format: '.$format);
$a=$this->PageFormats[$format];
return array($a[0]/$this->k, $a[1]/$this->k);
}
function _getfontpath()
{
echo 'fpdf-_getfontpath';
if(!defined('FPDF_FONTPATH') && is_dir(dirname(__FILE__).'/font'))
 define('FPDF_FONTPATH',dirname(__FILE__).'/font/');
  //echo ' FPDF_FONTPATH333: ' .FPDF_FONTPATH;
return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : '';
}
function _beginpage($orientation, $format)
{
echo 'fpdf-_beginpage';
$this->page++;
$this->pages[$this->page]='';
$this->state=2;
$this->x=$this->lMargin;
$this->y=$this->tMargin;
$this->FontFamily='';
//Check page size
if($orientation=='')
 $orientation=$this->DefOrientation;
else
 $orientation=strtoupper($orientation[0]);
if($format=='')
 $format=$this->DefPageFormat;
else
{
 if(is_string($format))
  $format=$this->_getpageformat($format);
}
if($orientation!=$this->CurOrientation || $format[0]!=$this->CurPageFormat[0] || $format[1]!=$this->CurPageFormat[1])
{
 //New size
 if($orientation=='P')
 {
  $this->w=$format[0];
  $this->h=$format[1];
 }
 else
 {
  $this->w=$format[1];
  $this->h=$format[0];
 }
 $this->wPt=$this->w*$this->k;
 $this->hPt=$this->h*$this->k;
 $this->PageBreakTrigger=$this->h-$this->bMargin;
 $this->CurOrientation=$orientation;
 $this->CurPageFormat=$format;
}
if($orientation!=$this->DefOrientation || $format[0]!=$this->DefPageFormat[0] || $format[1]!=$this->DefPageFormat[1])
 $this->PageSizes[$this->page]=array($this->wPt, $this->hPt);
}
function _endpage()
{
echo 'fpdf-_endpage';
$this->state=1;
}
function _escape($s)
{
//Escape special characters in strings
echo 'fpdf-_escape';
$s=str_replace('\\','\\\\',$s);
$s=str_replace('(','\\(',$s);
$s=str_replace(')','\\)',$s);
$s=str_replace("\r",'\\r',$s);
return $s;
}
function _textstring($s)
{
//Format a text string
echo 'fpdf-_textstring';
return '('.$this->_escape($s).')';
}
function _UTF8toUTF16($s)
{
//Convert UTF-8 to UTF-16BE with BOM
echo 'fpdf-_UTF8toUTF16';
$res="\xFE\xFF";
$nb=strlen($s);
$i=0;
while($i<$nb)
{
 $c1=ord($s[$i++]);
 if($c1>=224)
 {
  //3-byte character
  $c2=ord($s[$i++]);
  $c3=ord($s[$i++]);
  $res.=chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2));
  $res.=chr((($c2 & 0x03)<<6) + ($c3 & 0x3F));
 }
 elseif($c1>=192)
 {
  //2-byte character
  $c2=ord($s[$i++]);
  $res.=chr(($c1 & 0x1C)>>2);
  $res.=chr((($c1 & 0x03)<<6) + ($c2 & 0x3F));
 }
 else
 {
  //Single-byte character
  $res.="\0".chr($c1);
 }
}
return $res;
}
function _dounderline($x, $y, $txt)
{
//Underline text
echo 'fpdf-_dounderline';
$up=$this->CurrentFont['up'];
$ut=$this->CurrentFont['ut'];
$w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' ');
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);
}
function _parsejpg($file)
{
//Extract info from a JPEG file
echo 'fpdf-_parsejpg';
$a=GetImageSize($file);
if(!$a)
 $this->Error('Missing or incorrect image file: '.$file);
if($a[2]!=2)
 $this->Error('Not a JPEG file: '.$file);
if(!isset($a['channels']) || $a['channels']==3)
 $colspace='DeviceRGB';
elseif($a['channels']==4)
 $colspace='DeviceCMYK';
else
 $colspace='DeviceGray';
$bpc=isset($a['bits']) ? $a['bits'] : 8;
//Read whole file
$f=fopen($file,'rb');
$data='';
while(!feof($f))
 $data.=fread($f,8192);
fclose($f);
return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data);
}
function _parsepng($file)
{
echo 'fpdf-_parsepng';
//Extract info from a PNG file
$f=fopen($file,'rb');
if(!$f)
 $this->Error('Can\'t open image file: '.$file);
//Check signature
if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10))
 $this->Error('Not a PNG file: '.$file);
//Read header chunk
$this->_readstream($f,4);
if($this->_readstream($f,4)!='IHDR')
 $this->Error('Incorrect PNG file: '.$file);
$w=$this->_readint($f);
$h=$this->_readint($f);
$bpc=ord($this->_readstream($f,1));
if($bpc>8)
 $this->Error('16-bit depth not supported: '.$file);
$ct=ord($this->_readstream($f,1));
if($ct==0)
 $colspace='DeviceGray';
elseif($ct==2)
 $colspace='DeviceRGB';
elseif($ct==3)
 $colspace='Indexed';
else
 $this->Error('Alpha channel not supported: '.$file);
if(ord($this->_readstream($f,1))!=0)
 $this->Error('Unknown compression method: '.$file);
if(ord($this->_readstream($f,1))!=0)
 $this->Error('Unknown filter method: '.$file);
if(ord($this->_readstream($f,1))!=0)
 $this->Error('Interlacing not supported: '.$file);
$this->_readstream($f,4);
$parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
//Scan chunks looking for palette, transparency and image data
$pal='';
$trns='';
$data='';
do
{
 $n=$this->_readint($f);
 $type=$this->_readstream($f,4);
 if($type=='PLTE')
 {
  //Read palette
  $pal=$this->_readstream($f,$n);
  $this->_readstream($f,4);
 }
 elseif($type=='tRNS')
 {
  //Read transparency info
  $t=$this->_readstream($f,$n);
  if($ct==0)
   $trns=array(ord(substr($t,1,1)));
  elseif($ct==2)
   $trns=array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1)));
  else
  {
   $pos=strpos($t,chr(0));
   if($pos!==false)
 $trns=array($pos);
  }
  $this->_readstream($f,4);
 }
 elseif($type=='IDAT')
 {
  //Read image data block
  $data.=$this->_readstream($f,$n);
  $this->_readstream($f,4);
 }
 elseif($type=='IEND')
  break;
 else
  $this->_readstream($f,$n+4);
}
while($n);
if($colspace=='Indexed' && empty($pal))
 $this->Error('Missing palette in '.$file);
fclose($f);
return array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'parms'=>$parms, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data);
}
function _readstream($f, $n)
{
echo 'fpdf-_readstream';
//Read n bytes from stream
$res='';
while($n>0 && !feof($f))
{
 $s=fread($f,$n);
 if($s===false)
  $this->Error('Error while reading stream');
 $n-=strlen($s);
 $res.=$s;
}
if($n>0)
 $this->Error('Unexpected end of stream');
return $res;
}
function _readint($f)
{
//Read a 4-byte integer from stream
echo 'fpdf-_readint';
$a=unpack('Ni',$this->_readstream($f,4));
return $a['i'];
}
function _parsegif($file)
{
//Extract info from a GIF file (via PNG conversion)
echo 'fpdf-_parsegif';
if(!function_exists('imagepng'))
 $this->Error('GD extension is required for GIF support');
if(!function_exists('imagecreatefromgif'))
 $this->Error('GD has no GIF read support');
$im=imagecreatefromgif($file);
if(!$im)
 $this->Error('Missing or incorrect image file: '.$file);
imageinterlace($im,0);
$tmp=tempnam('.','gif');
if(!$tmp)
 $this->Error('Unable to create a temporary file');
if(!imagepng($im,$tmp))
 $this->Error('Error while saving to temporary file');
imagedestroy($im);
$info=$this->_parsepng($tmp);
unlink($tmp);
return $info;
}
function _newobj()
{
//Begin a new object
echo 'fpdf-_newobj';
$this->n++;
$this->offsets[$this->n]=strlen($this->buffer);
$this->_out($this->n.' 0 obj');
}
function _putstream($s)
{
echo 'fpdf-_putstream';
$this->_out('stream');
$this->_out($s);
$this->_out('endstream');
}
function _out($s)
{
//Add a line to the document
echo 'fpdf-_out';
/*if($this->state==2)
 $this->pages[$this->page].=$s."\n";
else
 $this->buffer.=$s."\n";*/
}
function _putpages()
{
echo 'fpdf-_putpages';
$nb=$this->page;
if(!empty($this->AliasNbPages))
{
 //Replace number of pages
 for($n=1;$n<=$nb;$n++)
  $this->pages[$n]=str_replace($this->AliasNbPages,$nb,$this->pages[$n]);
}
if($this->DefOrientation=='P')
{
 $wPt=$this->DefPageFormat[0]*$this->k;
 $hPt=$this->DefPageFormat[1]*$this->k;
}
else
{
 $wPt=$this->DefPageFormat[1]*$this->k;
 $hPt=$this->DefPageFormat[0]*$this->k;
}
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
for($n=1;$n<=$nb;$n++)
{
 //Page
 $this->_newobj();
 $this->_out('<</Type /Page');
 $this->_out('/Parent 1 0 R');
 if(isset($this->PageSizes[$n]))
  $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageSizes[$n][0],$this->PageSizes[$n][1]));
 $this->_out('/Resources 2 0 R');
 if(isset($this->PageLinks[$n]))
 {
  //Links
  $annots='/Annots [';
  foreach($this->PageLinks[$n] as $pl)
  {
   $rect=sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
   $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
   if(is_string($pl[4]))
 $annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>';
   else
   {
 $l=$this->links[$pl[4]];
 $h=isset($this->PageSizes[$l[0]]) ? $this->PageSizes[$l[0]][1] : $hPt;
 $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',1+2*$l[0],$h-$l[1]*$this->k);
   }
  }
  $this->_out($annots.']');
 }
 $this->_out('/Contents '.($this->n+1).' 0 R>>');
 $this->_out('endobj');
 //Page content
 $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n];
 $this->_newobj();
 $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
 $this->_putstream($p);
 $this->_out('endobj');
}
//Pages root
$this->offsets[1]=strlen($this->buffer);
$this->_out('1 0 obj');
$this->_out('<</Type /Pages');
$kids='/Kids [';
for($i=0;$i<$nb;$i++)
 $kids.=(3+2*$i).' 0 R ';
$this->_out($kids.']');
$this->_out('/Count '.$nb);
$this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$wPt,$hPt));
$this->_out('>>');
$this->_out('endobj');
}
function _putfonts()
{
echo 'fpdf-_putfonts';
$nf=$this->n;
foreach($this->diffs as $diff)
{
 //Encodings
 $this->_newobj();
 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
 $this->_out('endobj');
}
foreach($this->FontFiles as $file=>$info)
{
 //Font file embedding
 $this->_newobj();
 $this->FontFiles[$file]['n']=$this->n;
 $font='';
 $f=fopen($this->_getfontpath().$file,'rb',1);
 if(!$f)
  $this->Error('Font file not found');
 while(!feof($f))
  $font.=fread($f,8192);
 fclose($f);
 $compressed=(substr($file,-2)=='.z');
 if(!$compressed && isset($info['length2']))
 {
  $header=(ord($font[0])==128);
  if($header)
  {
   //Strip first binary header
   $font=substr($font,6);
  }
  if($header && ord($font[$info['length1']])==128)
  {
   //Strip second binary header
   $font=substr($font,0,$info['length1']).substr($font,$info['length1']+6);
  }
 }
 $this->_out('<</Length '.strlen($font));
 if($compressed)
  $this->_out('/Filter /FlateDecode');
 $this->_out('/Length1 '.$info['length1']);
 if(isset($info['length2']))
  $this->_out('/Length2 '.$info['length2'].' /Length3 0');
 $this->_out('>>');
 $this->_putstream($font);
 $this->_out('endobj');
}
foreach($this->fonts as $k=>$font)
{
 //Font objects
 $this->fonts[$k]['n']=$this->n+1;
 $type=$font['type'];
 $name=$font['name'];
 if($type=='core')
 {
  //Standard font
  $this->_newobj();
  $this->_out('<</Type /Font');
  $this->_out('/BaseFont /'.$name);
  $this->_out('/Subtype /Type1');
  if($name!='Symbol' && $name!='ZapfDingbats')
   $this->_out('/Encoding /WinAnsiEncoding');
  $this->_out('>>');
  $this->_out('endobj');
 }
 elseif($type=='Type1' || $type=='TrueType')
 {
  //Additional Type1 or TrueType font
  $this->_newobj();
  $this->_out('<</Type /Font');
  $this->_out('/BaseFont /'.$name);
  $this->_out('/Subtype /'.$type);
  $this->_out('/FirstChar 32 /LastChar 255');
  $this->_out('/Widths '.($this->n+1).' 0 R');
  $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  if($font['enc'])
  {
   if(isset($font['diff']))
 $this->_out('/Encoding '.($nf+$font['diff']).' 0 R');
   else
 $this->_out('/Encoding /WinAnsiEncoding');
  }
  $this->_out('>>');
  $this->_out('endobj');
  //Widths
  $this->_newobj();
  $cw=&$font['cw'];
  $s='[';
  for($i=32;$i<=255;$i++)
   $s.=$cw[chr($i)].' ';
  $this->_out($s.']');
  $this->_out('endobj');
  //Descriptor
  $this->_newobj();
  $s='<</Type /FontDescriptor /FontName /'.$name;
  foreach($font['desc'] as $k=>$v)
   $s.=' /'.$k.' '.$v;
  $file=$font['file'];
  if($file)
   $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
  $this->_out($s.'>>');
  $this->_out('endobj');
 }
 else
 {
  //Allow for additional types
  $mtd='_put'.strtolower($type);
  if(!method_exists($this,$mtd))
   $this->Error('Unsupported font type: '.$type);
  $this->$mtd($font);
 }
}
}
function _putimages()
{
echo 'fpdf-_putimages';
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
reset($this->images);
while(list($file,$info)=each($this->images))
{
 $this->_newobj();
 $this->images[$file]['n']=$this->n;
 $this->_out('<</Type /XObject');
 $this->_out('/Subtype /Image');
 $this->_out('/Width '.$info['w']);
 $this->_out('/Height '.$info['h']);
 if($info['cs']=='Indexed')
  $this->_out('/ColorSpace [/indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
 else
 {
  $this->_out('/ColorSpace /'.$info['cs']);
  if($info['cs']=='DeviceCMYK')
   $this->_out('/Decode [1 0 1 0 1 0 1 0]');
 }
 $this->_out('/BitsPerComponent '.$info['bpc']);
 if(isset($info['f']))
  $this->_out('/Filter /'.$info['f']);
 if(isset($info['parms']))
  $this->_out($info['parms']);
 if(isset($info['trns']) && is_array($info['trns']))
 {
  $trns='';
  for($i=0;$i<count($info['trns']);$i++)
   $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
  $this->_out('/Mask ['.$trns.']');
 }
 $this->_out('/Length '.strlen($info['data']).'>>');
 $this->_putstream($info['data']);
 unset($this->images[$file]['data']);
 $this->_out('endobj');
 //Palette
 if($info['cs']=='Indexed')
 {
  $this->_newobj();
  $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  $this->_putstream($pal);
  $this->_out('endobj');
 }
}
}
function _putxobjectdict()
{
echo 'fpdf-_putxobjectdict';
foreach($this->images as $image)
 $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
}
function _putresourcedict()
{
echo 'fpdf-_putresourcedict';
$this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
$this->_out('/Font <<');
foreach($this->fonts as $font)
 $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
$this->_out('>>');
$this->_out('/XObject <<');
$this->_putxobjectdict();
$this->_out('>>');
}
function _putresources()
{
echo 'fpdf-_putresources';
$this->_putfonts();
$this->_putimages();
//Resource dictionary
$this->offsets[2]=strlen($this->buffer);
$this->_out('2 0 obj');
$this->_out('<<');
$this->_putresourcedict();
$this->_out('>>');
$this->_out('endobj');
}
function _putinfo()
{
echo 'fpdf-_putinfo';
$this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION));
if(!empty($this->title))
 $this->_out('/Title '.$this->_textstring($this->title));
if(!empty($this->subject))
 $this->_out('/Subject '.$this->_textstring($this->subject));
if(!empty($this->author))
 $this->_out('/Author '.$this->_textstring($this->author));
if(!empty($this->keywords))
 $this->_out('/Keywords '.$this->_textstring($this->keywords));
if(!empty($this->creator))
 $this->_out('/Creator '.$this->_textstring($this->creator));
$this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis')));
}
function _putcatalog()
{
echo 'fpdf-_putcatalog';
$this->_out('/Type /Catalog');
$this->_out('/Pages 1 0 R');
if($this->ZoomMode=='fullpage')
 $this->_out('/OpenAction [3 0 R /Fit]');
elseif($this->ZoomMode=='fullwidth')
 $this->_out('/OpenAction [3 0 R /FitH null]');
elseif($this->ZoomMode=='real')
 $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
elseif(!is_string($this->ZoomMode))
 $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
if($this->LayoutMode=='single')
 $this->_out('/PageLayout /SinglePage');
elseif($this->LayoutMode=='continuous')
 $this->_out('/PageLayout /OneColumn');
elseif($this->LayoutMode=='two')
 $this->_out('/PageLayout /TwoColumnLeft');
}
function _putheader()
{
echo 'fpdf-_putheader';
$this->_out('%PDF-'.$this->PDFVersion);
}
function _puttrailer()
{
echo 'fpdf-_puttrailer';
$this->_out('/Size '.($this->n+1));
$this->_out('/Root '.$this->n.' 0 R');
$this->_out('/Info '.($this->n-1).' 0 R');
}
function _enddoc()
{
echo 'fpdf-_enddoc';
$this->_putheader();
$this->_putpages();
$this->_putresources();
//Info
$this->_newobj();
$this->_out('<<');
$this->_putinfo();
$this->_out('>>');
$this->_out('endobj');
//Catalog
$this->_newobj();
$this->_out('<<');
$this->_putcatalog();
$this->_out('>>');
$this->_out('endobj');
//Cross-ref
$o=strlen($this->buffer);
$this->_out('xref');
$this->_out('0 '.($this->n+1));
$this->_out('0000000000 65535 f ');
for($i=1;$i<=$this->n;$i++)
 $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
//Trailer
$this->_out('trailer');
$this->_out('<<');
$this->_puttrailer();
$this->_out('>>');
$this->_out('startxref');
$this->_out($o);
$this->_out('%%EOF');
$this->state=3;
}
//End of class
}
//Handle special IE contype request
if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']=='contype')
{
echo 'fpdf-fin';
header('Content-Type: application/pdf');
exit;
}
?>

e code of fpdf.php

Link to comment
Share on other sites

Try this out if it is not working please put all back to normal:

change the fpdf completely to this code:

<?php
//============================================================+
// File name   : fpdf.php
// Begin	   : 2002-08-03
// Last Update : 2005-03-31
// Authors	 : Olivier PLATHEY,
//			   Nicola Asuni
// Version	 : 1.53.0.TC008
// License	 : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
//
// Description : This is a PHP5 class for generating PDF files
//			   on-the-fly without requiring external
//			   extensions.
//			   This class is an extension and improvement of
//			   the Public Domain FPDF class by Olivier Plathey
//			   (http://www.fpdf.org).
//
// Main changes by Nicola Asuni:
//  - porting to PHP5
//  - support for UTF-8 Unicode
//  - code style and formatting
//  - automatic php documentation in PhpDocumentor Style
//    (www.phpdoc.org)
//  - all ISO page formats
//============================================================+
/**
* This is a PHP5 class for generating PDF files on-the-fly without requiring external extensions.<br>
* This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
* This version contains some changes: [porting to PHP5,  support for UTF-8 Unicode,  code style and formatting,  php documentation (www.phpdoc.org),  ISO page formats,  minor improvements,  image scale factor]<br>
* Tools to encode your unicode fonts can be found at: http://www.acko.net/blog/ufpdf
* @name FPDF
* @package com.tecnick.tcpdf
* @version 1.53.0.TC011
* @author Olivier PLATHEY,  Nicola Asuni
* @link http://tcpdf.sourceforge.net
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*/
if(!class_exists('FPDF')) {
   /**
 * define default PDF document producer
 */
   define('PDF_PRODUCER', 'TCPDF 1.53.0.TC011 (http://tcpdf.sourceforge.net)');
   /**
   * This is a PHP5 class for generating PDF files on-the-fly without requiring external extensions.<br>
   * This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
   * This version contains some changes: [porting to PHP5,  support for UTF-8 Unicode,  code style and formatting,  php documentation (www.phpdoc.org),  ISO page formats,  minor improvements,  image scale factor]<br>
   * Tools to encode your unicode fonts can be found at: http://www.acko.net/blog/ufpdf
   * @name FPDF
   * @package com.tecnick.tcpdf
   * @version 1.53.0.TC010
   * @author Olivier PLATHEY,  Nicola Asuni
   * @link http://tcpdf.sourceforge.net
   * @license http://www.gnu.org/copyleft/lesser.html LGPL
   */
   class FPDF {
    //Private properties
    /**
    * @var current page number
    * @access protected
    */
    protected $page;
    /**
    * @var current object number
    * @access protected
    */
    protected $n;
    /**
    * @var array of object offsets
    * @access protected
    */
    protected $offsets;
    /**
    * @var buffer holding in-memory PDF
    * @access protected
    */
    protected $buffer;
    /**
    * @var array containing pages
    * @access protected
    */
    protected $pages;
    /**
    * @var current document state
    * @access protected
    */
    protected $state;
    /**
    * @var compression flag
    * @access protected
    */
    protected $compress;
    /**
    * @var default orientation
    * @access protected
    */
    protected $DefOrientation;
    /**
    * @var current orientation
    * @access protected
    */
    protected $CurOrientation;
    /**
    * @var array indicating orientation changes
    * @access protected
    */
    protected $OrientationChanges;
    /**
    * @var scale factor (number of points in user unit)
    * @access protected
    */
    protected $k;
    /**
    * @var width of page format in points
    * @access protected
    */
    protected $fwPt;
    /**
    * @var height of page format in points
    * @access protected
    */
    protected $fhPt;
    /**
    * @var width of page format in user unit
    * @access protected
    */
    protected $fw;
    /**
    * @var height of page format in user unit
    * @access protected
    */
    protected $fh;
    /**
    * @var current width of page in points
    * @access protected
    */
    protected $wPt;
    /**
    * @var current height of page in points
    * @access protected
    */
    protected $hPt;
    /**
    * @var current width of page in user unit
    * @access protected
    */
    protected $w;
    /**
    * @var current height of page in user unit
    * @access protected
    */
    protected $h;
    /**
    * @var left margin
    * @access protected
    */
    protected $lMargin;
    /**
    * @var top margin
    * @access protected
    */
    protected $tMargin;
    /**
    * @var right margin
    * @access protected
    */
    protected $rMargin;
    /**
    * @var page break margin
    * @access protected
    */
    protected $bMargin;
    /**
    * @var cell margin
    * @access protected
    */
    protected $cMargin;
    /**
    * @var current horizontal position in user unit for cell positioning
    * @access protected
    */
    protected $x;
    /**
    * @var current vertical position in user unit for cell positioning
    * @access protected
    */
    protected $y;
    /**
    * @var height of last cell printed
    * @access protected
    */
    protected $lasth;
    /**
    * @var line width in user unit
    * @access protected
    */
    protected $LineWidth;
    /**
    * @var array of standard font names
    * @access protected
    */
    protected $CoreFonts;
    /**
    * @var array of used fonts
    * @access protected
    */
    protected $fonts;
    /**
    * @var array of font files
    * @access protected
    */
    protected $FontFiles;
    /**
    * @var array of encoding differences
    * @access protected
    */
    protected $diffs;
    /**
    * @var array of used images
    * @access protected
    */
    protected $images;
    /**
    * @var array of links in pages
    * @access protected
    */
    protected $PageLinks;
    /**
    * @var array of internal links
    * @access protected
    */
    protected $links;
    /**
    * @var current font family
    * @access protected
    */
    protected $FontFamily;
    /**
    * @var current font style
    * @access protected
    */
    protected $FontStyle;
    /**
    * @var underlining flag
    * @access protected
    */
    protected $underline;
    /**
    * @var current font info
    * @access protected
    */
    protected $CurrentFont;
    /**
    * @var current font size in points
    * @access protected
    */
    protected $FontSizePt;
    /**
    * @var current font size in user unit
    * @access protected
    */
    protected $FontSize;
    /**
    * @var commands for drawing color
    * @access protected
    */
    protected $DrawColor;
    /**
    * @var commands for filling color
    * @access protected
    */
    protected $FillColor;
    /**
    * @var commands for text color
    * @access protected
    */
    protected $TextColor;
    /**
    * @var indicates whether fill and text colors are different
    * @access protected
    */
    protected $ColorFlag;
    /**
    * @var word spacing
    * @access protected
    */
    protected $ws;
    /**
    * @var automatic page breaking
    * @access protected
    */
    protected $AutoPageBreak;
    /**
    * @var threshold used to trigger page breaks
    * @access protected
    */
    protected $PageBreakTrigger;
    /**
    * @var flag set when processing footer
    * @access protected
    */
    protected $InFooter;
    /**
    * @var zoom display mode
    * @access protected
    */
    protected $ZoomMode;
    /**
    * @var layout display mode
    * @access protected
    */
    protected $LayoutMode;
    /**
    * @var title
    * @access protected
    */
    protected $title;
    /**
    * @var subject
    * @access protected
    */
    protected $subject;
    /**
    * @var author
    * @access protected
    */
    protected $author;
    /**
    * @var keywords
    * @access protected
    */
    protected $keywords;
    /**
    * @var creator
    * @access protected
    */
    protected $creator;
    /**
    * @var alias for total number of pages
    * @access protected
    */
    protected $AliasNbPages;
    /**
    * @var right-bottom corner X coordinate of inserted image
    * @since 2002-07-31
    * @author Nicola Asuni
    * @access protected
    */
    protected $img_rb_x;
    /**
    * @var right-bottom corner Y coordinate of inserted image
    * @since 2002-07-31
    * @author Nicola Asuni
    * @access protected
    */
    protected $img_rb_y;
    /**
    * @var image scale factor
    * @since 2004-06-14
    * @author Nicola Asuni
    * @access protected
    */
    protected $imgscale = 1;
    /**
    * @var boolean set to true when the input text is unicode (require unicode fonts)
    * @since 2005-01-02
    * @author Nicola Asuni
    * @access protected
    */
    protected $isunicode = false;
    /**
    * @var PDF version
    * @since 1.5.3
    * @access protected
    */
    protected $PDFVersion = "1.3";
    //------------------------------------------------------------
    // Public methods
    //------------------------------------------------------------
    /**
    * This is the class constructor.
    * It allows to set up the page format,  the orientation and
    * the measure unit used in all the methods (except for the font sizes).<br>
    * Support UTF-8 Unicode [Nicola Asuni,  2005-01-02].
    * @since 1.0
    * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
    * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch,  that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
    * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
    * @param boolean $unicode TRUE means that the input text is unicode
    */
    protected function __construct($orientation='P',  $unit='mm',  $format='A4',  $unicode=false) {
	    //Some checks
	    $this->_dochecks();
	    //Initialization of properties
	    $this->isunicode=$unicode;
	    $this->page=0;
	    $this->n=2;
	    $this->buffer='';
	    $this->pages=array();
	    $this->OrientationChanges=array();
	    $this->state=0;
	    $this->fonts=array();
	    $this->FontFiles=array();
	    $this->diffs=array();
	    $this->images=array();
	    $this->links=array();
	    $this->InFooter=false;
	    $this->lasth=0;
	    $this->FontFamily='';
	    $this->FontStyle='';
	    $this->FontSizePt=12;
	    $this->underline=false;
	    $this->DrawColor='0 G';
	    $this->FillColor='0 g';
	    $this->TextColor='0 g';
	    $this->ColorFlag=false;
	    $this->ws=0;
	    //Standard Unicode fonts
	    $this->CoreFonts=array(
	    'courier'=>'Courier',
	    'courierB'=>'Courier-Bold',
	    'courierI'=>'Courier-Oblique',
	    'courierBI'=>'Courier-BoldOblique',
	    'helvetica'=>'Helvetica',
	    'helveticaB'=>'Helvetica-Bold',
	    'helveticaI'=>'Helvetica-Oblique',
	    'helveticaBI'=>'Helvetica-BoldOblique',
	    'times'=>'Times-Roman',
	    'timesB'=>'Times-Bold',
	    'timesI'=>'Times-Italic',
	    'timesBI'=>'Times-BoldItalic',
	    'symbol'=>'Symbol',
	    'zapfdingbats'=>'ZapfDingbats'
	    );
	    //Scale factor
	    // 2003-06-11 - Nicola Asuni : changed if/else with switch statement
	    switch (strtolower($unit)){
		    case 'pt': {$this->k=1; break;}
		    case 'mm': {$this->k=72/25.4; break;}
		    case 'cm': {$this->k=72/2.54;; break;}
		    case 'in': {$this->k=72;; break;}
		    default : {$this->Error('Incorrect unit: '.$unit); break;}
	    }
	    //Page format
	    if(is_string($format)) {
		    // 2002-07-24 - Nicola Asuni (info <at> tecnick <dot> com)
		    // Added new page formats (45 standard ISO paper formats and 4 american common formats).
		    // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
		    switch (strtoupper($format)){
			    case '4A0': {$format = array(4767.87, 6740.79); break;}
			    case '2A0': {$format = array(3370.39, 4767.87); break;}
			    case 'A0': {$format = array(2383.94, 3370.39); break;}
			    case 'A1': {$format = array(1683.78, 2383.94); break;}
			    case 'A2': {$format = array(1190.55, 1683.78); break;}
			    case 'A3': {$format = array(841.89, 1190.55); break;}
			    case 'A4': default: {$format = array(595.28, 841.89); break;}
			    case 'A5': {$format = array(419.53, 595.28); break;}
			    case 'A6': {$format = array(297.64, 419.53); break;}
			    case 'A7': {$format = array(209.76, 297.64); break;}
			    case 'A8': {$format = array(147.40, 209.76); break;}
			    case 'A9': {$format = array(104.88, 147.40); break;}
			    case 'A10': {$format = array(73.70, 104.88); break;}
			    case 'B0': {$format = array(2834.65, 4008.19); break;}
			    case 'B1': {$format = array(2004.09, 2834.65); break;}
			    case 'B2': {$format = array(1417.32, 2004.09); break;}
			    case 'B3': {$format = array(1000.63, 1417.32); break;}
			    case 'B4': {$format = array(708.66, 1000.63); break;}
			    case 'B5': {$format = array(498.90, 708.66); break;}
			    case 'B6': {$format = array(354.33, 498.90); break;}
			    case 'B7': {$format = array(249.45, 354.33); break;}
			    case 'B8': {$format = array(175.75, 249.45); break;}
			    case 'B9': {$format = array(124.72, 175.75); break;}
			    case 'B10': {$format = array(87.87, 124.72); break;}
			    case 'C0': {$format = array(2599.37, 3676.54); break;}
			    case 'C1': {$format = array(1836.85, 2599.37); break;}
			    case 'C2': {$format = array(1298.27, 1836.85); break;}
			    case 'C3': {$format = array(918.43, 1298.27); break;}
			    case 'C4': {$format = array(649.13, 918.43); break;}
			    case 'C5': {$format = array(459.21, 649.13); break;}
			    case 'C6': {$format = array(323.15, 459.21); break;}
			    case 'C7': {$format = array(229.61, 323.15); break;}
			    case 'C8': {$format = array(161.57, 229.61); break;}
			    case 'C9': {$format = array(113.39, 161.57); break;}
			    case 'C10': {$format = array(79.37, 113.39); break;}
			    case 'RA0': {$format = array(2437.80, 3458.27); break;}
			    case 'RA1': {$format = array(1729.13, 2437.80); break;}
			    case 'RA2': {$format = array(1218.90, 1729.13); break;}
			    case 'RA3': {$format = array(864.57, 1218.90); break;}
			    case 'RA4': {$format = array(609.45, 864.57); break;}
			    case 'SRA0': {$format = array(2551.18, 3628.35); break;}
			    case 'SRA1': {$format = array(1814.17, 2551.18); break;}
			    case 'SRA2': {$format = array(1275.59, 1814.17); break;}
			    case 'SRA3': {$format = array(907.09, 1275.59); break;}
			    case 'SRA4': {$format = array(637.80, 907.09); break;}
			    case 'LETTER': {$format = array(612.00, 792.00); break;}
			    case 'LEGAL': {$format = array(612.00, 1008.00); break;}
			    case 'EXECUTIVE': {$format = array(521.86, 756.00); break;}
			    case 'FOLIO': {$format = array(612.00, 936.00); break;}
			    // default: {$this->Error('Unknown page format: '.$format); break;}
			    // END CHANGES Nicola Asuni
		    }
		    $this->fwPt=$format[0];
		    $this->fhPt=$format[1];
	    }
	    else {
		    $this->fwPt=$format[0]*$this->k;
		    $this->fhPt=$format[1]*$this->k;
	    }
	    $this->fw=$this->fwPt/$this->k;
	    $this->fh=$this->fhPt/$this->k;
	    //Page orientation
	    $orientation=strtolower($orientation);
	    if($orientation=='p' or $orientation=='portrait') {
		    $this->DefOrientation='P';
		    $this->wPt=$this->fwPt;
		    $this->hPt=$this->fhPt;
	    }
	    elseif($orientation=='l' or $orientation=='landscape') {
		    $this->DefOrientation='L';
		    $this->wPt=$this->fhPt;
		    $this->hPt=$this->fwPt;
	    }
	    else {
		    $this->Error('Incorrect orientation: '.$orientation);
	    }
	    $this->CurOrientation=$this->DefOrientation;
	    $this->w=$this->wPt/$this->k;
	    $this->h=$this->hPt/$this->k;
	    //Page margins (1 cm)
	    $margin=28.35/$this->k;
	    $this->SetMargins($margin, $margin);
	    //Interior cell margin (1 mm)
	    $this->cMargin=$margin/10;
	    //Line width (0.2 mm)
	    $this->LineWidth=.567/$this->k;
	    //Automatic page break
	    $this->SetAutoPageBreak(true, 2*$margin);
	    //Full width display mode
	    $this->SetDisplayMode('fullwidth');
	    //Compression
	    $this->SetCompression(true);
	    //Set default PDF version number
	    $this->PDFVersion = "1.3";
    }
    /**
    * Set the image scale.
    * @param float $scale image scale.
    * @author Nicola Asuni
    * @since 1.5.2
    */
    public function setImageScale($scale) {
	    $this->imgscale=$scale;
    }
    /**
    * Returns the image scale.
    * @return float image scale.
    * @author Nicola Asuni
    * @since 1.5.2
    */
    public function getImageScale() {
	    return $this->imgscale;
    }
    /**
    * Returns the page width in units.
    * @return int page width.
    * @author Nicola Asuni
    * @since 1.5.2
    */
    public function getPageWidth() {
	    return $this->w;
    }
    /**
    * Returns the page height in units.
    * @return int page height.
    * @author Nicola Asuni
    * @since 1.5.2
    */
    public function getPageHeight() {
	    return $this->fh;
    }
    /**
    * Returns the page break margin.
    * @return int page break margin.
    * @author Nicola Asuni
    * @since 1.5.2
    */
    public function getBreakMargin() {
	    return $this->bMargin;
    }
    /**
    * Returns the scale factor (number of points in user unit).
    * @return int scale factor.
    * @author Nicola Asuni
    * @since 1.5.2
    */
    public function getScaleFactor() {
	    return $this->k;
    }
    /**
    * Defines the left,  top and right margins. By default,  they equal 1 cm. Call this method to change them.
    * @param float $left Left margin.
    * @param float $top Top margin.
    * @param float $right Right margin. Default value is the left one.
    * @since 1.0
    * @see SetLeftMargin(),  SetTopMargin(),  SetRightMargin(),  SetAutoPageBreak()
    */
    public function SetMargins($left,  $top,  $right=-1) {
	    //Set left,  top and right margins
	    $this->lMargin=$left;
	    $this->tMargin=$top;
	    if($right==-1) {
		    $right=$left;
	    }
	    $this->rMargin=$right;
    }
    /**
    * Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page,  it is brought back to the margin.
    * @param float $margin The margin.
    * @since 1.4
    * @see SetTopMargin(),  SetRightMargin(),  SetAutoPageBreak(),  SetMargins()
    */
    public function SetLeftMargin($margin) {
	    //Set left margin
	    $this->lMargin=$margin;
	    if(($this->page>0) and ($this->x<$margin)) {
		    $this->x=$margin;
	    }
    }
    /**
    * Defines the top margin. The method can be called before creating the first page.
    * @param float $margin The margin.
    * @since 1.5
    * @see SetLeftMargin(),  SetRightMargin(),  SetAutoPageBreak(),  SetMargins()
    */
    public function SetTopMargin($margin) {
	    //Set top margin
	    $this->tMargin=$margin;
    }
    /**
    * Defines the right margin. The method can be called before creating the first page.
    * @param float $margin The margin.
    * @since 1.5
    * @see SetLeftMargin(),  SetTopMargin(),  SetAutoPageBreak(),  SetMargins()
    */
    public function SetRightMargin($margin) {
	    //Set right margin
	    $this->rMargin=$margin;
    }
    /**
    * Enables or disables the automatic page breaking mode. When enabling,  the second parameter is the distance from the bottom of the page that defines the triggering limit. By default,  the mode is on and the margin is 2 cm.
    * @param boolean $auto Boolean indicating if mode should be on or off.
    * @param float $margin Distance from the bottom of the page.
    * @since 1.0
    * @see Cell(),  MultiCell(),  AcceptPageBreak()
    */
    public function SetAutoPageBreak($auto,  $margin=0) {
	    //Set auto page break mode and triggering margin
	    $this->AutoPageBreak=$auto;
	    $this->bMargin=$margin;
	    $this->PageBreakTrigger=$this->h-$margin;
    }
    /**
    * Defines the way the document is to be displayed by the viewer. The zoom level can be set: pages can be displayed entirely on screen,  occupy the full width of the window,  use real size,  be scaled by a specific zooming factor or use viewer default (configured in the Preferences menu of Acrobat). The page layout can be specified too: single at once,  continuous display,  two columns or viewer default. By default,  documents use the full width mode with continuous display.
    * @param mixed $zoom The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
    * @param string $layout The page layout. Possible values are:<ul><li>single: displays one page at once</li><li>continuous: displays pages continuously (default)</li><li>two: displays two pages on two columns</li><li>default: uses viewer default mode</li></ul>
    * @since 1.2
    */
    public function SetDisplayMode($zoom,  $layout='continuous') {
	    //Set display mode in viewer
	    if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) {
		    $this->ZoomMode=$zoom;
	    }
	    else {
		    $this->Error('Incorrect zoom display mode: '.$zoom);
	    }
	    if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') {
		    $this->LayoutMode=$layout;
	    }
	    else {
		    $this->Error('Incorrect layout display mode: '.$layout);
	    }
    }
    /**
    * Activates or deactivates page compression. When activated,  the internal representation of each page is compressed,  which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
    * Note: the Zlib extension is required for this feature. If not present,  compression will be turned off.
    * @param boolean $compress Boolean indicating if compression must be enabled.
    * @since 1.4
    */
    public function SetCompression($compress) {
	    //Set page compression
	    if(function_exists('gzcompress')) {
		    $this->compress=$compress;
	    }
	    else {
		    $this->compress=false;
	    }
    }
    /**
    * Defines the title of the document.
    * @param string $title The title.
    * @since 1.2
    * @see SetAuthor(),  SetCreator(),  SetKeywords(),  SetSubject()
    */
    public function SetTitle($title) {
	    //Title of document
	    $this->title=$title;
    }
    /**
    * Defines the subject of the document.
    * @param string $subject The subject.
    * @since 1.2
    * @see SetAuthor(),  SetCreator(),  SetKeywords(),  SetTitle()
    */
    public function SetSubject($subject) {
	    //Subject of document
	    $this->subject=$subject;
    }
    /**
    * Defines the author of the document.
    * @param string $author The name of the author.
    * @since 1.2
    * @see SetCreator(),  SetKeywords(),  SetSubject(),  SetTitle()
    */
    public function SetAuthor($author) {
	    //Author of document
	    $this->author=$author;
    }
    /**
    * Associates keywords with the document,  generally in the form 'keyword1 keyword2 ...'.
    * @param string $keywords The list of keywords.
    * @since 1.2
    * @see SetAuthor(),  SetCreator(),  SetSubject(),  SetTitle()
    */
    public function SetKeywords($keywords) {
	    //Keywords of document
	    $this->keywords=$keywords;
    }
    /**
    * Defines the creator of the document. This is typically the name of the application that generates the PDF.
    * @param string $creator The name of the creator.
    * @since 1.2
    * @see SetAuthor(),  SetKeywords(),  SetSubject(),  SetTitle()
    */
    public function SetCreator($creator) {
	    //Creator of document
	    $this->creator=$creator;
    }
    /**
    * Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
    * <b>Example:</b><br />
    * <pre>
    * class PDF extends FPDF {
    *	 public function Footer() {
    *		 //Go to 1.5 cm from bottom
    *		 $this->SetY(-15);
    *		 //Select Arial italic 8
    *		 $this->SetFont('Arial', 'I', 8);
    *		 //Print current and total page numbers
    *		 $this->Cell(0, 10, 'Page '.$this->PageNo().'/{nb}', 0, 0, 'C');
    *	 }
    * }
    * $pdf=new PDF();
    * $pdf->AliasNbPages();
    * </pre>
    * @param string $alias The alias. Default value: {nb}.
    * @since 1.4
    * @see PageNo(),  Footer()
    */
    public function AliasNbPages($alias='{nb}') {
	    //Define an alias for total number of pages
	    $this->AliasNbPages = $this->_escapetext($alias);
    }
    /**
    * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script,  or the resulting document would probably be invalid.
    * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
    * @param string $msg The error message
    * @since 1.0
    */
    public function Error($msg) {
	    //Fatal error
	    die('<strong>FPDF error: </strong>'.$msg);
    }
    /**
    * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
    * Note: no page is created by this method
    * @since 1.0
    * @see AddPage(),  Close()
    */
    public function Open() {
	    //Begin document
	    $this->state=1;
    }
    /**
    * Terminates the PDF document. It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page,  AddPage() is called to prevent from getting an invalid document.
    * @since 1.0
    * @see Open(),  Output()
    */
    public function Close() {
	    //Terminate document
	    if($this->state==3) {
		    return;
	    }
	    if($this->page==0) {
		    $this->AddPage();
	    }
	    //Page footer
	    $this->InFooter=true;
	    $this->Footer();
	    $this->InFooter=false;
	    //Close page
	    $this->_endpage();
	    //Close document
	    $this->_enddoc();
    }
    /**
    * Adds a new page to the document. If a page is already present,  the Footer() method is called first to output the footer. Then the page is added,  the current position set to the top-left corner according to the left and top margins,  and Header() is called to display the header.
    * The font which was set before calling is automatically restored. There is no need to call SetFont() again if you want to continue with the same font. The same is true for colors and line width.
    * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
    * @param string $orientation Page orientation. Possible values are (case insensitive):<ul><li>P or Portrait</li><li>L or Landscape</li></ul> The default value is the one passed to the constructor.
    * @since 1.0
    * @see FPDF(),  Header(),  Footer(),  SetMargins()
    */
    public function AddPage($orientation='') {
	    //Start a new page
	    if($this->state==0) {
		    $this->Open();
	    }
	    $family=$this->FontFamily;
	    $style=$this->FontStyle.($this->underline ? 'U' : '');
	    $size=$this->FontSizePt;
	    $lw=$this->LineWidth;
	    $dc=$this->DrawColor;
	    $fc=$this->FillColor;
	    $tc=$this->TextColor;
	    $cf=$this->ColorFlag;
	    if($this->page>0) {
		    //Page footer
		    $this->InFooter=true;
		    $this->Footer();
		    $this->InFooter=false;
		    //Close page
		    $this->_endpage();
	    }
	    //Start new page
	    $this->_beginpage($orientation);
	    //Set line cap style to square
	    $this->_out('2 J');
	    //Set line width
	    $this->LineWidth=$lw;
	    $this->_out(sprintf('%.2f w', $lw*$this->k));
	    //Set font
	    if($family) {
		    $this->SetFont($family, $style, $size);
	    }
	    //Set colors
	    $this->DrawColor=$dc;
	    if($dc!='0 G') {
		    $this->_out($dc);
	    }
	    $this->FillColor=$fc;
	    if($fc!='0 g') {
		    $this->_out($fc);
	    }
	    $this->TextColor=$tc;
	    $this->ColorFlag=$cf;
	    //Page header
	    $this->Header();
	    //Restore line width
	    if($this->LineWidth!=$lw) {
		    $this->LineWidth=$lw;
		    $this->_out(sprintf('%.2f w', $lw*$this->k));
	    }
	    //Restore font
	    if($family) {
		    $this->SetFont($family, $style, $size);
	    }
	    //Restore colors
	    if($this->DrawColor!=$dc) {
		    $this->DrawColor=$dc;
		    $this->_out($dc);
	    }
	    if($this->FillColor!=$fc) {
		    $this->FillColor=$fc;
		    $this->_out($fc);
	    }
	    $this->TextColor=$tc;
	    $this->ColorFlag=$cf;
    }
    /**
    * This method is used to render the page header. It is automatically called by AddPage() and should not be called directly by the application. The implementation in FPDF is empty,  so you have to subclass it and override the method if you want a specific processing.<br />
    * <b>Example:</b><br />
    * <pre>
    * class PDF extends FPDF {
    *	 public function Header() {
    *		 //Select Arial bold 15
    *		 $this->SetFont('Arial', 'B', 15);
    *		 //Move to the right
    *		 $this->Cell(80);
    *		 //Framed title
    *		 $this->Cell(30, 10, 'Title', 1, 0, 'C');
    *		 //Line break
    *		 $this->Ln(20);
    *	 }
    * }
    * </pre>
    * @since 1.0
    * @see Footer()
    */
    public function Header() {
	    //To be implemented in your own inherited class
    }
    /**
    * This method is used to render the page footer. It is automatically called by AddPage() and Close() and should not be called directly by the application. The implementation in FPDF is empty,  so you have to subclass it and override the method if you want a specific processing.
    * <b>Example:</b><br />
    * <pre>
    * class PDF extends FPDF {
    *	 public function Footer() {
    *		 //Go to 1.5 cm from bottom
    *		 $this->SetY(-15);
    *		 //Select Arial italic 8
    *		 $this->SetFont('Arial', 'I', 8);
    *		 //Print centered page number
    *		 $this->Cell(0, 10, 'Page '.$this->PageNo(), 0, 0, 'C');
    *	 }
    * }
    * </pre>
    * @since 1.0
    * @see Header()
    */
    public function Footer() {
	    //To be implemented in your own inherited class
    }
    /**
    * Returns the current page number.
    * @return int page number
    * @since 1.0
    * @see AliasNbPages()
    */
    public function PageNo() {
	    //Get current page number
	    return $this->page;
    }
    /**
    * Defines the color used for all drawing operations (lines,  rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
    * @param int $r If g et b are given,  red component; if not,  indicates the gray level. Value between 0 and 255
    * @param int $g Green component (between 0 and 255)
    * @param int $b Blue component (between 0 and 255)
    * @since 1.3
    * @see SetFillColor(),  SetTextColor(),  Line(),  Rect(),  Cell(),  MultiCell()
    */
    public function SetDrawColor($r,  $g=-1,  $b=-1) {
	    //Set color for all stroking operations
	    if(($r==0 and $g==0 and $b==0) or $g==-1) {
		    $this->DrawColor=sprintf('%.3f G', $r/255);
	    }
	    else {
		    $this->DrawColor=sprintf('%.3f %.3f %.3f RG', $r/255, $g/255, $b/255);
	    }
	    if($this->page>0) {
		    $this->_out($this->DrawColor);
	    }
    }
    /**
    * Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
    * @param int $r If g et b are given,  red component; if not,  indicates the gray level. Value between 0 and 255
    * @param int $g Green component (between 0 and 255)
    * @param int $b Blue component (between 0 and 255)
    * @since 1.3
    * @see SetDrawColor(),  SetTextColor(),  Rect(),  Cell(),  MultiCell()
    */
    public function SetFillColor($r,  $g=-1,  $b=-1) {
	    //Set color for all filling operations
	    if(($r==0 and $g==0 and $b==0) or $g==-1) {
		    $this->FillColor=sprintf('%.3f g', $r/255);
	    }
	    else {
		    $this->FillColor=sprintf('%.3f %.3f %.3f rg', $r/255, $g/255, $b/255);
	    }
	    $this->ColorFlag=($this->FillColor!=$this->TextColor);
	    if($this->page>0) {
		    $this->_out($this->FillColor);
	    }
    }
    /**
    * Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
    * @param int $r If g et b are given,  red component; if not,  indicates the gray level. Value between 0 and 255
    * @param int $g Green component (between 0 and 255)
    * @param int $b Blue component (between 0 and 255)
    * @since 1.3
    * @see SetDrawColor(),  SetFillColor(),  Text(),  Cell(),  MultiCell()
    */
    public function SetTextColor($r,  $g=-1,  $b=-1) {
	    //Set color for text
	    if(($r==0 and $g==0 and $b==0) or $g==-1) {
		    $this->TextColor=sprintf('%.3f g', $r/255);
	    }
	    else {
		    $this->TextColor=sprintf('%.3f %.3f %.3f rg', $r/255, $g/255, $b/255);
	    }
	    $this->ColorFlag=($this->FillColor!=$this->TextColor);
    }
    /**
    * Returns the length of a string in user unit. A font must be selected.<br>
    * Support UTF-8 Unicode [Nicola Asuni,  2005-01-02]
    * @param string $s The string whose length is to be computed
    * @return int
    * @since 1.2
    */
    public function GetStringWidth($s) {
	    //Get width of a string in the current font
	    $s = (string)$s;
	    $cw = &$this->CurrentFont['cw'];
	    $w = 0;
	    if($this->isunicode) {
		    $unicode = $this->UTF8StringToArray($s);
		    foreach($unicode as $char) {
			    if (isset($cw[$char])) {
				    $w+=$cw[$char];
			    } elseif(isset($cw[ord($char)])) {
				    $w+=$cw[ord($char)];
			    } elseif(isset($cw[chr($char)])) {
				    $w+=$cw[chr($char)];
			    } elseif(isset($this->CurrentFont['desc']['MissingWidth'])) {
				    $w += $this->CurrentFont['desc']['MissingWidth']; // set default size
			    } else {
				    $w += 500;
			    }
		    }
	    } else {
		    $l = strlen($s);
		    for($i=0; $i<$l; $i++) {
			    if (isset($cw[$s{$i}])) {
				    $w += $cw[$s{$i}];
			    } else if (isset($cw[ord($s{$i})])) {
				    $w += $cw[ord($s{$i})];
			    }
		    }
	    }
	    return ($w * $this->FontSize / 1000);
    }
    /**
    * Defines the line width. By default,  the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
    * @param float $width The width.
    * @since 1.0
    * @see Line(),  Rect(),  Cell(),  MultiCell()
    */
    public function SetLineWidth($width) {
	    //Set line width
	    $this->LineWidth=$width;
	    if($this->page>0) {
		    $this->_out(sprintf('%.2f w', $width*$this->k));
	    }
    }
    /**
    * Draws a line between two points.
    * @param float $x1 Abscissa of first point
    * @param float $y1 Ordinate of first point
    * @param float $x2 Abscissa of second point
    * @param float $y2 Ordinate of second point
    * @since 1.0
    * @see SetLineWidth(),  SetDrawColor()
    */
    public function Line($x1,  $y1,  $x2,  $y2) {
	    //Draw a line
	    $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));
    }
    /**
    * Outputs a rectangle. It can be drawn (border only),  filled (with no border) or both.
    * @param float $x Abscissa of upper-left corner
    * @param float $y Ordinate of upper-left corner
    * @param float $w Width
    * @param float $h Height
    * @param string $style Style of rendering. Possible values are:<ul><li>D or empty string: draw (default)</li><li>F: fill</li><li>DF or FD: draw and fill</li></ul>
    * @since 1.0
    * @see SetLineWidth(),  SetDrawColor(),  SetFillColor()
    */
    public function Rect($x,  $y,  $w,  $h,  $style='') {
	    //Draw a rectangle
	    if($style=='F') {
		    $op='f';
	    }
	    elseif($style=='FD' or $style=='DF') {
		    $op='B';
	    }
	    else {
		    $op='S';
	    }
	    $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k, $op));
    }
    /**
    * Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility. The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by FPDF_FONTPATH if the constant is defined. If it could not be found,  the error "Could not include font definition file" is generated.
    * Support UTF-8 Unicode [Nicola Asuni,  2005-01-02].
    * <b>Example</b>:<br />
    * <pre>
    * $pdf->AddFont('Comic', 'I');
    * // is equivalent to:
    * $pdf->AddFont('Comic', 'I', 'comici.php');
    * </pre>
    * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name,  it will override the corresponding font.
    * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
    * @param string $file The font definition file. By default,  the name is built from the family and style,  in lower case with no space.
    * @since 1.5
    * @see SetFont()
    */
    public function AddFont($family,  $style='',  $file='') {
	    if(empty($family)) {
		    return;
	    }
	    //Add a TrueType or Type1 font
	    $family = strtolower($family);
	    if((!$this->isunicode) AND ($family == 'arial')) {
		    $family = 'helvetica';
	    }
	    $style=strtoupper($style);
	    $style=str_replace('U', '', $style);
	    if($style == 'IB') {
		    $style = 'BI';
	    }
	    $fontkey = $family.$style;
	    // check if the font has been already added
	    if(isset($this->fonts[$fontkey])) {
		    return;
	    }
	    if($file=='') {
		    $file = str_replace(' ',  '',  $family).strtolower($style).'.php';
	    }
	    if(!file_exists($this->_getfontpath().$file)) {
		    // try to load the basic file without styles
		    $file = str_replace(' ',  '',  $family).'.php';
	    }
	    include($this->_getfontpath().$file);
	    if(!isset($name) AND !isset($fpdf_charwidths)) {
		    $this->Error('Could not include font definition file');
	    }
	    $i = count($this->fonts)+1;
	    if($this->isunicode) {
		    $this->fonts[$fontkey] = array('i'=>$i,  'type'=>$type,  'name'=>$name,  'desc'=>$desc,  'up'=>$up,  'ut'=>$ut,  'cw'=>$cw,  'enc'=>$enc,  'file'=>$file,  'ctg'=>$ctg);
		    $fpdf_charwidths[$fontkey] = $cw;
	    } else {
		    $this->fonts[$fontkey]=array('i'=>$i,  'type'=>'core',  'name'=>$this->CoreFonts[$fontkey],  'up'=>-100,  'ut'=>50,  'cw'=>$fpdf_charwidths[$fontkey]);
	    }
	    if(isset($diff) AND (!empty($diff))) {
		    //Search existing encodings
		    $d=0;
		    $nb=count($this->diffs);
		    for($i=1;$i<=$nb;$i++) {
			    if($this->diffs[$i]==$diff) {
				    $d=$i;
				    break;
			    }
		    }
		    if($d==0) {
			    $d=$nb+1;
			    $this->diffs[$d]=$diff;
		    }
		    $this->fonts[$fontkey]['diff']=$d;
	    }
	    if(!empty($file)) {
		    if((strcasecmp($type, "TrueType") == 0) OR (strcasecmp($type, "TrueTypeUnicode") == 0)) {
			    $this->FontFiles[$file]=array('length1'=>$originalsize);
		    }
		    else {
			    $this->FontFiles[$file]=array('length1'=>$size1, 'length2'=>$size2);
		    }
	    }
    }
    /**
    * Sets the font used to print character strings. It is mandatory to call this method at least once before printing text or the resulting document would not be valid.
    * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
    * The method can be called before the first page is created and the font is retained from page to page.
    If you just wish to change the current font size,  it is simpler to call SetFontSize().
    * Note: for the standard fonts,  the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the FPDF_FONTPATH constant</li></ul><br />
    * Example for the last case (note the trailing slash):<br />
    * <pre>
    * define('FPDF_FONTPATH', '/home/www/font/');
    * require('fpdf.php');
    *
    * //Times regular 12
    * $pdf->SetFont('Times');
    * //Arial bold 14
    * $pdf->SetFont('Arial', 'B', 14);
    * //Removes bold
    * $pdf->SetFont('');
    * //Times bold,  italic and underlined 14
    * $pdf->SetFont('Times', 'BIU');
    * </pre><br />
    * If the file corresponding to the requested font is not found,  the error "Could not include font metric file" is generated.
    * @param string $family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case,  the current family is retained.
    * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li></ul>or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats
    * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document,  the value taken is 12
    * @since 1.0
    * @see AddFont(),  SetFontSize(),  Cell(),  MultiCell(),  Write()
    */
    public function SetFont($family,  $style='',  $size=0) {
	    //Select a font; size given in points
	    global $fpdf_charwidths;
	    $family=strtolower($family);
	    if($family=='') {
		    $family=$this->FontFamily;
	    }
	    if((!$this->isunicode) AND ($family == 'arial')) {
		    $family = 'helvetica';
	    }
	    elseif(($family=="symbol") OR ($family=="zapfdingbats")) {
		    $style='';
	    }
	    $style=strtoupper($style);
	    if(strpos($style, 'U')!==false) {
		    $this->underline=true;
		    $style=str_replace('U', '', $style);
	    }
	    else {
		    $this->underline=false;
	    }
	    if($style=='IB') {
		    $style='BI';
	    }
	    if($size==0) {
		    $size=$this->FontSizePt;
	    }
	    // try to add font (if not already added)
	    if($this->isunicode) {
		    $this->AddFont($family,  $style);
	    }

	    //Test if font is already selected
	    if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size)) {
		    return;
	    }

	    $fontkey = $family.$style;
	    //if(!isset($this->fonts[$fontkey]) AND isset($this->fonts[$family])) {
	    //    $style='';
	    //}
	    //Test if used for the first time
	    if(!isset($this->fonts[$fontkey])) {
		    //Check if one of the standard fonts
		    if(isset($this->CoreFonts[$fontkey])) {
			    if(!isset($fpdf_charwidths[$fontkey])) {
				    //Load metric file
				    $file = $family;
				    if(($family!='symbol') AND ($family!='zapfdingbats')) {
					    $file .= strtolower($style);
				    }
				    if(!file_exists($this->_getfontpath().$file.'.php')) {
					    // try to load the basic file without styles
					    $file = $family;
					    $fontkey = $family;
				    }
				    include($this->_getfontpath().$file.'.php');
				    if (($this->isunicode AND !isset($ctg)) OR ((!$this->isunicode) AND (!isset($fpdf_charwidths[$fontkey]))) ) {
					    $this->Error("Could not include font metric file [".$fontkey."]: ".$this->_getfontpath().$file.".php");
				    }
			    }
			    $i = count($this->fonts) + 1;
			    if($this->isunicode) {
				    $this->fonts[$fontkey] = array('i'=>$i,  'type'=>$type,  'name'=>$name,  'desc'=>$desc,  'up'=>$up,  'ut'=>$ut,  'cw'=>$cw,  'enc'=>$enc,  'file'=>$file,  'ctg'=>$ctg);
				    $fpdf_charwidths[$fontkey] = $cw;
			    } else {
				    $this->fonts[$fontkey]=array('i'=>$i,  'type'=>'core',  'name'=>$this->CoreFonts[$fontkey],  'up'=>-100,  'ut'=>50,  'cw'=>$fpdf_charwidths[$fontkey]);
			    }
		    }
		    else {
			    $this->Error('Undefined font: '.$family.' '.$style);
		    }
	    }
	    //Select it
	    $this->FontFamily = $family;
	    $this->FontStyle = $style;
	    $this->FontSizePt = $size;
	    $this->FontSize = $size / $this->k;
	    $this->CurrentFont = &$this->fonts[$fontkey];
	    if($this->page>0) {
		    $this->_out(sprintf('BT /F%d %.2f Tf ET',  $this->CurrentFont['i'],  $this->FontSizePt));
	    }
    }
    /**
    * Defines the size of the current font.
    * @param float $size The size (in points)
    * @since 1.0
    * @see SetFont()
    */
    public function SetFontSize($size) {
	    //Set font size in points
	    if($this->FontSizePt==$size) {
		    return;
	    }
	    $this->FontSizePt = $size;
	    $this->FontSize = $size / $this->k;
	    if($this->page > 0) {
		    $this->_out(sprintf('BT /F%d %.2f Tf ET',  $this->CurrentFont['i'],  $this->FontSizePt));
	    }
    }
    /**
    * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />
    * The identifier can then be passed to Cell(),  Write(),  Image() or Link(). The destination is defined with SetLink().
    * @since 1.5
    * @see Cell(),  Write(),  Image(),  Link(),  SetLink()
    */
    public function AddLink() {
	    //Create a new internal link
	    $n=count($this->links)+1;
	    $this->links[$n]=array(0, 0);
	    return $n;
    }
    /**
    * Defines the page and position a link points to
    * @param int $link The link identifier returned by AddLink()
    * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
    * @param int $page Number of target page; -1 indicates the current page. This is the default value
    * @since 1.5
    * @see AddLink()
    */
    public function SetLink($link,  $y=0,  $page=-1) {
	    //Set destination of internal link
	    if($y==-1) {
		    $y=$this->y;
	    }
	    if($page==-1) {
		    $page=$this->page;
	    }
	    $this->links[$link]=array($page, $y);
    }
    /**
    * Puts a link on a rectangular area of the page. Text or image links are generally put via Cell(),  Write() or Image(),  but this method can be useful for instance to define a clickable area inside an image.
    * @param float $x Abscissa of the upper-left corner of the rectangle
    * @param float $y Ordinate of the upper-left corner of the rectangle
    * @param float $w Width of the rectangle
    * @param float $h Height of the rectangle
    * @param mixed $link URL or identifier returned by AddLink()
    * @since 1.5
    * @see AddLink(),  Cell(),  Write(),  Image()
    */
    public function Link($x,  $y,  $w,  $h,  $link) {
	    //Put a link on the page
	    $this->PageLinks[$this->page][] = array($x * $this->k,  $this->hPt - $y * $this->k,  $w * $this->k,  $h*$this->k,  $link);
    }
    /**
    * Prints a character string. The origin is on the left of the first charcter,  on the baseline. This method allows to place a string precisely on the page,  but it is usually easier to use Cell(),  MultiCell() or Write() which are the standard methods to print text.
    * @param float $x Abscissa of the origin
    * @param float $y Ordinate of the origin
    * @param string $txt String to print
    * @since 1.0
    * @see SetFont(),  SetTextColor(),  Cell(),  MultiCell(),  Write()
    */
    public function Text($x,  $y,  $txt) {
	    //Output a string
	    $s=sprintf('BT %.2f %.2f Td (%s) Tj ET',  $x * $this->k,  ($this->h-$y) * $this->k,  $this->_escapetext($txt));
	    if($this->underline AND ($txt!='')) {
		    $s .= ' '.$this->_dounderline($x, $y, $txt);
	    }
	    if($this->ColorFlag) {
		    $s='q '.$this->TextColor.' '.$s.' Q';
	    }
	    $this->_out($s);
    }
    /**
    * Whenever a page break condition is met,  the method is called,  and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
    * This method is called automatically and should not be called directly by the application.<br />
    * <b>Example:</b><br />
    * The method is overriden in an inherited class in order to obtain a 3 column layout:<br />
    * <pre>
    * class PDF extends FPDF {
    *	 var $col=0;
    *
    *	 public function SetCol($col) {
    *		 //Move position to a column
    *		 $this->col=$col;
    *		 $x=10+$col*65;
    *		 $this->SetLeftMargin($x);
    *		 $this->SetX($x);
    *	 }
    *
    *	 public function AcceptPageBreak() {
    *		 if($this->col<2) {
    *			 //Go to next column
    *			 $this->SetCol($this->col+1);
    *			 $this->SetY(10);
    *			 return false;
    *		 }
    *		 else {
    *			 //Go back to first column and issue page break
    *			 $this->SetCol(0);
    *			 return true;
    *		 }
    *	 }
    * }
    *
    * $pdf=new PDF();
    * $pdf->Open();
    * $pdf->AddPage();
    * $pdf->SetFont('Arial', '', 12);
    * for($i=1;$i<=300;$i++) {
    *	 $pdf->Cell(0, 5, "Line $i", 0, 1);
    * }
    * $pdf->Output();
    * </pre>
    * @return boolean
    * @since 1.4
    * @see SetAutoPageBreak()
    */
    public function AcceptPageBreak() {
	    //Accept automatic page break or not
	    return $this->AutoPageBreak;
    }
    /**
    * Prints a cell (rectangular area) with optional borders,  background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call,  the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
    * If automatic page breaking is enabled and the cell goes beyond the limit,  a page break is done before outputting.
    * @param float $w Cell width. If 0,  the cell extends up to the right margin.
    * @param float $h Cell height. Default value: 0.
    * @param string $txt String to print. Default value: empty string.
    * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
    * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
    Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
    * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li></ul>
    * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
    * @param mixed $link URL or identifier returned by AddLink().
    * @since 1.0
    * @see SetFont(),  SetDrawColor(),  SetFillColor(),  SetTextColor(),  SetLineWidth(),  AddLink(),  Ln(),  MultiCell(),  Write(),  SetAutoPageBreak()
    */
    public function Cell($w,  $h=0,  $txt='',  $border=0,  $ln=0,  $align='',  $fill=0,  $link='') {
	    //Output a cell
	    $k=$this->k;
	    if(($this->y + $h) > $this->PageBreakTrigger AND empty($this->InFooter) AND $this->AcceptPageBreak()) {
		    //Automatic page break
		    $x = $this->x;
		    $ws = $this->ws;
		    if($ws > 0) {
			    $this->ws = 0;
			    $this->_out('0 Tw');
		    }
		    $this->AddPage($this->CurOrientation);
		    $this->x = $x;
		    if($ws > 0) {
			    $this->ws = $ws;
			    $this->_out(sprintf('%.3f Tw', $ws * $k));
		    }
	    }
	    if($w == 0) {
		    $w = $this->w - $this->rMargin - $this->x;
	    }
	    $s = '';
	    if(($fill == 1) OR ($border == 1)) {
		    if($fill == 1) {
			    $op = ($border == 1) ? 'B' : 'f';
		    }
		    else {
			    $op = 'S';
		    }
		    $s = sprintf('%.2f %.2f %.2f %.2f re %s ',  $this->x * $k,  ($this->h - $this->y) * $k,  $w * $k,  -$h * $k,  $op);
	    }
	    if(is_string($border)) {
		    $x=$this->x;
		    $y=$this->y;
		    if(strpos($border, 'L')!==false) {
			    $s.=sprintf('%.2f %.2f m %.2f %.2f l S ', $x*$k, ($this->h-$y)*$k, $x*$k, ($this->h-($y+$h))*$k);
		    }
		    if(strpos($border, 'T')!==false) {
			    $s.=sprintf('%.2f %.2f m %.2f %.2f l S ', $x*$k, ($this->h-$y)*$k, ($x+$w)*$k, ($this->h-$y)*$k);
		    }
		    if(strpos($border, 'R')!==false) {
			    $s.=sprintf('%.2f %.2f m %.2f %.2f l S ', ($x+$w)*$k, ($this->h-$y)*$k, ($x+$w)*$k, ($this->h-($y+$h))*$k);
		    }
		    if(strpos($border, 'B')!==false) {
			    $s.=sprintf('%.2f %.2f m %.2f %.2f l S ', $x*$k, ($this->h-($y+$h))*$k, ($x+$w)*$k, ($this->h-($y+$h))*$k);
		    }
	    }
	    if($txt != '') {
		    $width = $this->GetStringWidth($txt);
		    if($align == 'R') {
			    $dx = $w - $this->cMargin - $width;
		    }
		    elseif($align=='C') {
			    $dx = ($w - $width)/2;
		    }
		    else {
			    $dx = $this->cMargin;
		    }
		    if($this->ColorFlag) {
			    $s .= 'q '.$this->TextColor.' ';
		    }
		    $txt2 = $this->_escapetext($txt);
		    $s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',  ($this->x + $dx) * $k,  ($this->h - ($this->y + 0.5 * $h + 0.3 * $this->FontSize)) * $k,  $txt2);
		    if($this->underline) {
			    $s.=' '.$this->_dounderline($this->x + $dx,  $this->y + 0.5 * $h + 0.3 * $this->FontSize,  $txt);
		    }
		    if($this->ColorFlag) {
			    $s.=' Q';
		    }
		    if($link) {
			    $this->Link($this->x + $dx,  $this->y + 0.5 * $h - 0.5 * $this->FontSize,  $width,  $this->FontSize,  $link);
		    }
	    }
	    if($s) {
		    $this->_out($s);
	    }
	    $this->lasth = $h;
	    if($ln>0) {
		    //Go to next line
		    $this->y += $h;
		    if($ln == 1) {
			    $this->x = $this->lMargin;
		    }
	    }
	    else {
		    $this->x += $w;
	    }
    }
    /**
    * This method allows printing text with line breaks. They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output,  one below the other.<br />
    * Text can be aligned,  centered or justified. The cell block can be framed and the background painted.
    * @param float $w Width of cells. If 0,  they extend up to the right margin of the page.
    * @param float $h Height of cells.
    * @param string $txt String to print
    * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
    * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
    Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
    * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value)</li></ul>
    * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
    * @since 1.3
    * @see SetFont(),  SetDrawColor(),  SetFillColor(),  SetTextColor(),  SetLineWidth(),  Cell(),  Write(),  SetAutoPageBreak()
    */
    public function MultiCell($w,  $h,  $txt,  $border=0,  $align='J',  $fill=0) {
	    //Output text with automatic or explicit line breaks
	    $cw = &$this->CurrentFont['cw'];
	    if($w == 0) {
		    $w = $this->w - $this->rMargin - $this->x;
	    }
	    $wmax = ($w - 2 * $this->cMargin);
	    $s = str_replace("\r",  '',  $txt); // remove carriage returns
	    $nb = strlen($s);
	    $b=0;
	    if($border) {
		    if($border==1) {
			    $border='LTRB';
			    $b='LRT';
			    $b2='LR';
		    }
		    else {
			    $b2='';
			    if(strpos($border, 'L')!==false) {
				    $b2.='L';
			    }
			    if(strpos($border, 'R')!==false) {
				    $b2.='R';
			    }
			    $b=(strpos($border, 'T')!==false) ? $b2.'T' : $b2;
		    }
	    }
	    $sep=-1;
	    $i=0;
	    $j=0;
	    $l=0;
	    $ns=0;
	    $nl=1;
	    while($i<$nb) {
		    //Get next character
		    $c = $s{$i};
		    if(preg_match("/[\n]/u",  $c)) {
			    //Explicit line break
			    if($this->ws > 0) {
				    $this->ws = 0;
				    $this->_out('0 Tw');
			    }
			    $this->Cell($w,  $h,  substr($s,  $j,  $i-$j),  $b,  2,  $align,  $fill);
			    $i++;
			    $sep=-1;
			    $j=$i;
			    $l=0;
			    $ns=0;
			    $nl++;
			    if($border and $nl==2) {
				    $b = $b2;
			    }
			    continue;
		    }
		    if(preg_match("/[ ]/u",  $c)) {
			    $sep = $i;
			    $ls = $l;
			    $ns++;
		    }
		    $l = $this->GetStringWidth(substr($s,  $j,  $i-$j));
		    if($l > $wmax) {
			    //Automatic line break
			    if($sep == -1) {
				    if($i == $j) {
					    $i++;
				    }
				    if($this->ws > 0) {
					    $this->ws = 0;
					    $this->_out('0 Tw');
				    }
				    $this->Cell($w,  $h,  substr($s,  $j,  $i-$j),  $b,  2,  $align,  $fill);
			    }
			    else {
				    if($align=='J') {
					    $this->ws = ($ns>1) ? ($wmax-$ls)/($ns-1) : 0;
					    $this->_out(sprintf('%.3f Tw',  $this->ws * $this->k));
				    }
				    $this->Cell($w,  $h,  substr($s,  $j,  $sep-$j),  $b,  2,  $align,  $fill);
				    $i = $sep + 1;
			    }
			    $sep=-1;
			    $j=$i;
			    $l=0;
			    $ns=0;
			    $nl++;
			    if($border AND ($nl==2)) {
				    $b=$b2;
			    }
		    }
		    else {
			    $i++;
		    }
	    }
	    //Last chunk
	    if($this->ws>0) {
		    $this->ws=0;
		    $this->_out('0 Tw');
	    }
	    if($border and is_int(strpos($border, 'B'))) {
		    $b.='B';
	    }
	    $this->Cell($w,  $h,  substr($s,  $j,  $i-$j),  $b,  2,  $align,  $fill);
	    $this->x=$this->lMargin;
    }
    /**
    * This method prints text from the current position. When the right margin is reached (or the \n character is met) a line break occurs and text continues from the left margin. Upon method exit,  the current position is left just at the end of the text. It is possible to put a link on the text.<br />
    * <b>Example:</b><br />
    * <pre>
    * //Begin with regular font
    * $pdf->SetFont('Arial', '', 14);
    * $pdf->Write(5, 'Visit ');
    * //Then put a blue underlined link
    * $pdf->SetTextColor(0, 0, 255);
    * $pdf->SetFont('', 'U');
    * $pdf->Write(5, 'www.fpdf.org', 'http://www.fpdf.org');
    * </pre>
    * @param float $h Line height
    * @param string $txt String to print
    * @param mixed $link URL or identifier returned by AddLink()
    * @since 1.5
    * @see SetFont(),  SetTextColor(),  AddLink(),  MultiCell(),  SetAutoPageBreak()
    */
    public function Write($h,  $txt,  $link='') {
	    //Output text in flowing mode
	    $cw = &$this->CurrentFont['cw'];
	    $w = $this->w - $this->rMargin - $this->x;
	    $wmax = ($w - 2 * $this->cMargin);
	    $s = str_replace("\r",  '',  $txt);
	    $nb = strlen($s);
	    // handle single space character
	    if(($nb==1) AND preg_match("/[ ]/u",  $s)) {
		    $this->x += $this->GetStringWidth($s);
		    return;
	    }
	    $sep=-1;
	    $i=0;
	    $j=0;
	    $l=0;
	    $nl=1;
	    while($i<$nb) {
		    //Get next character
		    $c=$s{$i};
		    if(preg_match("/[\n]/u",  $c)) {
			    //Explicit line break
			    $this->Cell($w,  $h,  substr($s,  $j,  $i-$j),  0,  2,  '',  0,  $link);
			    $i++;
			    $sep = -1;
			    $j = $i;
			    $l = 0;
			    if($nl == 1) {
				    $this->x = $this->lMargin;
				    $w = $this->w - $this->rMargin - $this->x;
				    $wmax = ($w - 2 * $this->cMargin);
			    }
			    $nl++;
			    continue;
		    }
		    if(preg_match("/[ ]/u",  $c)) {
			    $sep= $i;
		    }
		    $l = $this->GetStringWidth(substr($s,  $j,  $i-$j));
		    if($l > $wmax) {
			    //Automatic line break
			    if($sep == -1) {
				    if($this->x > $this->lMargin) {
					    //Move to next line
					    $this->x = $this->lMargin;
					    $this->y += $h;
					    $w=$this->w - $this->rMargin - $this->x;
					    $wmax=($w - 2 * $this->cMargin);
					    $i++;
					    $nl++;
					    continue;
				    }
				    if($i==$j) {
					    $i++;
				    }
				    $this->Cell($w,  $h,  substr($s,  $j,  $i-$j),  0,  2,  '',  0,  $link);
			    }
			    else {
				    $this->Cell($w,  $h,  substr($s,  $j,  $sep-$j),  0,  2,  '',  0,  $link);
				    $i=$sep+1;
			    }
			    $sep = -1;
			    $j = $i;
			    $l = 0;
			    if($nl==1) {
				    $this->x = $this->lMargin;
				    $w = $this->w - $this->rMargin - $this->x;
				    $wmax = ($w - 2 * $this->cMargin);
			    }
			    $nl++;
		    }
		    else {
			    $i++;
		    }
	    }
	    //Last chunk
	    if($i!=$j) {
		    $this->Cell($l / 1000 * $this->FontSize,  $h,  substr($s,  $j),  0,  0,  '',  0,  $link);
	    }
	    $this->x += $this->GetStringWidth(substr($s,  $j,  $i-$j));
    }
    /**
    * Puts an image in the page. The upper-left corner must be given. The dimensions can be specified in different ways:<ul><li>explicit width and height (expressed in user unit)</li><li>one explicit dimension,  the other being calculated automatically in order to keep the original proportions</li><li>no explicit dimension,  in which case the image is put at 72 dpi</li></ul>
    * Supported formats are JPEG and PNG.
    * For JPEG,  all flavors are allowed:<ul><li>gray scales</li><li>true colors (24 bits)</li><li>CMYK (32 bits)</li></ul>
    * For PNG,  are allowed:<ul><li>gray scales on at most 8 bits (256 levels)</li><li>indexed colors</li><li>true colors (24 bits)</li></ul>
    * but are not supported:<ul><li>Interlacing</li><li>Alpha channel</li></ul>
    * If a transparent color is defined,  it will be taken into account (but will be only interpreted by Acrobat 4 and above).<br />
    * The format can be specified explicitly or inferred from the file extension.<br />
    * It is possible to put a link on the image.<br />
    * Remark: if an image is used several times,  only one copy will be embedded in the file.<br />
    * @param string $file Name of the file containing the image.
    * @param float $x Abscissa of the upper-left corner.
    * @param float $y Ordinate of the upper-left corner.
    * @param float $w Width of the image in the page. If not specified or equal to zero,  it is automatically calculated.
    * @param float $h Height of the image in the page. If not specified or equal to zero,  it is automatically calculated.
    * @param string $type Image format. Possible values are (case insensitive): JPG,  JPEG,  PNG. If not specified,  the type is inferred from the file extension.
    * @param mixed $link URL or identifier returned by AddLink().
    * @since 1.1
    * @see AddLink()
    */
    public function Image($file,  $x,  $y,  $w=0,  $h=0,  $type='',  $link='') {
	    //Put an image on the page
	    if(!isset($this->images[$file])) {
		    //First use of image,  get info
		    if($type == '') {
			    $pos = strrpos($file, '.');
			    if(empty($pos)) {
				    $this->Error('Image file has no extension and no type was specified: '.$file);
			    }
			    $type = substr($file,  $pos+1);
		    }
		    $type = strtolower($type);
		    $mqr = get_magic_quotes_runtime();
		    set_magic_quotes_runtime(0);
		    if($type == 'jpg' or $type == 'jpeg') {
			    $info=$this->_parsejpg($file);
		    }
		    elseif($type == 'png') {
			    $info=$this->_parsepng($file);
		    }
		    else {
			    //Allow for additional formats
			    $mtd='_parse'.$type;
			    if(!method_exists($this, $mtd)) {
				    $this->Error('Unsupported image type: '.$type);
			    }
			    $info=$this->$mtd($file);
		    }
		    set_magic_quotes_runtime($mqr);
		    $info['i']=count($this->images)+1;
		    $this->images[$file]=$info;
	    }
	    else {
		    $info=$this->images[$file];
	    }
	    //Automatic width and height calculation if needed
	    if(($w == 0) and ($h == 0)) {
		    //Put image at 72 dpi
		    // 2004-06-14 :: Nicola Asuni,  scale factor where added
		    $w = $info['w'] / ($this->imgscale * $this->k);
		    $h = $info['h'] / ($this->imgscale * $this->k);
	    }
	    if($w == 0) {
		    $w = $h * $info['w'] / $info['h'];
	    }
	    if($h == 0) {
		    $h = $w * $info['h'] / $info['w'];
	    }
	    $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']));
	    if($link) {
		    $this->Link($x,  $y,  $w,  $h,  $link);
	    }
	    //2002-07-31 - Nicola Asuni
	    // set right-bottom corner coordinates
	    $this->img_rb_x = $x + $w;
	    $this->img_rb_y = $y + $h;
    }
    /**
    * Performs a line break. The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
    * @param float $h The height of the break. By default,  the value equals the height of the last printed cell.
    * @since 1.0
    * @see Cell()
    */
    public function Ln($h='') {
	    //Line feed; default value is last cell height
	    $this->x=$this->lMargin;
	    if(is_string($h)) {
		    $this->y+=$this->lasth;
	    }
	    else {
		    $this->y+=$h;
	    }
    }
    /**
    * Returns the abscissa of the current position.
    * @return float
    * @since 1.2
    * @see SetX(),  GetY(),  SetY()
    */
    public function GetX() {
	    //Get x position
	    return $this->x;
    }
    /**
    * Defines the abscissa of the current position. If the passed value is negative,  it is relative to the right of the page.
    * @param float $x The value of the abscissa.
    * @since 1.2
    * @see GetX(),  GetY(),  SetY(),  SetXY()
    */
    public function SetX($x) {
	    //Set x position
	    if($x>=0) {
		    $this->x=$x;
	    }
	    else {
		    $this->x=$this->w+$x;
	    }
    }
    /**
    * Returns the ordinate of the current position.
    * @return float
    * @since 1.0
    * @see SetY(),  GetX(),  SetX()
    */
    public function GetY() {
	    //Get y position
	    return $this->y;
    }
    /**
    * Moves the current abscissa back to the left margin and sets the ordinate. If the passed value is negative,  it is relative to the bottom of the page.
    * @param float $y The value of the ordinate.
    * @since 1.0
    * @see GetX(),  GetY(),  SetY(),  SetXY()
    */
    public function SetY($y) {
	    //Set y position and reset x
	    $this->x=$this->lMargin;
	    if($y>=0) {
		    $this->y=$y;
	    }
	    else {
		    $this->y=$this->h+$y;
	    }
    }
    /**
    * Defines the abscissa and ordinate of the current position. If the passed values are negative,  they are relative respectively to the right and bottom of the page.
    * @param float $x The value of the abscissa
    * @param float $y The value of the ordinate
    * @since 1.2
    * @see SetX(),  SetY()
    */
    public function SetXY($x,  $y) {
	    //Set x and y positions
	    $this->SetY($y);
	    $this->SetX($x);
    }
    /**
    * Send the document to a given destination: string,  local file or browser. In the last case,  the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
    * The method first calls Close() if necessary to terminate the document.
    * @param string $name The name of the file. If not given,  the document will be sent to the browser (destination I) with the name doc.pdf.
    * @param string $dest Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser. The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local file with the name given by name.</li><li>S: return the document as a string. name is ignored.</li></ul>If the parameter is not specified but a name is given,  destination is F. If no parameter is specified at all,  destination is I.<br />Note: for compatibility with previous versions,  a boolean value is also accepted (false for F and true for D).
    * @since 1.0
    * @see Close()
    */
    public function Output($name='', $dest='') {
	    //Output PDF to some destination
	    //Finish document if necessary
	    if($this->state < 3) {
		    $this->Close();
	    }
	    //Normalize parameters
	    if(is_bool($dest)) {
		    $dest=$dest ? 'D' : 'F';
	    }
	    $dest=strtoupper($dest);
	    if($dest=='') {
		    if($name=='') {
			    $name='doc.pdf';
			    $dest='I';
		    } else {
			    $dest='F';
		    }
	    }
	    switch($dest) {
		    case 'I': {
			    //Send to standard output
			    if(ob_get_contents()) {
				    $this->Error('Some data has already been output,  can\'t send PDF file');
			    }
			    if(php_sapi_name()!='cli') {
				    //We send to a browser
				    header('Content-Type: application/pdf');
				    if(headers_sent()) {
					    $this->Error('Some data has already been output to browser,  can\'t send PDF file');
				    }
				    header('Content-Length: '.strlen($this->buffer));
				    header('Content-disposition: inline; filename="'.$name.'"');
			    }
			    echo $this->buffer;
			    break;
		    }
		    case 'D': {
			    //Download file
			    if(ob_get_contents()) {
				    $this->Error('Some data has already been output,  can\'t send PDF file');
			    }
			    if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
				    header('Content-Type: application/force-download');
			    } else {
				    header('Content-Type: application/octet-stream');
			    }
			    if(headers_sent()) {
				    $this->Error('Some data has already been output to browser,  can\'t send PDF file');
			    }
			    header('Content-Length: '.strlen($this->buffer));
			    header('Content-disposition: attachment; filename="'.$name.'"');
			    echo $this->buffer;
			    break;
		    }
		    case 'F': {
			    //Save to local file
			    $f=fopen($name, 'wb');
			    if(!$f) {
				    $this->Error('Unable to create output file: '.$name);
			    }
			    fwrite($f, $this->buffer, strlen($this->buffer));
			    fclose($f);
			    break;
		    }
		    case 'S': {
			    //Return as a string
			    return $this->buffer;
		    }
		    default: {
			    $this->Error('Incorrect output destination: '.$dest);
		    }
	    }
	    return '';
    }
    // Protected methods
    /**
    * Check for locale-related bug
    * @access protected
    */
    protected function _dochecks() {
	    //Check for locale-related bug
	    if(1.1==1) {
		    $this->Error('Don\'t alter the locale before including class file');
	    }
	    //Check for decimal separator
	    if(sprintf('%.1f', 1.0)!='1.0') {
		    setlocale(LC_NUMERIC, 'C');
	    }
    }
    /**
    * Return fonts path
    * @access protected
    */
    protected function _getfontpath() {
	    if(!defined('FPDF_FONTPATH') AND is_dir(dirname(__FILE__).'/font')) {
		    define('FPDF_FONTPATH',  dirname(__FILE__).'/font/');
	    }
	    return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : '';
    }
    /**
    * Start document
    * @access protected
    */
    protected function _begindoc() {
	    //Start document
	    $this->state=1;
	    $this->_out('%PDF-1.3');
    }
    /**
    * _putpages
    * @access protected
    */
    protected function _putpages() {
	    $nb = $this->page;
	    if(!empty($this->AliasNbPages)) {
		    $nbstr = $this->UTF8ToUTF16BE($nb,  false);
		    //Replace number of pages
		    for($n=1;$n<=$nb;$n++) {
			    $this->pages[$n]=str_replace($this->AliasNbPages,  $nbstr,  $this->pages[$n]);
		    }
	    }
	    if($this->DefOrientation=='P') {
		    $wPt=$this->fwPt;
		    $hPt=$this->fhPt;
	    }
	    else {
		    $wPt=$this->fhPt;
		    $hPt=$this->fwPt;
	    }
	    $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
	    for($n=1;$n<=$nb;$n++) {
		    //Page
		    $this->_newobj();
		    $this->_out('<</Type /Page');
		    $this->_out('/Parent 1 0 R');
		    if(isset($this->OrientationChanges[$n])) {
			    $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]', $hPt, $wPt));
		    }
		    $this->_out('/Resources 2 0 R');
		    if(isset($this->PageLinks[$n])) {
			    //Links
			    $annots='/Annots [';
			    foreach($this->PageLinks[$n] as $pl) {
				    $rect=sprintf('%.2f %.2f %.2f %.2f', $pl[0], $pl[1], $pl[0]+$pl[2], $pl[1]-$pl[3]);
				    $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
				    if(is_string($pl[4])) {
					    $annots.='/A <</S /URI /URI ('.$this->_escape($pl[4]).')>>>>';
				    }
				    else {
					    $l=$this->links[$pl[4]];
					    $h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt;
					    $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>', 1+2*$l[0], $h-$l[1]*$this->k);
				    }
			    }
			    $this->_out($annots.']');
		    }
		    $this->_out('/Contents '.($this->n+1).' 0 R>>');
		    $this->_out('endobj');
		    //Page content
		    $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n];
		    $this->_newobj();
		    $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
		    $this->_putstream($p);
		    $this->_out('endobj');
	    }
	    //Pages root
	    $this->offsets[1]=strlen($this->buffer);
	    $this->_out('1 0 obj');
	    $this->_out('<</Type /Pages');
	    $kids='/Kids [';
	    for($i=0;$i<$nb;$i++) {
		    $kids.=(3+2*$i).' 0 R ';
	    }
	    $this->_out($kids.']');
	    $this->_out('/Count '.$nb);
	    $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]', $wPt, $hPt));
	    $this->_out('>>');
	    $this->_out('endobj');
    }
    /**
    * Adds fonts
    * _putfonts
    * @access protected
    */
    protected function _putfonts() {
	    $nf=$this->n;
	    foreach($this->diffs as $diff) {
		    //Encodings
		    $this->_newobj();
		    $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
		    $this->_out('endobj');
	    }
	    $mqr=get_magic_quotes_runtime();
	    set_magic_quotes_runtime(0);
	    foreach($this->FontFiles as $file=>$info) {
		    //Font file embedding
		    $this->_newobj();
		    $this->FontFiles[$file]['n']=$this->n;
		    $font='';
		    $f=fopen($this->_getfontpath().$file, 'rb', 1);
		    if(!$f) {
			    $this->Error('Font file not found');
		    }
		    while(!feof($f)) {
			    $font .= fread($f,  8192);
		    }
		    fclose($f);
		    $compressed=(substr($file, -2)=='.z');
		    if(!$compressed && isset($info['length2'])) {
			    $header=(ord($font{0})==128);
			    if($header) {
				    //Strip first binary header
				    $font=substr($font, 6);
			    }
			    if($header && ord($font{$info['length1']})==128) {
				    //Strip second binary header
				    $font=substr($font, 0, $info['length1']).substr($font, $info['length1']+6);
			    }
		    }
		    $this->_out('<</Length '.strlen($font));
		    if($compressed) {
			    $this->_out('/Filter /FlateDecode');
		    }
		    $this->_out('/Length1 '.$info['length1']);
		    if(isset($info['length2'])) {
			    $this->_out('/Length2 '.$info['length2'].' /Length3 0');
		    }
		    $this->_out('>>');
		    $this->_putstream($font);
		    $this->_out('endobj');
	    }
	    set_magic_quotes_runtime($mqr);
	    foreach($this->fonts as $k=>$font) {
		    //Font objects
		    $this->fonts[$k]['n']=$this->n+1;
		    $type=$font['type'];
		    $name=$font['name'];
		    if($type=='core') {
			    //Standard font
			    $this->_newobj();
			    $this->_out('<</Type /Font');
			    $this->_out('/BaseFont /'.$name);
			    $this->_out('/Subtype /Type1');
			    if($name!='Symbol' && $name!='ZapfDingbats') {
				    $this->_out('/Encoding /WinAnsiEncoding');
			    }
			    $this->_out('>>');
			    $this->_out('endobj');
		    } elseif($type=='Type1' || $type=='TrueType') {
			    //Additional Type1 or TrueType font
			    $this->_newobj();
			    $this->_out('<</Type /Font');
			    $this->_out('/BaseFont /'.$name);
			    $this->_out('/Subtype /'.$type);
			    $this->_out('/FirstChar 32 /LastChar 255');
			    $this->_out('/Widths '.($this->n+1).' 0 R');
			    $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
			    if($font['enc']) {
				    if(isset($font['diff'])) {
					    $this->_out('/Encoding '.($nf+$font['diff']).' 0 R');
				    } else {
					    $this->_out('/Encoding /WinAnsiEncoding');
				    }
			    }
			    $this->_out('>>');
			    $this->_out('endobj');
			    //Widths
			    $this->_newobj();
			    $cw=&$font['cw'];
			    $s='[';
			    for($i=32;$i<=255;$i++) {
				    $s.=$cw[chr($i)].' ';
			    }
			    $this->_out($s.']');
			    $this->_out('endobj');
			    //Descriptor
			    $this->_newobj();
			    $s='<</Type /FontDescriptor /FontName /'.$name;
			    foreach($font['desc'] as $k=>$v) {
				    $s.=' /'.$k.' '.$v;
			    }
			    $file = $font['file'];
			    if($file) {
				    $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
			    }
			    $this->_out($s.'>>');
			    $this->_out('endobj');
		    } else {
			    //Allow for additional types
			    $mtd='_put'.strtolower($type);
			    if(!method_exists($this,  $mtd)) {
				    $this->Error('Unsupported font type: '.$type);
			    }
			    $this->$mtd($font);
		    }
	    }
    }
    /**
    * _putimages
    * @access protected
    */
    protected function _putimages() {
	    $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
	    reset($this->images);
	    while(list($file, $info)=each($this->images)) {
		    $this->_newobj();
		    $this->images[$file]['n']=$this->n;
		    $this->_out('<</Type /XObject');
		    $this->_out('/Subtype /Image');
		    $this->_out('/Width '.$info['w']);
		    $this->_out('/Height '.$info['h']);
		    if($info['cs']=='Indexed') {
			    $this->_out('/ColorSpace [/indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
		    }
		    else {
			    $this->_out('/ColorSpace /'.$info['cs']);
			    if($info['cs']=='DeviceCMYK') {
				    $this->_out('/Decode [1 0 1 0 1 0 1 0]');
			    }
		    }
		    $this->_out('/BitsPerComponent '.$info['bpc']);
		    if(isset($info['f'])) {
			    $this->_out('/Filter /'.$info['f']);
		    }
		    if(isset($info['parms'])) {
			    $this->_out($info['parms']);
		    }
		    if(isset($info['trns']) and is_array($info['trns'])) {
			    $trns='';
			    for($i=0;$i<count($info['trns']);$i++) {
				    $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
			    }
			    $this->_out('/Mask ['.$trns.']');
		    }
		    $this->_out('/Length '.strlen($info['data']).'>>');
		    $this->_putstream($info['data']);
		    unset($this->images[$file]['data']);
		    $this->_out('endobj');
		    //Palette
		    if($info['cs']=='Indexed') {
			    $this->_newobj();
			    $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
			    $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
			    $this->_putstream($pal);
			    $this->_out('endobj');
		    }
	    }
    }
    /**
    * _putxobjectdict
    * @access protected
    */
    function _putxobjectdict() {
	    foreach($this->images as $image) {
		    $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
	    }
    }
    /**
    * _putresourcedict
    * @access protected
    */
    function _putresourcedict(){
	    $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
	    $this->_out('/Font <<');
	    foreach($this->fonts as $font) {
		    $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
	    }
	    $this->_out('>>');
	    $this->_out('/XObject <<');
	    $this->_putxobjectdict();
	    $this->_out('>>');
    }
    /**
    * _putresources
    * @access protected
    */
    function _putresources() {
	    $this->_putfonts();
	    $this->_putimages();
	    //Resource dictionary
	    $this->offsets[2]=strlen($this->buffer);
	    $this->_out('2 0 obj');
	    $this->_out('<<');
	    $this->_putresourcedict();
	    $this->_out('>>');
	    $this->_out('endobj');
    }

    /**
    * _putinfo
    * @access protected
    */
    protected function _putinfo() {
	    $this->_out('/Producer '.$this->_textstring(PDF_PRODUCER));
	    if(!empty($this->title)) {
		    $this->_out('/Title '.$this->_textstring($this->title));
	    }
	    if(!empty($this->subject)) {
		    $this->_out('/Subject '.$this->_textstring($this->subject));
	    }
	    if(!empty($this->author)) {
		    $this->_out('/Author '.$this->_textstring($this->author));
	    }
	    if(!empty($this->keywords)) {
		    $this->_out('/Keywords '.$this->_textstring($this->keywords));
	    }
	    if(!empty($this->creator)) {
		    $this->_out('/Creator '.$this->_textstring($this->creator));
	    }
	    $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis')));
    }
    /**
    * _putcatalog
    * @access protected
    */
    protected function _putcatalog() {
	    $this->_out('/Type /Catalog');
	    $this->_out('/Pages 1 0 R');
	    if($this->ZoomMode=='fullpage') {
		    $this->_out('/OpenAction [3 0 R /Fit]');
	    }
	    elseif($this->ZoomMode=='fullwidth') {
		    $this->_out('/OpenAction [3 0 R /FitH null]');
	    }
	    elseif($this->ZoomMode=='real') {
		    $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
	    }
	    elseif(!is_string($this->ZoomMode)) {
		    $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
	    }
	    if($this->LayoutMode=='single') {
		    $this->_out('/PageLayout /SinglePage');
	    }
	    elseif($this->LayoutMode=='continuous') {
		    $this->_out('/PageLayout /OneColumn');
	    }
	    elseif($this->LayoutMode=='two') {
		    $this->_out('/PageLayout /TwoColumnLeft');
	    }
    }
    /**
    * _puttrailer
    * @access protected
    */
    protected function _puttrailer() {
	    $this->_out('/Size '.($this->n+1));
	    $this->_out('/Root '.$this->n.' 0 R');
	    $this->_out('/Info '.($this->n-1).' 0 R');
    }
    /**
    * _putheader
    * @access protected
    */
    function _putheader() {
	    $this->_out('%PDF-'.$this->PDFVersion);
    }
    /**
    * _enddoc
    * @access protected
    */
    protected function _enddoc() {
	    $this->_putheader();
	    $this->_putpages();
	    $this->_putresources();
	    //Info
	    $this->_newobj();
	    $this->_out('<<');
	    $this->_putinfo();
	    $this->_out('>>');
	    $this->_out('endobj');
	    //Catalog
	    $this->_newobj();
	    $this->_out('<<');
	    $this->_putcatalog();
	    $this->_out('>>');
	    $this->_out('endobj');
	    //Cross-ref
	    $o=strlen($this->buffer);
	    $this->_out('xref');
	    $this->_out('0 '.($this->n+1));
	    $this->_out('0000000000 65535 f ');
	    for($i=1;$i<=$this->n;$i++) {
		    $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
	    }
	    //Trailer
	    $this->_out('trailer');
	    $this->_out('<<');
	    $this->_puttrailer();
	    $this->_out('>>');
	    $this->_out('startxref');
	    $this->_out($o);
	    $this->_out('%%EOF');
	    $this->state=3;
    }
    /**
    * _beginpage
    * @access protected
    */
    protected function _beginpage($orientation) {
	    $this->page++;
	    $this->pages[$this->page]='';
	    $this->state=2;
	    $this->x=$this->lMargin;
	    $this->y=$this->tMargin;
	    $this->FontFamily='';
	    //Page orientation
	    if(empty($orientation)) {
		    $orientation=$this->DefOrientation;
	    }
	    else {
		    $orientation=strtoupper($orientation{0});
		    if($orientation!=$this->DefOrientation) {
			    $this->OrientationChanges[$this->page]=true;
		    }
	    }
	    if($orientation!=$this->CurOrientation) {
		    //Change orientation
		    if($orientation=='P') {
			    $this->wPt=$this->fwPt;
			    $this->hPt=$this->fhPt;
			    $this->w=$this->fw;
			    $this->h=$this->fh;
		    }
		    else {
			    $this->wPt=$this->fhPt;
			    $this->hPt=$this->fwPt;
			    $this->w=$this->fh;
			    $this->h=$this->fw;
		    }
		    $this->PageBreakTrigger=$this->h-$this->bMargin;
		    $this->CurOrientation=$orientation;
	    }
    }
    /**
    * End of page contents
    * @access protected
    */
    protected function _endpage() {
	    $this->state=1;
    }
    /**
    * Begin a new object
    * @access protected
    */
    protected function _newobj() {
	    $this->n++;
	    $this->offsets[$this->n]=strlen($this->buffer);
	    $this->_out($this->n.' 0 obj');
    }
    /**
    * Underline text
    * @access protected
    */
    protected function _dounderline($x, $y, $txt) {
	    $up = $this->CurrentFont['up'];
	    $ut = $this->CurrentFont['ut'];
	    $w = $this->GetStringWidth($txt) + $this->ws * substr_count($txt, ' ');
	    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);
    }
    /**
    * Extract info from a JPEG file
    * @access protected
    */
    protected function _parsejpg($file) {
	    $a=GetImageSize($file);
	    if(empty($a)) {
		    $this->Error('Missing or incorrect image file: '.$file);
	    }
	    if($a[2]!=2) {
		    $this->Error('Not a JPEG file: '.$file);
	    }
	    if(!isset($a['channels']) or $a['channels']==3) {
		    $colspace='DeviceRGB';
	    }
	    elseif($a['channels']==4) {
		    $colspace='DeviceCMYK';
	    }
	    else {
		    $colspace='DeviceGray';
	    }
	    $bpc=isset($a['bits']) ? $a['bits'] : 8;
	    //Read whole file
	    $f=fopen($file, 'rb');
	    $data='';
	    while(!feof($f)) {
		    $data.=fread($f, 4096);
	    }
	    fclose($f);
	    return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data);
    }
    /**
    * Extract info from a PNG file
    * @access protected
    */
    protected function _parsepng($file) {
	    $f=fopen($file, 'rb');
	    if(empty($f)) {
		    $this->Error('Can\'t open image file: '.$file);
	    }
	    //Check signature
	    if(fread($f, 8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
		    $this->Error('Not a PNG file: '.$file);
	    }
	    //Read header chunk
	    fread($f, 4);
	    if(fread($f, 4)!='IHDR') {
		    $this->Error('Incorrect PNG file: '.$file);
	    }
	    $w=$this->_freadint($f);
	    $h=$this->_freadint($f);
	    $bpc=ord(fread($f, 1));
	    if($bpc>8) {
		    $this->Error('16-bit depth not supported: '.$file);
	    }
	    $ct=ord(fread($f, 1));
	    if($ct==0) {
		    $colspace='DeviceGray';
	    }
	    elseif($ct==2) {
		    $colspace='DeviceRGB';
	    }
	    elseif($ct==3) {
		    $colspace='Indexed';
	    }
	    else {
		    $this->Error('Alpha channel not supported: '.$file);
	    }
	    if(ord(fread($f, 1))!=0) {
		    $this->Error('Unknown compression method: '.$file);
	    }
	    if(ord(fread($f, 1))!=0) {
		    $this->Error('Unknown filter method: '.$file);
	    }
	    if(ord(fread($f, 1))!=0) {
		    $this->Error('Interlacing not supported: '.$file);
	    }
	    fread($f, 4);
	    $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
	    //Scan chunks looking for palette,  transparency and image data
	    $pal='';
	    $trns='';
	    $data='';
	    do {
		    $n=$this->_freadint($f);
		    $type=fread($f, 4);
		    if($type=='PLTE') {
			    //Read palette
			    $pal=fread($f, $n);
			    fread($f, 4);
		    }
		    elseif($type=='tRNS') {
			    //Read transparency info
			    $t=fread($f, $n);
			    if($ct==0) {
				    $trns=array(ord(substr($t, 1, 1)));
			    }
			    elseif($ct==2) {
				    $trns=array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
			    }
			    else {
				    $pos=strpos($t, chr(0));
				    if($pos!==false) {
					    $trns=array($pos);
				    }
			    }
			    fread($f, 4);
		    }
		    elseif($type=='IDAT') {
			    //Read image data block
			    $data.=fread($f, $n);
			    fread($f, 4);
		    }
		    elseif($type=='IEND') {
			    break;
		    }
		    else {
			    fread($f, $n+4);
		    }
	    }
	    while($n);
	    if($colspace=='Indexed' and empty($pal)) {
		    $this->Error('Missing palette in '.$file);
	    }
	    fclose($f);
	    return array('w'=>$w,  'h'=>$h,  'cs'=>$colspace,  'bpc'=>$bpc,  'f'=>'FlateDecode',  'parms'=>$parms,  'pal'=>$pal,  'trns'=>$trns,  'data'=>$data);
    }
    /**
    * Read a 4-byte integer from file
    * @access protected
    */
    protected function _freadint($f) {
	    //Read a 4-byte integer from file
	    $a=unpack('Ni', fread($f, 4));
	    return $a['i'];
    }
    /**
    * Format a text string
    * @access protected
    */
    protected function _textstring($s) {
	    if($this->isunicode) {
		    //Convert string to UTF-16BE
		    $s = $this->UTF8ToUTF16BE($s,  true);
	    }
	    return '('. $this->_escape($s).')';
    }
    /**
    * Format a text string
    * @access protected
    */
    function _escapetext($s) {
	    if($this->isunicode) {
		    //Convert string to UTF-16BE
		    $s = $this->UTF8ToUTF16BE($s,  false);
	    }
	    return $this->_escape($s);
    }
    /**
    * Add \ before \,  ( and )
    * @access protected
    */
    protected function _escape($s) {
	    return strtr($s,  array(')' => '\\)',  '(' => '\\(',  '\\' => '\\\\'));
    }
    /**
    *
    * @access protected
    */
    protected function _putstream($s) {
	    $this->_out('stream');
	    $this->_out($s);
	    $this->_out('endstream');
    }
    /**
    * Add a line to the document
    * @access protected
    */
    protected function _out($s) {
	    if($this->state==2) {
		    $this->pages[$this->page] .= $s."\n";
	    }
	    else {
		    $this->buffer .= $s."\n";
	    }
    }
    /**
    * Adds unicode fonts.<br>
    * Based on PDF Reference 1.3 (section 5)
    * @access protected
    * @author Nicola Asuni
    * @since 1.52.0.TC005 (2005-01-05)
    */
    protected function _puttruetypeunicode($font) {
	    // Type0 Font
	    // A composite font—a font composed of other fonts,  organized hierarchically
	    $this->_newobj();
	    $this->_out('<</Type /Font');
	    $this->_out('/Subtype /Type0');
	    $this->_out('/BaseFont /'.$font['name'].'');
	    $this->_out('/Encoding /Identity-H'); //The horizontal identity mapping for 2-byte CIDs; may be used with CIDFonts using any Registry,  Ordering,  and Supplement values.
	    $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
	    $this->_out('>>');
	    $this->_out('endobj');

	    // CIDFontType2
	    // A CIDFont whose glyph descriptions are based on TrueType font technology
	    $this->_newobj();
	    $this->_out('<</Type /Font');
	    $this->_out('/Subtype /CIDFontType2');
	    $this->_out('/BaseFont /'.$font['name'].'');
	    $this->_out('/CIDSystemInfo '.($this->n + 1).' 0 R');
	    $this->_out('/FontDescriptor '.($this->n + 2).' 0 R');
	    if (isset($font['desc']['MissingWidth'])){
		    $this->_out('/DW '.$font['desc']['MissingWidth'].''); // The default width for glyphs in the CIDFont MissingWidth
	    }
	    $w = "";
	    foreach ($font['cw'] as $cid => $width) {
		    $w .= ''.$cid.' ['.$width.'] '; // define a specific width for each individual CID
	    }
	    $this->_out('/W ['.$w.']'); // A description of the widths for the glyphs in the CIDFont
	    $this->_out('/CIDToGIDMap '.($this->n + 3).' 0 R');
	    $this->_out('>>');
	    $this->_out('endobj');

	    // CIDSystemInfo dictionary
	    // A dictionary containing entries that define the character collectionof the CIDFont.
	    $this->_newobj();
	    $this->_out('<</Registry (Adobe)'); // A string identifying an issuer of character collections
	    $this->_out('/Ordering (UCS)'); // A string that uniquely names a character collection issued by a specific registry
	    $this->_out('/Supplement 0'); // The supplement number of the character collection.
	    $this->_out('>>');
	    $this->_out('endobj');

	    // Font descriptor
	    // A font descriptor describing the CIDFont’s default metrics other than its glyph widths
	    $this->_newobj();
	    $this->_out('<</Type /FontDescriptor');
	    $this->_out('/FontName /'.$font['name']);
	    foreach ($font['desc'] as $key => $value) {
		    $this->_out('/'.$key.' '.$value);
	    }
	    if ($font['file']) {
		    // A stream containing a TrueType font program
		    $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R');
	    }
	    $this->_out('>>');
	    $this->_out('endobj');
	    // Embed CIDToGIDMap
	    // A specification of the mapping from CIDs to glyph indices
	    $this->_newobj();
	    $ctgfile = $this->_getfontpath().$font['ctg'];
	    if(!file_exists($ctgfile)) {
		    $this->Error('Font file not found: '.$ctgfile);
	    }
	    $size = filesize($ctgfile);
	    $this->_out('<</Length '.$size.'');
	    if(substr($ctgfile,  -2) == '.z') { // check file extension
		    /* Decompresses data encoded using the public-domain
		    zlib/deflate compression method,  reproducing the
		    original text or binary data */
		    $this->_out('/Filter /FlateDecode');
	    }
	    $this->_out('>>');
	    $this->_putstream(file_get_contents($ctgfile));
	    $this->_out('endobj');
    }
	 /**
	 * Converts UTF-8 strings to codepoints array.<br>
	 * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
	 * Based on: http://www.faqs.org/rfcs/rfc3629.html
	 * <pre>
	 *	   Char. number range  |	    UTF-8 octet sequence
	 *	   (hexadecimal)    |			  (binary)
	 *    --------------------+-----------------------------------------------
	 *    0000 0000-0000 007F | 0xxxxxxx
	 *    0000 0080-0000 07FF | 110xxxxx 10xxxxxx
	 *    0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
	 *    0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
	 *    ---------------------------------------------------------------------
	 *
	 *   ABFN notation:
	 *   ---------------------------------------------------------------------
	 *   UTF8-octets = *( UTF8-char )
	 *   UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
	 *   UTF8-1	  = %x00-7F
	 *   UTF8-2	  = %xC2-DF UTF8-tail
	 *
	 *   UTF8-3	  = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
	 *				 %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
	 *   UTF8-4	  = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
	 *				 %xF4 %x80-8F 2( UTF8-tail )
	 *   UTF8-tail   = %x80-BF
	 *   ---------------------------------------------------------------------
	 * </pre>
	 * @param string $str string to process.
	 * @return array containing codepoints (UTF-8 characters values)
	 * @access protected
	 * @author Nicola Asuni
	 * @since 1.53.0.TC005 (2005-01-05)
	 */
    protected function UTF8StringToArray($str) {
	    if(!$this->isunicode) {
		    return $str; // string is not in unicode
	    }
	    $unicode = array(); // array containing unicode values
	    $bytes  = array(); // array containing single character byte sequences
	    $numbytes  = 1; // number of octetc needed to represent the UTF-8 character

	    $str .= ""; // force $str to be a string
	    $length = strlen($str);

	    for($i = 0; $i < $length; $i++) {
		    $char = ord($str{$i}); // get one string character at time
		    if(count($bytes) == 0) { // get starting octect
			    if ($char <= 0x7F) {
				    $unicode[] = $char; // use the character "as is" because is ASCII
			    } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
				    $bytes[] = ($char - 0xC0) << 0x06;
				    $numbytes = 2;
			    } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
				    $bytes[] = ($char - 0xE0) << 0x0C;
				    $numbytes = 3;
			    } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
				    $bytes[] = ($char - 0xF0) << 0x12;
				    $numbytes = 4;
			    } else {
				    // use replacement character for other invalid sequences
				    $unicode[] = 0xFFFD;
				    $bytes = array();
				    $numbytes = 1;
			    }
		    } elseif (($char >> 0x06) == 0x02) { // bytes 2,  3 and 4 must start with 0x02 = 10 BIN
			    $bytes[] = $char - 0x80;
			    if (count($bytes) == $numbytes) {
				    // compose UTF-8 bytes to a single unicode value
				    $char = $bytes[0];
				    for($j = 1; $j < $numbytes; $j++) {
					    $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
				    }
				    if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
					    /* The definition of UTF-8 prohibits encoding character numbers between
					    U+D800 and U+DFFF,  which are reserved for use with the UTF-16
					    encoding form (as surrogate pairs) and do not directly represent
					    characters. */
					    $unicode[] = 0xFFFD; // use replacement character
				    }
				    else {
					    $unicode[] = $char; // add char to array
				    }
				    // reset data for next char
				    $bytes = array();
				    $numbytes = 1;
			    }
		    } else {
			    // use replacement character for other invalid sequences
			    $unicode[] = 0xFFFD;
			    $bytes = array();
			    $numbytes = 1;
		    }
	    }
	    return $unicode;
    }

    /**
	 * Converts UTF-8 strings to UTF16-BE.<br>
	 * Based on: http://www.faqs.org/rfcs/rfc2781.html
	  * <pre>
	 *   Encoding UTF-16:
	 *
	  *   Encoding of a single character from an ISO 10646 character value to
	 *    UTF-16 proceeds as follows. Let U be the character number,  no greater
	 *    than 0x10FFFF.
	 *
	 *    1) If U < 0x10000,  encode U as a 16-bit unsigned integer and
	 *	   terminate.
	 *
	 *    2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
	 *	   U' must be less than or equal to 0xFFFFF. That is,  U' can be
	 *	   represented in 20 bits.
	 *
	 *    3) Initialize two 16-bit unsigned integers,  W1 and W2,  to 0xD800 and
	 *	   0xDC00,  respectively. These integers each have 10 bits free to
	 *	   encode the character value,  for a total of 20 bits.
	 *
	 *    4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
	 *	   bits of W1 and the 10 low-order bits of U' to the 10 low-order
	 *	   bits of W2. Terminate.
	 *
	 *    Graphically,  steps 2 through 4 look like:
	 *    U' = yyyyyyyyyyxxxxxxxxxx
	 *    W1 = 110110yyyyyyyyyy
	 *    W2 = 110111xxxxxxxxxx
	 * </pre>
	 * @param string $str string to process.
	 * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
	 * @return string
	 * @access protected
	 * @author Nicola Asuni
	 * @since 1.53.0.TC005 (2005-01-05)
	 * @uses UTF8StringToArray
	 */
    protected function UTF8ToUTF16BE($str,  $setbom=true) {
	    if(!$this->isunicode) {
		    return $str; // string is not in unicode
	    }
	    $outstr = ""; // string to be returned
	    $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
	    $numitems = count($unicode);

	    if ($setbom) {
		    $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
	    }
	    foreach($unicode as $char) {
		    if($char == 0xFFFD) {
			    $outstr .= "\xFF\xFD"; // replacement character
		    } elseif ($char < 0x10000) {
			    $outstr .= chr($char >> 0x08);
			    $outstr .= chr($char & 0xFF);
		    } else {
			    $char -= 0x10000;
			    $w1 = 0xD800 | ($char >> 0x10);
			    $w2 = 0xDC00 | ($char & 0x3FF);   
			    $outstr .= chr($w1 >> 0x08);
			    $outstr .= chr($w1 & 0xFF);
			    $outstr .= chr($w2 >> 0x08);
			    $outstr .= chr($w2 & 0xFF);
		    }
	    }
	    return $outstr;
    }

   } // END OF CLASS
   //Handle special IE contype request
   if(isset($_SERVER['HTTP_USER_AGENT']) AND ($_SERVER['HTTP_USER_AGENT']=='contype')) {
    header('Content-Type: application/pdf');
    exit;
   }
}
//============================================================+
// END OF FILE
//============================================================+
?>

 

Now go to your fpdf/font folder and open Heleveticab.php and change the code to:

<?php
// vim: expandtab sw=4 ts=4 sts=4:
$fpdf_charwidths['helveticaB']=array(
   chr(0)=>278, chr(1)=>278, chr(2)=>278, chr(3)=>278, chr(4)=>278, chr(5)=>278, chr(6)=>278, chr(7)=>278, chr(8)=>278, chr(9)=>278, chr(10)=>278, chr(11)=>278, chr(12)=>278, chr(13)=>278, chr(14)=>278, chr(15)=>278, chr(16)=>278, chr(17)=>278, chr(18)=>278, chr(19)=>278, chr(20)=>278, chr(21)=>278,
   chr(22)=>278, chr(23)=>278, chr(24)=>278, chr(25)=>278, chr(26)=>278, chr(27)=>278, chr(28)=>278, chr(29)=>278, chr(30)=>278, chr(31)=>278, ' '=>278, '!'=>333, '"'=>474, '#'=>556, '$'=>556, '%'=>889, '&'=>722, '\''=>238, '('=>333, ')'=>333, '*'=>389, '+'=>584,
   ', '=>278, '-'=>333, '.'=>278, '/'=>278, '0'=>556, '1'=>556, '2'=>556, '3'=>556, '4'=>556, '5'=>556, '6'=>556, '7'=>556, '8'=>556, '9'=>556, ':'=>333, ';'=>333, '<'=>584, '='=>584, '>'=>584, '?'=>611, '@'=>975, 'A'=>722,
   'B'=>722, 'C'=>722, 'D'=>722, 'E'=>667, 'F'=>611, 'G'=>778, 'H'=>722, 'I'=>278, 'J'=>556, 'K'=>722, 'L'=>611, 'M'=>833, 'N'=>722, 'O'=>778, 'P'=>667, 'Q'=>778, 'R'=>722, 'S'=>667, 'T'=>611, 'U'=>722, 'V'=>667, 'W'=>944,
   'X'=>667, 'Y'=>667, 'Z'=>611, '['=>333, '\\'=>278, ']'=>333, '^'=>584, '_'=>556, '`'=>333, 'a'=>556, 'b'=>611, 'c'=>556, 'd'=>611, 'e'=>556, 'f'=>333, 'g'=>611, 'h'=>611, 'i'=>278, 'j'=>278, 'k'=>556, 'l'=>278, 'm'=>889,
   'n'=>611, 'o'=>611, 'p'=>611, 'q'=>611, 'r'=>389, 's'=>556, 't'=>333, 'u'=>611, 'v'=>556, 'w'=>778, 'x'=>556, 'y'=>556, 'z'=>500, '{'=>389, '|'=>280, '}'=>389, '~'=>584, chr(127)=>350, chr(128)=>556, chr(129)=>350, chr(130)=>278, chr(131)=>556,
   chr(132)=>500, chr(133)=>1000, chr(134)=>556, chr(135)=>556, chr(136)=>333, chr(137)=>1000, chr(138)=>667, chr(139)=>333, chr(140)=>1000, chr(141)=>350, chr(142)=>611, chr(143)=>350, chr(144)=>350, chr(145)=>278, chr(146)=>278, chr(147)=>500, chr(148)=>500, chr(149)=>350, chr(150)=>556, chr(151)=>1000, chr(152)=>333, chr(153)=>1000,
   chr(154)=>556, chr(155)=>333, chr(156)=>944, chr(157)=>350, chr(158)=>500, chr(159)=>667, chr(160)=>278, chr(161)=>333, chr(162)=>556, chr(163)=>556, chr(164)=>556, chr(165)=>556, chr(166)=>280, chr(167)=>556, chr(168)=>333, chr(169)=>737, chr(170)=>370, chr(171)=>556, chr(172)=>584, chr(173)=>333, chr(174)=>737, chr(175)=>333,
   chr(176)=>400, chr(177)=>584, chr(178)=>333, chr(179)=>333, chr(180)=>333, chr(181)=>611, chr(182)=>556, chr(183)=>278, chr(184)=>333, chr(185)=>333, chr(186)=>365, chr(187)=>556, chr(188)=>834, chr(189)=>834, chr(190)=>834, chr(191)=>611, chr(192)=>722, chr(193)=>722, chr(194)=>722, chr(195)=>722, chr(196)=>722, chr(197)=>722,
   chr(198)=>1000, chr(199)=>722, chr(200)=>667, chr(201)=>667, chr(202)=>667, chr(203)=>667, chr(204)=>278, chr(205)=>278, chr(206)=>278, chr(207)=>278, chr(208)=>722, chr(209)=>722, chr(210)=>778, chr(211)=>778, chr(212)=>778, chr(213)=>778, chr(214)=>778, chr(215)=>584, chr(216)=>778, chr(217)=>722, chr(218)=>722, chr(219)=>722,
   chr(220)=>722, chr(221)=>667, chr(222)=>667, chr(223)=>611, chr(224)=>556, chr(225)=>556, chr(226)=>556, chr(227)=>556, chr(228)=>556, chr(229)=>556, chr(230)=>889, chr(231)=>556, chr(232)=>556, chr(233)=>556, chr(234)=>556, chr(235)=>556, chr(236)=>278, chr(237)=>278, chr(238)=>278, chr(239)=>278, chr(240)=>611, chr(241)=>611,
   chr(242)=>611, chr(243)=>611, chr(244)=>611, chr(245)=>611, chr(246)=>611, chr(247)=>584, chr(248)=>611, chr(249)=>611, chr(250)=>611, chr(251)=>611, chr(252)=>611, chr(253)=>556, chr(254)=>611, chr(255)=>556);
?>

 

 

Make sure you are calling the php file to Helveticab.php and make sure this file is placed in fpdf/font folder.

Let me know if it worked out!

Link to comment
Share on other sites

Okay change the fpdf.php file back to original and keep the Helveticab.php as mentioned above in same folder as mentioned above.

 

Try again and tell me if anything changes.

I think the original file had a problem finding the HelveticaB.php or it was uncorrectly named.

 

Let me know if anything changes!

Link to comment
Share on other sites

@helldog : I'v ejust done whar you asked for, went back to the initial fpdf.php file and kept the new helveticab.php in /font but I have the error : ErrorFPDF error: Could not include font metric file . I've checked and all the file in /font are here and they are the same as in PS1473, last release, I don't really understand

Link to comment
Share on other sites

Okay we are going the good way, you have the correct file in the correct folder.

Now we will give the FPDF.php a good direction to the fonts.

Find this code:

 

define('FPDF_VERSION','1.6');

 

And change it to:

 

define('FPDF_FONTPATH','class/fpdf_font/');

 

Let me know if it worked out.. Cheers helldog!

Link to comment
Share on other sites

I alwyas get the same error .

I'm a bit confused with the code :

define('FPDF_FONTPATH','class/font/');

require('fpdf.php');

class/font/ : I think you mean the path to font folder, there's no class/font path existing , and what's the map you're talking about ?

In the beginning of my fpdf.php file I've addes these line

define('FPDF_FONTPATH',dirname(__FILE__).'/font/');

define('FPDF_FONTPATHH',dirname(__FILE__).'/font/helveticab.php');

and after echoed these variables, the path to fpdf/font/helveticab.php is found

I've also checked the permission of the fhe folder and the files within /font, they're all at 644.

 

I've added the initial code, and now it doesn't enter the function _getfontpath()

I've also deleted the authName of the htaccess in case of.

Very weird !!

Link to comment
Share on other sites

Make sure the map is called fpdf_font else it won't work

Or else change the code to:

define('FPDF_FONTPATH','class/font/');
require('fpdf.php');

 

My bad change the code to:

 

define('FPDF_FONTPATH','font/');
require('fpdf.php');

 

I am trying to help lots of people now with different problems, getting a bit confused now haha

it is not in the class folder, but in the tools folder sorry! :)

Link to comment
Share on other sites

Okay my last resort now:

I have studied the FPDF program a little and this is what I found out:

 

Currently, fpdf only supports Helvetica (Arial), Times, Courier, and Symbol. I ended up not using any "symbols" in the reports, so I guess the symbol.php file is not needed. You can edit both the pdfpedigreeform.php and pdfdescendform.php files to include the HelveticaB font by including the line <OPTION Value="HelveticaB"> HelveticaB in the appropriate place beneath <SELECT Name="rptFont">.

 

There are so many files because there are different files for normal, bold, italic, and bold-italic font-styles.

 

Make sure it is supposed to be called HelveticaB, check other files to see what it is called in FPDF.

Let me know if this made any changes!

Cheers helldog

Link to comment
Share on other sites

Hi,

Here's the last news. The erro comes from the _out() function

 

Here's the code executed at the end of the _setFont function:

//Select it

$this->FontFamily=$family;

echo '$family:' .$family;

$this->FontStyle=$style;

echo '$style:' .$style;

$this->FontSizePt=$size;

$this->FontSize=$size/$this->k;

echo '$size:' .$size;

$this->CurrentFont=&$this->fonts[$fontkey];

echo '$fontkey:' .$fontkey;

if($this->page>0)

$this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));

 

$fontkey:courierB$family:courier$style:B$size:7$fontkey:courierBFatal error

Then the the call to _out() function causes error but why !?!?

 

An idea ?

 

Cheers

Link to comment
Share on other sites

I've created courierb.php, courieri.php and courierbi.php files and containing the code to put in helveticab.php and changing the values..

I've always get the error but it seems it aborts by the end.

Pl

fpdf-11111fpdf-FPDFfpdf-SetFont$fontkey:courierB$family:courier$family:courier$style:B$size:15$fontkey:courierBfpdf-SetFont$fontkey:courier$family:courier$style:$size:12$fontkey:courierfpdf-SetFont$fontkey:courier$family:courier$style:$size:9$fontkey:courierfpdf-SetFontfpdf-SetFont$fontkey:courierB$family:courier$style:B$size:8$fontkey:courierBfpdf-SetFont$fontkey:courier$family:courier$style:$size:8$fontkey:courierfpdf-SetFont$fontkey:courierB$family:courier$style:B$size:7$fontkey:courierBFatal error

ease check the echoed code :

 

An idea ?

Link to comment
Share on other sites

You can edit both the pdfpedigreeform.php and pdfdescendform.php files to include the courierB font by including the line <OPTION Value="courierB"> courierB in the appropriate place beneath <SELECT Name="rptFont">.

 

This is excactly what you did for HelevitcaB and that doesn't seem to give an error anymore.

Now we just have to specify the next font family to pinpoint it the correct way.

 

Let me know if this worked out!

Cheers Helldog.

Link to comment
Share on other sites

I have taken some other research as you had the metric failure.

The thing is you need to add and install the font on your server/host.

This needs two files: PFM and AFM (AFM is the Metric file) if this is not on the host/server it can not be found either, which results in an error and can not be used.

 

Here is a website with detailed information on how to create your AFM file and redirect your FPDF to your metric file.

I hope this makes any sense to you, and I hope all the hard work for you will finaly result in a completion.

 

Cheers Helldog..

 

Owh BTW the website is: http://www.id.uzh.ch/cl/zinfo/fpdf/tutorial/tuto7.htm

Link to comment
Share on other sites

I think it's not a metric error but I may be wrong.

The last echoed variables (as mentionned 2 psots ago) is here:

 

$fontkey:courierB$family:courier$style:B$size:7$fontkey:courierBFatal error

So the courierB is found but in the function _out() there's a problem, I think which causes the Fatal Error above.

 

Am i wrong ?

Link to comment
Share on other sites

Okay well if it is not a metric error, then we can continue to step 2 as issued on the same website.

You have a helper script in tools/fpdf/font/makefont.

 

Read this one the same website I gave you earlier:

- Generation of the font definition file

- Declaration of the font in a script

 

That SHOULD do the trick!

Cheers Helldog!

Link to comment
Share on other sites

It seems there's a problem with the _out() function here :

function _out($s)
{
//Add a line to the document
echo 'fpdf-_out';
echo '$s:' .$s;' ';
if($this->state==2)
 $this->pages[$this->page].=$s."\n";
else
 $this->buffer.=$s."\n";
}

 

The displays :

$fontkey:courierBfpdf-_out$s:BT /F1 7.00 Tf ETFatal error

 

My 2 lines of echo dispay correctly and I have the Fatal Error after so I think the test causes the crash, but why?

Link to comment
Share on other sites

I(ve uploaded yout fpdf.php file and the PDF delivery works well but the PDF invoice has always the fatal error.and it's in the out() function.

I was thinking of an issue with PHP5 but I don't really know.

 

Cheers

Link to comment
Share on other sites

Maybe we should debug your site hope it gives back an error with little more information.

 

in config/config.inc.php you can find these lines:

 

/* Debug only */
@ini_set('display_errors', 'off');
define('_PS_DEBUG_SQL_', false);

 

Change it with:

 

/* Debug only */
@ini_set('display_errors', 'on');
define('_PS_DEBUG_SQL_', true);

 

return to website and let me know what kind of error you get, this might bring us a little closer to finding the error.

If it is possible for this problem offcourse, as I am running out of resources ;)

 

Cheers Helldog!

Link to comment
Share on other sites

Thanks very much for your help. I'm still investigating to find something.

I don't really understand why it works for the delivery PDF and not for the invoice. Do you think data of the db could be involved ?

I already ckecked the invoice data and all seems correct.

Another idea is : when you click to generate the PDF, where is the access to the db made, in /controller folder... ? What are the fiels involved in that process ? Do you know ?

Cheers

Link to comment
Share on other sites

  • 3 years later...

Hi there,Please could you help me? I have a website on PS 1,3 and whenever I try download an attachment it comes up saying the file type is not recognized. If I choose what program to open with and I select adobe then it opens. How do I correct this?

Link to comment
Share on other sites

×
×
  • Create New...