如何用fpdf或tcpdf或其他格式制作名片?当我有 jpg 背景并且文本需要重叠时?
我有一张用于名片布局的 jpg 图像,尺寸为:9,8 厘米/5,9 厘米。我必须将其作为背景布局,并且在此布局之上我必须打印姓名/地址/电话号码、电子邮件等。并将其打印/保存为 pdf 以供以后使用。
但问题是我无法让它与 FPDF 或 TCPDF 一起使用。知道我该如何准备这个吗?使用 FPDF 或 TCPDF?
I have a jpg image for the business card layout with dimensions: 9,8 cm/5,9 cm. I have to put it as background layout and on top of this layout i have to print name/address/telephone number email etc. And print it/save it as pdf for later use.
But problem is i cant make it work with FPDF or TCPDF. Any idea how can i prepare this? with FPDF or TCPDF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用 TCPDF,您可以绝对定位元素,因此您可以执行类似的操作
TCPDF 在线文档不是很好,但示例有很大帮助
Using TCPDF you can position elements absolutely as it were, so you could do something like
The TCPDF online documentation isn't great, but the examples help a lot http://www.tcpdf.org/examples.php
您特别询问了如何创建名片大小的文档,因此您应该使用:
该文档在此处提供了预定义页面大小的列表:http://www.tcpdf.org/doc/classTCPDF.html#a087d4df77e60b7054e97804069ed32c5
You specifically asked about creating a business card sized document, so you should use:
The documentation gives a list of pre-defined page sizes here: http://www.tcpdf.org/doc/classTCPDF.html#a087d4df77e60b7054e97804069ed32c5
例子 n. http://www.tcpdf.org 上的 51 显示了如何创建整页背景。
然后,对于页面格式,查看getPageSizeFromFormat()方法的源代码文档(已经定义了300多种页面格式,包括名片)。
The example n. 51 at http://www.tcpdf.org shows how to create a full page background.
Then, for the page format, check the source code documentation of the getPageSizeFromFormat() method (more than 300 page formats are already defined, including business cards).
要在 fpdf 上设置背景,您必须在类中设置 Header() 函数时首先调用 Image() 。
我通常这样做的方法是在我自己的类中扩展 Extend FPDF,即:
require('path/to/fpdf.php);
类 SomeClassName 扩展 FPDF {
// 如果需要的话添加实例变量
....
函数头(){
//现在调用Image()
$this->Image(); //在这里设置你的背景
...
}
}
如果您查看 fpdf.org 站点中的常见问题解答,您将看到有关如何执行此操作的(模糊的)说明。
To set the background on fpdf you have to call Image() as the first thing when setting up the Header() function in your class.
The way I normally do it is by extending Extend FPDF in my own class, i.e.:
require('path/to/fpdf.php);
class SomeClassName extends FPDF {
// add your instance variables if needed
....
function Header(){
//now call Image()
$this->Image(); //set up your background here
...
}
}
If you look at faqs in the fpdf.org site you will see (vague) instructions on how to do this.
有一个实现FPDF的库,称为FPDI。要创建自定义纸张尺寸,例如名片,通常使用尺寸为 54mm x 86mm 的 CR80,您可以直接将此尺寸添加到 fpdf 的类构造函数中.php位于stdPageSizes,如下所示:'cr80'=>array(152.82,243.38)。此条目已存在,因此只需添加此自定义条目即可。您的完整定义将如下所示:
如果使用 FPDI,您的调用现在将如下所示:
请注意,即使 CR80 的正确尺寸是 54x86mm,但似乎正确的设置要求这些值乘以 2.83 -已测试。我希望这有助于缩短代码和快速重用。
There is a library which implements FPDF called FPDI. To create custom paper sizes, like business cards, which typically use CR80 with dimensions of 54mm x 86mm, you can directly add this size into the class constructor of fpdf.php at stdPageSizes as this: 'cr80'=>array(152.82,243.38). This entry already exists so just add this custom one. Your complete definition will be something like this:
Your calls, if using FPDI, will now be something like this:
Note that even though the right size of CR80 is 54x86mm, it seems that the right settings require that these values be multiplied by 2.83 - tested. I hope this helps in code shortenings and quick reuse.