如何用fpdf或tcpdf或其他格式制作名片?当我有 jpg 背景并且文本需要重叠时?

发布于 2024-11-19 02:21:51 字数 173 浏览 6 评论 0原文

我有一张用于名片布局的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

初熏 2024-11-26 02:21:51

使用 TCPDF,您可以绝对定位元素,因此您可以执行类似的操作

$pdf = new TCPDF('L', 'mm', 'A4'); //Or whatever your required settings are

//Basic setup
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

$pdf->AddPage();

$pdf->Image('src', x, y); //Where x and y are the offset (probably 0, 0)
$pdf->writeHTMLCell(w, h, x, y, 'html') //Again where x and y are offset

$pdf->Output('filename.pdf', 'D'); //To force download

TCPDF 在线文档不是很好,但示例有很大帮助

Using TCPDF you can position elements absolutely as it were, so you could do something like

$pdf = new TCPDF('L', 'mm', 'A4'); //Or whatever your required settings are

//Basic setup
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

$pdf->AddPage();

$pdf->Image('src', x, y); //Where x and y are the offset (probably 0, 0)
$pdf->writeHTMLCell(w, h, x, y, 'html') //Again where x and y are offset

$pdf->Output('filename.pdf', 'D'); //To force download

The TCPDF online documentation isn't great, but the examples help a lot http://www.tcpdf.org/examples.php

顾铮苏瑾 2024-11-26 02:21:51

您特别询问了如何创建名片大小的文档,因此您应该使用:

//Sets document size to a 5.9cm x 9.8cm landscape oriented page    
$pdf = new TCPDF('L', 'mm', array(59,98)); 

该文档在此处提供了预定义页面大小的列表:http://www.tcpdf.org/doc/classTCPDF.html#a087d4df77e60b7054e97804069ed32c5

You specifically asked about creating a business card sized document, so you should use:

//Sets document size to a 5.9cm x 9.8cm landscape oriented page    
$pdf = new TCPDF('L', 'mm', array(59,98)); 

The documentation gives a list of pre-defined page sizes here: http://www.tcpdf.org/doc/classTCPDF.html#a087d4df77e60b7054e97804069ed32c5

一身仙ぐ女味 2024-11-26 02:21:51

例子 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).

第几種人 2024-11-26 02:21:51

要在 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.

你曾走过我的故事 2024-11-26 02:21:51

有一个实现FPDF的库,称为FPDI。要创建自定义纸张尺寸,例如名片,通常使用尺寸为 54mm x 86mmCR80,您可以直接将此尺寸添加到 fpdf 的类构造函数中.php位于stdPageSizes,如下所示:'cr80'=>array(152.82,243.38)。此条目已存在,因此只需添加此自定义条目即可。您的完整定义将如下所示:

$this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), 'letter'=>array(612,792), 'legal'=>array(612,1008), 'cr80'=>array(152.82,243.38));

如果使用 FPDI,您的调用现在将如下所示:

$pdf = new Fpdi();
$pdf->AddPage('L','cr80');   //note our custom name 

请注意,即使 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:

$this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), 'letter'=>array(612,792), 'legal'=>array(612,1008), 'cr80'=>array(152.82,243.38));

Your calls, if using FPDI, will now be something like this:

$pdf = new Fpdi();
$pdf->AddPage('L','cr80');   //note our custom name 

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文