使用TCPDF将空间写入PDF文件

时间:2012-06-06 13:07:30

标签: php pdf whitespace tcpdf

我有这个简单的脚本,将一些文本写入PDF文件TCPDF。 这是脚本:

// 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!';

问题是脚本有效,但在文件中我会看到没有空格的文本!像这样: 的HelloWorld,i'mmichele 有没有人有解决方案?!!?

3 个答案:

答案 0 :(得分:0)

选项1:如果您想使用Cell

原型是:

//Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M')

要处理间距,请使用以下内容:

$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);

你可以试试这个:

$label="Hello world, i'm michele";
$pdf->Cell(0, 0 , $label, 1, 1, 'C', 0, '', 3;

边框已打开,因此您可以查看单元格是否足够大。希望这有效。 (用于指示,以下内容:FALSE,'T','M'默认为值)

选项2:您还可以使用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);

您可以在那里找到大量示例:TCPDF examples

答案 1 :(得分:0)

我认为问题在于“时代”字体。我遇到了与特定字体相同的问题。您可以在tcpdf fonts目录中尝试一些其他字体。

答案 2 :(得分:0)

我已经解决了,问题是浏览器的PDF插件可视化工具的错误!!

相关问题