dougaoxian8922 2019-02-26 20:43
浏览 336

TCPDF文本和图像定位

So I am trying to generate a PDF of car plates using TCPDF. Basically, the text and image should always be in the center of the box. I managed to to it by using the positioning. The format should be as follows:

AAA <img> BB CCC

Notice the larger space between BB and CCC. The space between the image at the center is the same between AA and <img> and <img> and BB.

Exhibit A

Now, my main issue is, I can get the following to display(This is perfectly aligned and spaced. Also notice larger space between BB and CCC compared to similar space between AAA <img> and <img> BB): AAA <img> BB CCC e.g enter image description here

Exhibit B

However, let's say I try (Wrong spacing, which needs to be spaced properly and centered in the box): AA <img> BB CCCC e.g enter image description here

Exhibit C

Here's another case where it goes wrong: enter image description here

The problem now is this: The spacing is not good, as there needs to be a single space between between AA and <img> and <img> and BB. There needs to be a larger(3 spaces) space between BB and CCCC.

Here is a link of an actual online generator that uses Javascript to display how the output should look like: https://brelok.de/#konfigurator

enter image description here

If you type in the text boxes, you will see why my PDF is not generating properly.

Here is the code I have tried and which gives the output Exhibit A:

$x = 80;
$y = 50;
$width = 51.8;
$height = 10.8;

$pdf->Rect($x, $y, $width, $height);
$pdf->cropMark($x, $y, 10, 10, 'TL');
$pdf->cropMark($x + $width, $y, 10, 10, 'TR');
$pdf->cropMark($x, $y + $height, 10, 10, 'BL');
$pdf->cropMark($x + $width, $y + $height, 10, 10, 'BR');

//Country_Image
$country_width = 5;
$country_height = 10.8;

//Images
$pdf->Image('../../images/country/desuthchland-icon.png', $x, $y, $country_width, $country_height, '', '', '', false, 300);

$left_text_x = 85;
$left_text_y = 50;

$middle_img_top_x = $left_text_x + 15.8;
$middle_img_top_y = $y + 0.6;

$middle_img_bottom_x = $left_text_x + 15.3;
$middle_img_bottom_y = $y + 5.1;

$middle_text_x = $middle_img_bottom_x + 4.7;
$middle_text_y = $left_text_y;

$right_text_x = $middle_text_x + 11.3;
$right_text_y = $left_text_y;

//Text
$pdf->Text($left_text_x, $left_text_y, 'AAA', false, false, true, 0, 0, '', false, '', 0, false, 'T', 'M', false ); //Left

$pdf->Image('../../images/bundesland/Baden-Wurttemberg.png', $middle_img_top_x, $middle_img_top_y, 4, 4, '', '', '', false, 300); //Top img mid
$pdf->Image('../../images/plakette/rose.png', $middle_img_bottom_x, $middle_img_bottom_y, 5, 5, '', '', '', false, 300); //Bottom img mid

$pdf->Text($middle_text_x, $middle_text_y, 'B', false, false, true, 0, 0, '', false, '', 0, false, 'T', 'M', false ); //Middle
$pdf->Text($right_text_x, $right_text_y, 'CCC', false, false, true, 0, 0, '', false, '', 0, false, 'T', 'M', false ); //Right

The code works for Exhibit A only. But for the rest, it just doesn't work as the text and spacing are not the same anymore. Also, I cannot center whole content inside the box except for Exhibit A. I think I am lacking some logic here and maybe did some hardcoding. But I have tried multiple ways around this and can't figure it out.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安装svn网络有问题怎么办
    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥15 latex怎么处理论文引理引用参考文献