1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > php tcpdf修改pdf内容 php-使用TCPDF将空间写入PDF文件

php tcpdf修改pdf内容 php-使用TCPDF将空间写入PDF文件

时间:2021-05-23 17:19:52

相关推荐

php tcpdf修改pdf内容 php-使用TCPDF将空间写入PDF文件

我有一个简单的脚本,可以将一些文本写入PDF,而不是php库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

有人有解决方案吗?!?

解决方法:

选项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,'TESTCELLSTRETCH:spacing',1,1,'C',0,'',3);

$pdf->Cell(0,0,'TESTCELLSTRETCH:forcespacing',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();

//setsometexttoprint

$label =<<

About Michele.

Michele is awesome.

EOD;

//printablockoftextusingWrite()

$pdf->Write($h=0,$label,$link='',$fill=0,$align='C',$ln=true,$stretch=0,$firstline=false,$firstblock=false,$maxh=0);

标签:tcpdf,php,pdf,whitespace

来源: https://codeday.me/bug/1013/1904949.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。