问题
I've this simple script that write some text into a PDF trought the php library TCPDF. This is the script:
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Label Creator');
$pdf->SetTitle('labels');
$pdf->SetSubject('Labels di prova');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE,0);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// set font
$pdf->SetFont('times', '', 15);
//left margin
$pdf->SetMargins(18,15,18,FALSE);
// add a page
$pdf->AddPage();
$label="Hello world, i'm michele";
$pdf->Cell(0, 0 , $label, 0, 1, 'C', 0, '', 0,FALSE,'T','M');
//Close and output PDF document
$pdf->Output('../../labels.pdf', 'F');
echo 'Labels generate!';
the problem is that the script works, but in the file I'll see the text without spaces! Like this: helloworld,i'mmichele Does anyone have the solution?!!?
回答1:
Option 1: If you want to use Cell
The prototype is:
//Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M')
To deal with spacing, use these:
$pdf->Cell(0, 0, 'TEST CELL STRETCH: spacing', 1, 1, 'C', 0, '', 3);
$pdf->Cell(0, 0, 'TEST CELL STRETCH: force spacing', 1, 1, 'C', 0, '', 4);
You can try this:
$label="Hello world, i'm michele";
$pdf->Cell(0, 0 , $label, 1, 1, 'C', 0, '', 3;
The border is on, so that you can see if the cell is large enough. Hope this works. (for indication, what follows : FALSE,'T','M' are already the values by default)
Option 2: You can also use Write()
$pdf->AddPage();
// set some text to print
$label = <<<EOD
About Michele.
Michele is awesome.
EOD;
// print a block of text using Write()
$pdf->Write($h=0, $label, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
You can find plenty of examples there: TCPDF examples
回答2:
I believe the problem lies with the "times" font. I had the same problems with that particular font. You can try some of the other fonts in the tcpdf fonts directory.
回答3:
I've resolved, the problem is a bug with the browser's PDF plug-in visualizer!!
来源:https://stackoverflow.com/questions/10914835/write-space-with-tcpdf-into-a-pdf-file