在PDF中插入换行符 [英] Inserting line breaks into PDF

查看:799
本文介绍了在PDF中插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP即时生成一些PDF文件.我的问题是我需要在要插入PDF文件的文本的某些部分插入换行符.像这样:

I'm generating some PDF file on the fly using PHP. My problem is I need to insert line breaks in some part of the text that will be inserted in the PDF file. Something like:

$pdf->InsertText('Line one\n\nLine two');

因此它会打印:

第一行

第二行

我知道\n在PDF上不起作用,但是你们知道在这些文件上有任何字符或代表换行符的东西吗?

I know \n doesn't work on PDF, but do you guys know any character or something that represents a line break on these files?

推荐答案

如果您使用的是fpdf,为了能够使用换行符,您将需要使用

If you are using fpdf, in order to be able to use line breaks you will need to use a multi-line text cell as described here.

如果使用此选项,则应该正确解释和转换文本中的换行符.

If you use this, then line breaks in your text should be interpreted and converted correctly.

一个简单的例子:

$pdf->Multicell(0,2,"This is a multi-line text string\nNew line\nNew line"); 

在这里,2是多行文本框的高度.我不知道测量的单位是什么,或者您是否可以将其设置为0并忽略它.如果一开始不起作用,也许可以尝试大量使用.

Here, 2 is the height of the multi-line text box. I don't know what units that's measured in or if you can just set it to 0 and ignore it. Perhaps try it with a large number if at first it doesn't work.

这篇关于在PDF中插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆