【问题标题】:Image and text formating in TCPDFTCPDF 中的图像和文本格式
【发布时间】:2014-11-27 18:19:06
【问题描述】:

使用 TCPDF 在 PDF 中生成我的 HTML。但是文本格式没有出现,PDF 中没有图像。 什么问题。 ?

PHP 代码:

require_once('tcpdf/tcpdf.php');

// 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);
// set default header data
// $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 021', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// set font
$pdf->SetFont('helvetica', '', 9);

// add a page
$pdf->AddPage();
// create some HTML content

/*---------*/
$html  = 'HTML Content Which is pasted under the HTML head in this Question'; 

// output the HTML content
$pdf->writeHTML($html, true, 0, true, 0);

// reset pointer to the last page
$pdf->lastPage();
ob_end_clean();
//Close and output PDF document
$pdf->Output('rec_users.pdf','D');

HTML

<table>
        <tbody>
            <tr>
                <td style='background:red'>&nbsp;</td>

                <td><img alt='' height='129' src=
                'demo-300x300.jpg'
                width='300'></td>

                <td>
                    <div class='header'>
                        <div class='right'>
                            <p>1790 lee Travino</p>

                            <p>CL paso xyz</p>

                            <p>T-123456789</p>

                            <p>F-45678903</p>

                            <p>wwww.xyz.com</p>
                        </div>
                    </div>
                </td>
            </tr>

            <tr>
                <td style='background:red'>&nbsp;</td>

                <td>
                    <div class='letter_section'>
                        <h1>Service Agreement</h1>

                        <p style=
                        'color: #5d605f; font-family: arial; font-size: 20px; margin: 40px 0;'>
                        December 30,2013</p>

                        <h3 class='address'>Ms.jenifer Carter</h3>

                        <h3 class='address'>Ms.jenifer Carter</h3>

                        <h3 class='address'>Ms.jenifer Carter</h3>

                        <h3 class='address'>Ms.jenifer Carter</h3>

                        <h3 class='address'>Ms.jenifer Carter</h3>
                    </div>
                </td>

                <td>&nbsp;</td>
            </tr>

            <tr>
                <td style='background:red'>&nbsp;</td>

                <td colspan='2'>
                    <p>lorem ipum is the dolor sit amet lorem ipum is the dolor
                    sit amet lorem ipum is the dolor sit ametlorem ipum is the
                    dolor sit ametlorem ipum is the dolor sit amet lorem ipum
                    is the dolor sit amet lorem ipum is the dolor sit amet</p>

                    <p>lorem ipum is the dolor sit amet lorem ipum is the dolor
                    sit amet lorem ipum is the dolor sit ametlorem ipum is the
                    dolor sit ametlorem ipum is the dolor sit amet lorem ipum
                    is the dolor sit ametlorem ipum is the dolor sit amet lorem
                    ipum is the dolor sit amet lorem ipum is the dolor sit
                    ametlorem ipum is the dolor sit ametlorem ipum is the dolor
                    sit amet lorem ipum is the dolor sit amet</p>
                </td>
            </tr>
        </tbody>
    </table>

所需输出:

【问题讨论】:

  • 所以您展示了代码和所需的输出,您仍然需要向我们展示您在输出中实际得到的内容,以便我们知道要查看的内容。

标签: php pdf-generation tcpdf


【解决方案1】:

1)检查图像路径..确认给定路径内的图像。 2)要打印图像,请参考以下代码

$pdf->图像($image_path.'imageName.jpg',$x_im+32.8,$y_im+32,$w_im,$h_im);

【讨论】:

    猜你喜欢
    • 2023-03-06
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    相关资源
    最近更新 更多