SetCreator(PDF_CREATOR); $pdf->SetAuthor('Ken Draper'); $pdf->SetTitle('TCPDF : method CellFitText'); $pdf->SetSubject('Documentation and Examples'); $pdf->SetKeywords('TCPDF, PDF, CellFitText, documentation, example'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, 'TCPDF : method CellFitText', "Documentation and Examples\nby Ken Draper, ken@spottedhog.co.uk, www.spottedhog.co.uk"); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // --------------------------------------------------------- $pdf->AddPage('P','A4'); $pdf->SetFillColor(150, 225, 255); // parms($w, $h=0, $txt='', $border=0, $ln=0, $halign='', $valign='', $fill=0, $link='', $pad='', $fit='', $fontsizePtmin=0, tabsize) { $pdf->SetFontSize(11); $pdf->SetXY(15,25); $pdf->CellFitText(30,10,"Class Libary" ,1,0,'R','T',1,'','3,2,3'); $pdf->CellFitText(150,10,"TCPDF - PHP class for generating PDF documents",1,1,'L','T',0,'','3,2,3'); $pdf->CellFitText(30,10,"Method" ,1,0,'R','T',1,'','3,2,3'); $pdf->CellFitText(150,10,"CellFitText",1,1,'L','T',0,'','3,2,3'); $pdf->CellFitText(30,20,"Author" ,1,0,'R','T',1,'','3,2,3'); $pdf->CellFitText(150,20, "Ken Draper - info@spottedhog.co.uk - http://www.spottedhog.co.uk". "\n\tNOTE: This class is an entension to the TCPDF class by Nicola Asuni". "\n\tinfo@tecnick.com - http://www.tcpdf.org" ,1,1,'L','T',0,'','3,2,3'); $pdf->CellFitText(30,10,"License" ,1,0,'R','T',1,'','3,2,3'); $pdf->CellFitText(150,10,"GNU Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)",1,1,'L','T',0,'','3,2,3'); $pdf->CellFitText(30,40,"Description" ,1,0,'R','T',1,'','3,2,3'); $pdf->CellFitText(150,40, "Displays a cell containing text at the current position.". "\nProvides control over borders, fill, padding, horizontal and vertical cell alignment, forced new lines and tabs.". "\nMakes a prioritised set of compromises in an attempt to fit all the text within the cell.". "\nThese compromises include reducing the font size, reducing cell padding, removing whitespace, removing forced new lines/tabs and splitting words. The set of compromises and the order they are applied can be controlled.", 1,1,'L','T',0,'','3,2,3'); $pdf->CellFitText(30,15,"When to Use" ,1,0,'R','T',1,'','3,2,3'); $pdf->CellFitText(150,15, "This method is most useful when placing variable length formatted text into fixed size page areas and ensuring that every effort is made to display all the text.", 1,1,'L','T',0,'','3,2,3'); $pdf->CellFitText(30,10,"Version" ,1,0,'R','T',1,'','3,2,3'); $pdf->CellFitText(150,10,"1.0.0",1,1,'L','T',0,'','3,2,3'); $pdf->CellFitText(30,18,"Compatiability" ,1,0,'R','T',1,'','3,2,3',5,'f'); $pdf->CellFitText(150,18,"PHP 5.2.12\nTCPDF 4.8.039\n unknown for other versions",1,1,'L','T',0,'','3,2,3'); $pdf->AddPage('P','A4'); $pdf->SetY($pdf->GetY()); $pdf->CellFitText(180,6,"Parmeters" ,1,1,'L','M',1); $pdf->SetFont('courier'); $pdf->CellFitText(180,22, 'void CellTextFit( float $w, [float $h = 0], [string $txt = '."''".'],\n\t[mixed $border = 0], [int $ln = 0], [string $halign = '."''".'],\n\t[string $valign = '."''".'], '. '[int $fill = 0], [mixed $link = '."''".'],\n\t[mixed $pad = '."''".'], [int $tab = 5], [string $fit = '."''".'], [int $fontmin = 8] )' ,1,1,'L','J',0,'',1); $pdf->SetFont('helvetica'); $pdf->CellFitText(20,6,'Parm' ,1,0,'L','M',1); $pdf->CellFitText(25,6,"Name" ,1,0,'L','M',1); $pdf->CellFitText(15,6,"Type" ,1,0,'L','M',1); $pdf->CellFitText(15,6,"Default" ,1,0,'L','M',1); $pdf->CellFitText(105,6,"Description",1,1,'L','M',1,'','3'); $pdf->SetFillColor(235, 249, 249); $pdf->CellFitText(20,13,'$w' ,1,0,'L','T',1); $pdf->CellFitText(25,13,"width" ,1,0,'L','T',1); $pdf->CellFitText(15,13,"float" ,1,0,'L','T',1); $pdf->CellFitText(15,13,"0" ,1,0,'L','T',1); $pdf->CellFitText(105,13, "Cell width.\nIf 0 extends to the right margin", 1,1,'L','T',0,'','3'); $pdf->CellFitText(20,13,'$h' ,1,0,'L','T',1); $pdf->CellFitText(25,13,"height" ,1,0,'L','T',1); $pdf->CellFitText(15,13,"float" ,1,0,'L','T',1); $pdf->CellFitText(15,13,"0",1,0,'L','T',1); $pdf->CellFitText(105,13, "Cell height.\nIf 0 the height will extended to fit the content.", 1,1,'L','T',0,'','3'); $pdf->CellFitText(20,32,'$txt' ,1,0,'L','T',1); $pdf->CellFitText(25,32,"text" ,1,0,'L','T',1); $pdf->CellFitText(15,32,"string" ,1,0,'L','T',1); $pdf->CellFitText(15,32,"empty string",1,0,'L','T',1); $pdf->CellFitText(105,32, "The string to print.\nMay contain the escape characters :-\n\t". "\ n - New line\n\t". "\ t - Tab (refer to the ".'$tabsize'." parameter.)\n". "Note : there must not be a space between the \ and the escape characters (n,t).", 1,1,'L','T',0,'','3'); $pdf->CellFitText(20,51,'$border' ,1,0,'L','T',1); $pdf->CellFitText(25,51,"border" ,1,0,'L','T',1); $pdf->CellFitText(15,51,"mixed" ,1,0,'L','T',1); $pdf->CellFitText(15,51,"0",1,0,'L','T',1); $pdf->CellFitText(105,51, "Determines whether cell borders are displayed.". "\nValid values are :-". "\n\t0\t - (int) no border. (default)". "\n\t1\t - (int) border on all sides.". "\n\t'LTRB' - (string) a string containing one or more of :-". "\n\t\t\tL - left". "\n\t\t\tT - top". "\n\t\t\tR - right". "\n\t\t\tB - bottom". "\nThe current default line style is used." ,1,1,'L','T',0,'','3',8); $pdf->CellFitText(20,26,'$ln' ,1,0,'L','T',1); $pdf->CellFitText(25,26,"new current position" ,1,0,'L','T',1); $pdf->CellFitText(15,26,"int" ,1,0,'L','T',1); $pdf->CellFitText(15,26,"0",1,0,'L','T',1); $pdf->CellFitText(105,26, "Determines where the new current page position will be after the cell is output.". " Valid values are :-". "\n\t0 - to the right (or left for RTL languages)". "\n\t1 - start of next line.". "\n\t2 - below" ,1,1,'L','T',0,'','3',8); $pdf->CellFitText(20,31,'$halign' ,1,0,'L','T',1); $pdf->CellFitText(25,31,"horizontal text alignment" ,1,0,'L','T',1); $pdf->CellFitText(15,31,"string" ,1,0,'L','T',1); $pdf->CellFitText(15,31,"L",1,0,'L','T',1); $pdf->CellFitText(105,31, "Determines the horizontal alignment of the text within the cell.". " Valid values are :-". "\n\tL, '' - Left (default)". "\n\tC - Centered.". "\n\tR - Right". "\n\tJ - Justified" ,1,1,'L','T',0,'','3',8); $pdf->CellFitText(20,36,'$valign' ,1,0,'L','T',1); $pdf->CellFitText(25,36,"vertical text alignment" ,1,0,'L','T',1); $pdf->CellFitText(15,36,"string" ,1,0,'L','T',1); $pdf->CellFitText(15,36,"M",1,0,'L','T',1); $pdf->CellFitText(105,36, "Determines the vertical alignment of the text within the cell.". "\nValid values are :-". "\n\tT - Top.". "\n\tM, '' - Middle (default).". "\n\tB - Bottom". "\n\tJ - Justified" ,1,1,'L','T',0,'','3',8); $pdf->SetFillColor(150, 225, 255); $pdf->AddPage('P','A4'); $pdf->CellFitText(20,6,'Parm' ,1,0,'L','M',1); $pdf->CellFitText(25,6,"Name" ,1,0,'L','M',1); $pdf->CellFitText(15,6,"Type" ,1,0,'L','M',1); $pdf->CellFitText(15,6,"Default" ,1,0,'L','M',1); $pdf->CellFitText(105,6,"Description",1,1,'L','M',1,'','3'); $pdf->SetFillColor(235, 249, 249); $pdf->CellFitText(20,21,'$fill' ,1,0,'L','T',1); $pdf->CellFitText(25,21,"cell fill" ,1,0,'L','T',1); $pdf->CellFitText(15,21,"int" ,1,0,'L','T',1); $pdf->CellFitText(15,21,"0",1,0,'L','T',1); $pdf->CellFitText(105,21, "Determines whether the cell background has a fill color.". "\nValid values are :-". "\n\t0 - No fill (default)". "\n\t1 - fill. Uses default fill color." ,1,1,'L','T',0,'','3',8); $pdf->CellFitText(20,7,'$link' ,1,0,'L','T',1); $pdf->CellFitText(25,7,"URL Link" ,1,0,'L','T',1); $pdf->CellFitText(15,7,"mixed" ,1,0,'L','T',1); $pdf->CellFitText(15,7,"0",1,0,'L','T',1); $pdf->CellFitText(105,7, "URL or identifier returned by AddLink()." ,1,1,'L','T',0,'','3',8); $pdf->CellFitText(20,90,'$pad' ,1,0,'L','T',1); $pdf->CellFitText(25,90,"cell padding" ,1,0,'L','T',1); $pdf->CellFitText(15,90,"mixed" ,1,0,'L','T',1); $pdf->CellFitText(15,90,"empty string",1,0,'L','T',1); $pdf->CellFitText(105,90, "Determines the size of the empty space between the cell edge and the block containing the text.". "\n\nValid values are :-". "\n empty string - the system default padding (default)". "\n\t\t left,right - Value of ".'$cMargin variable'. "\n\t\t top,bottom - ".'$cMargin / 2'. "\n\n float\t - a single float positve numeric. represents the\n\t\tpadding value in system units to be applied\n\t\t to all sides". "\n\n 'float,float,float,float' - a string containing between 1 and 4". "\n\t\tcomma separated floats interpretted as". "\n\t\t'left,top,right,bottom' padding values.". "\n\ne.g. ',3,1' interprretted as left default, top 3 units, right 1 unit, bottom - default." ,1,1,'L','T',0,'','3',8); $pdf->CellFitText(20,20,'$tab' ,1,0,'L','T',1); $pdf->CellFitText(25,20,"tab size" ,1,0,'L','T',1); $pdf->CellFitText(15,20,"int" ,1,0,'L','T',1); $pdf->CellFitText(15,20,"5",1,0,'L','T',1); $pdf->CellFitText(105,20, "The default number of spaces representing a tab.\nA tab is placed within text using a \ t (without a space after the \)" ,1,1,'L','T',0,'','3',8); $pdf->CellFitText(20,86,'$fit' ,1,0,'L','T',1); $pdf->CellFitText(25,86,"text fit rules" ,1,0,'L','T',1); $pdf->CellFitText(15,86,"string" ,1,0,'L','T',1); $pdf->CellFitText(15,86,"empty string",1,0,'L','T',1); $pdf->CellFitText(105,86, "Determines the set and priority of the measures taken to fit the supplied text within the given cell dimensions. The measures taken are cumulative.". "\nValid values are :-". "\n\tempty string - interpretted as 'fpsw' (see below)". "\n\t'x' - disable all rules". "\n\tstring - 1 to 5 characters from the below rules. The order dictates the priority from highest to lowest.". "\n\nRules :-". "\n\tf - reduce the current fontsize until all the text can be displayed. Down to a mimin value of ".'$fontmin.'. "\n\tp - reduce the padding factors in the order (Bottom,Left,Top,Right) until the full text can be displayed.". "\n\ts - remove excess spaces whitespace new lines and tabs from the text.". "\n\tw - split lines mid word where necessary." ,1,1,'L','T',0,'','3',8); $pdf->CellFitText(20,12,'$fontmin' ,1,0,'L','T',1); $pdf->CellFitText(25,12,"minimum font size PT" ,1,0,'L','T',1); $pdf->CellFitText(15,12,"float" ,1,0,'L','T',1); $pdf->CellFitText(15,12,"8",1,0,'L','T',1); $pdf->CellFitText(105,12, "The minimum fontsize in points to be considered for use when applying the text fit rule 'f'" ,1,1,'L','T',0,'','3',8); $pdf->SetFillColor(150, 225, 255); $pdf->AddPage('P','A4'); $pdf->CellFitText(180,6,"Examples" ,1,1,'L','M',1); $pdf->SetFillColor(235, 249, 249); $pdf->SetXY($pdf->GetX(),$pdf->GetY()+5); $pdf->CellFitText(180,6,'1) Defaults\t$w=55, $h=20, $txt='."'...'".', all other parameters as default.' ,0,1,'L','M',1); $pdf->SetXY($pdf->GetX()+50,$pdf->GetY()+5); $pdf->CellFitText(55/*w*/,20/*h*/,"'To err is human but to really foul things up requires a computer' - Farmers' Almanac"); $pdf->SetXY(15,$pdf->GetY()+25); $pdf->CellFitText(180,6,'2) Border, Fill \t$w=55, $h=17, $txt='."'...'".', $border=1, $fill=1' ,0,1,'L','M',1); $pdf->SetXY($pdf->GetX()+50,$pdf->GetY()+5); $pdf->CellFitText(55/*w*/,17/*h*/,"'The thing with high-tech is that you always end up using scissors' - David Hockney",1,0,'','',1); $pdf->SetXY(15,$pdf->GetY()+25); $pdf->CellFitText(180,6,'3) Padding, vertical and horizontal justification ..., $halign='."'J'".', $valign='."'J'".', $pad=5',0,1,'L','M',1); $pdf->SetXY($pdf->GetX()+45,$pdf->GetY()+5); $pdf->CellFitText(75/*w*/,35/*h*/,"'Someone told me that each equation I included in the book would halve the sales.' - Stephen Hawkings" ,1/*border*/,0/*ln*/,'J'/*halign*/,'J'/*valign*/,1/*fill*/,''/*link*/,5/*pad*/,5/*tab*/,''/*fit*/,''/*fontmin*/); $pdf->SetXY(15,$pdf->GetY()+45); $pdf->CellFitText(180,6,'4) Explicit tabs ( \ t ) and new lines ( \ n ) within text. $tab=7',0,1,'L','M',1); $pdf->SetXY($pdf->GetX()+40,$pdf->GetY()+5); $pdf->CellFitText(90/*w*/,0/*h*/,"\tThe tab escape character has been used to indent the start of this sentence.". "\n\n\tThis sentence starts with an explicit new line character and a tab character.". "\n\n\tCombinations of the newline and tab characters can be used to :-". "\n\t\t1 - format indented paragraphs". "\n\t\t2 - create indented lists". "\n\t\t3 - leave\tlarge\tgaps" ,1/*border*/,0/*ln*/,''/*halign*/,''/*valign*/,1/*fill*/,''/*link*/,''/*pad*/,7/*tab*/); $pdf->AddPage('P','A4'); $pdf->CellFitText(180,6,'5) Fit',0,1,'L','M',1); $pdf->CellFitText(170/*w*/,0/*h*/,"\n\tFollows are a series of examples used to illustrate the measures that the CellTextFit method can take to ensure that all the provided text is displayed within the cell.". "\n The following text will be used to show the impact of each of the 'fit' measures :-" ,0/*border*/,1/*ln*/,''/*halign*/,''/*valign*/,0/*fill*/,''/*link*/,''/*pad*/,7/*tab*/,''/*fit*/,''/*fontmin*/); $pdf->SetXY($pdf->GetX()+5,$pdf->GetY()+5); $pdf->CellFitText(170/*w*/,0/*h*/, "\tDecca Records rejected The Beatles, saying that 'guitar groups are on the way out' and 'the Beatles have no future in show business'.". "\n\tThey instead signed The Tremeloes because they were local and would require less travel expenses." ,0/*border*/,1/*ln*/,''/*halign*/,''/*valign*/,1/*fill*/,''/*link*/,''/*pad*/,7/*tab*/,''/*fit*/,''/*fontmin*/); $pdf->SetXY(15,$pdf->GetY()+7); $pdf->CellFitText(180,0,'\tThis example shows a cell with the fit rules disabled resulting in the text not fitting into the cell. $fit='."'x'. Note that the padding is set to 5 for all sides.",0,1); $pdf->SetXY($pdf->GetX()+30,$pdf->GetY()+3); $pdf->CellFitText(90/*w*/,40/*h*/, "\tDecca Records rejected The Beatles, saying that 'guitar groups are on the way out' and 'the Beatles have no future in show business'.". "\n\tThey instead signed The Tremeloes because they were local and would require less travel expenses." ,1/*border*/,1/*ln*/,''/*halign*/,''/*valign*/,1/*fill*/,''/*link*/,5/*pad*/,''/*tab*/,'x'/*fit*/,''/*fontmin*/); $pdf->SetXY(15,$pdf->GetY()+7); $pdf->CellFitText(180,0,'\tThe same example with $fit='."''".'. This is the default. It is interpretted as $fit='."'fpsw'".' Each of the fit measures are applied in priority order (left to right) until the text fits. The application of the measures is cummulative. In this example the font size reduction is sufficient.',0,1); $pdf->SetXY($pdf->GetX()+30,$pdf->GetY()+3); $pdf->CellFitText(90/*w*/,40/*h*/, "\tDecca Records rejected The Beatles, saying that 'guitar groups are on the way out' and 'the Beatles have no future in show business'.". "\n\tThey instead signed The Tremeloes because they were local and would require less travel expenses." ,1/*border*/,1/*ln*/,''/*halign*/,''/*valign*/,1/*fill*/,''/*link*/,5/*pad*/,''/*tab*/,''/*fit*/,''/*fontmin*/); $pdf->SetXY(15,$pdf->GetY()+7); $pdf->CellFitText(180,0,'\tThe same example with $fit='."'f'".'. The font is reduced to ensure the text fits. This is the same result as above since the font reduction was the highest priority measure and was sufficient in the previous example.',0,1); $pdf->SetXY($pdf->GetX()+30,$pdf->GetY()+3); $pdf->CellFitText(90/*w*/,40/*h*/, "\tDecca Records rejected The Beatles, saying that 'guitar groups are on the way out' and 'the Beatles have no future in show business'.". "\n\tThey instead signed The Tremeloes because they were local and would require less travel expenses." ,1/*border*/,1/*ln*/,''/*halign*/,''/*valign*/,1/*fill*/,''/*link*/,5/*pad*/,''/*tab*/,'f'/*fit*/,''/*fontmin*/); $pdf->AddPage('P','A4'); $pdf->SetXY(15,$pdf->GetY()); $pdf->CellFitText(180,0,'\tThe same example with $fit='."'p'".'. The bottom padding is reduced to ensure the text fits. The right, top and left padding would have also be reduced/removed if this had been necessary.',0,1); $pdf->SetXY($pdf->GetX()+30,$pdf->GetY()+3); $pdf->CellFitText(90/*w*/,40/*h*/, "\tDecca Records rejected The Beatles, saying that 'guitar groups are on the way out' and 'the Beatles have no future in show business'.". "\n\tThey instead signed The Tremeloes because they were local and would require less travel expenses." ,1/*border*/,1/*ln*/,''/*halign*/,''/*valign*/,1/*fill*/,''/*link*/,5/*pad*/,''/*tab*/,'p'/*fit*/,''/*fontmin*/); $pdf->SetXY(15,$pdf->GetY()+7); $pdf->CellFitText(180,0,'\tThe same example with $fit='."'s'".'. New lines, Tabs and multiple spaces are reduce to single space characters.',0,1); $pdf->SetXY($pdf->GetX()+30,$pdf->GetY()+3); $pdf->CellFitText(90/*w*/,40/*h*/, "\tDecca Records rejected The Beatles, saying that 'guitar groups are on the way out' and 'the Beatles have no future in show business'.". "\n\tThey instead signed The Tremeloes because they were local and would require less travel expenses." ,1/*border*/,1/*ln*/,''/*halign*/,''/*valign*/,1/*fill*/,''/*link*/,5/*pad*/,''/*tab*/,'s'/*fit*/,''/*fontmin*/); $pdf->SetXY(15,$pdf->GetY()+7); $pdf->CellFitText(180,0,'\tThe same example with $fit='."'w'".'. Words are broken at line ends. This is usually set as the the lowest priority measure.',0,1); $pdf->SetXY($pdf->GetX()+30,$pdf->GetY()+3); $pdf->CellFitText(90/*w*/,40/*h*/, "\tDecca Records rejected The Beatles, saying that 'guitar groups are on the way out' and 'the Beatles have no future in show business'.". "\n\tThey instead signed The Tremeloes because they were local and would require less travel expenses." ,1/*border*/,1/*ln*/,''/*halign*/,''/*valign*/,1/*fill*/,''/*link*/,5/*pad*/,''/*tab*/,'w'/*fit*/,''/*fontmin*/); $pdf->SetXY(15,$pdf->GetY()+7); $pdf->CellFitText(180,0,'\tThis time the cell size has been changed (w=101, h=12) to illustrate the cumulative application of all the measures. The only way to fit this text into a smaller cell would be to reduce the $fontmin parameter which is currently set to the default value of 8pt. $fit='."'fpsw'",0,1); $pdf->SetXY($pdf->GetX()+30,$pdf->GetY()+3); $pdf->CellFitText(101/*w*/,12/*h*/, "\tDecca Records rejected The Beatles, saying that 'guitar groups are on the way out' and 'the Beatles have no future in show business'.". "\n\tThey instead signed The Tremeloes because they were local and would require less travel expenses." ,1/*border*/,1/*ln*/,''/*halign*/,''/*valign*/,1/*fill*/,''/*link*/,5/*pad*/,''/*tab*/,''/*fit*/,''/*fontmin*/); // // --------------------------------------------------------- //Close and output PDF document $pdf->SetDisplayMode('fullpage'); $pdf->Output('tmp/CellFitText.pdf','F'); header('Location: '.'tmp/CellFitText.pdf'); //============================================================+ // END OF FILE //============================================================+ ?>