EzDevInfo.com

TCPDF

Official clone of PHP library to generate PDF documents and barcodes TCPDF tcpdf: open source php class for generating pdf documents

How to calculate the height of a MultiCell/writeHTMLCell in TCPDF?

I try to create a PDF with multiple pages and need to calculate the height of each individual element (MultiCell) in advance to prepare for a page break. According to the documentation there are a couple of functions out there like GetCharWidth/GetStringWidth to support me in doing it on my own, but besides a potential performance lost I probably will not do it the right anyway. Suggestions to achieve my goal in a more elegant way?

Reference: TCPDF


Source: (StackOverflow)

TCPDF ERROR: Can't open image file: /var/www/html/tcpdf/cache/

I have a website that is generating a PDF file based from data.

I tried it in a free webhost and it is ok but when i upload it to my server i get this error:

TCPDF ERROR: Can't open image file: /var/www/html/tcpdf/cache/mska_1d34cb1ba2c1951624fbccb7556c6d1d

in the cache folder the mska_1d34cb1ba2c1951624fbccb7556c6d1d doesnt exist in the folder.


Source: (StackOverflow)

Advertisements

TCPDF ERROR: [Image] Unable to get image

I'm using TCPDF with Drupal's print module to generate PDF of articles, & ending up with following error message when I click the link to generate PDF:

TCPDF ERROR: [Image] Unable to get image: http://localhost/pathToDrupal/themes/bartik/logo.png

The Image exists in the location specified. I tried applying:

allow_url_fopen = On;
allow_url_include = On;

in php.ini but that could not resolve the problem.

Please care to help :(


Source: (StackOverflow)

How to implement custom fonts in TCPDF

In TCPDF, there are only a few fonts to choose from, to create pdf files. I want to set Tahoma as my pdf font. How can I include Tahoma in TCPDF??


Source: (StackOverflow)

Changing or eliminating Header & Footer in TCPDF

AddPage() in tcpdf automatically calls Header and Footer. How do I eliminate/override this?


Source: (StackOverflow)

TCPDF not render all CSS properties

I try to make a PDF writing CSS and HTML but my CSS doesn't appear in my PDF. The only thing considered is the font-size and font-color.

I give you the code (sorry, it's a little long...)

$config = sfTCPDFPluginConfigHandler::loadConfig('my_config');

    $doc_title    = "Fiche Logement";

    $html = <<<EOF
<style>
        .informations {
            padding: 10px;
            margin: 10px;
            border: 1px dotted black;}
        .informations table {
            margin-top: 10px;}
        #modif {
            margin: 20px;
            text-align: left;
            float: right;}
        #modif th {
            padding-left: 10px;}
        #modif td {
            padding-left: 10px;}
        #adresse {
            width: 307px;
            float: left;}
        #reservataire {
            width: 307px;
            float: right;}
        #intergen {
            width: 307px;
            float: right;}
        #infos {
            width: 290px;
            float: left;}
        #handicap {
            padding-bottom: 12px;
            width: 324px;
            float: right;}
        #charges {
            margin-bottom: 20px;
            width: 307px;
            float: left;}
        #loyer {
            width: 307px;
            float: right;}
        #commentaires {
            clear: both;}
        h2 {
            font-variant: small-caps;
            text-align: center;
            font-size: 19px;
            font-weight: bold;
            padding: 0px 0px 2px 5px;
            margin: 15px 0px 20px 0px;
            color: #000000;
            border-top: 1px dotted black;
            border-bottom: 1px dotted black;}

        h3 {
            width: 250px;
            font-variant: small-caps;
            font-size: 15px;
            font-weight: bold;
            padding: 0px 0px 0px 5px;
            margin: 0px;
            color: #225D6D;
            border-top: 1px dotted black;
            border-bottom: 1px dotted black;}
</style>


            <div id='intergen' class='informations'>
                <h3>Intergénérationnel</h3>
                <table>
                    <tr>
                        <th>Intergénérationnel :</th> <td><?php echo \$logement->getIntergen() ?></td>
                    </tr>
                </table>
            </div>

            <div id='infos' class='informations'>
                <h3>Informations logement</h3>
                <table>
                    <tr>
                        <th>Bâtiment :</th> <td><?php echo \$logement->Parclogement->getBatiment() ?></td>
                    </tr>
                    <tr>
                        <th>Taille :</th> <td><?php echo \$logement->getTaille() ?></td>
                    </tr>
                    <tr>
                        <th>Type :</th> <td><?php echo \$logement->getTypelog() ?></td>
                    </tr>
                    <tr>
                        <th>Surface habitable :</th> <td><?php if(\$logement->getSurfacehab() == 0){ echo 'Non Spécifié';} else {echo \$logement->getSurfacehab(). " m²";} ?></td>
                    </tr>
                    <tr>
                        <th>Chauffage :</th> <td><?php echo \$logement->getChauffage() ?></td>
                    </tr>
                    <tr>
                        <th>Ascenseur :</th> <td><?php echo \$logement->getAscenseur() ?></td>
                    </tr>
                </table>
            </div>

            <div id='handicap' class='informations'>
                <h3>Infrastructures handicapés</h3>
                <table>
                    <tr>
                        <th>Immeuble accessible :</th> <td><?php echo \$logement->getAccessibl() ?></td>
                    </tr>
                    <tr>
                        <th>Ascenceur accessible :</th> <td><?php echo \$logement->getAscenseuracc() ?></td>
                    </tr>
                    <tr>
                        <th>Logement adaptable :</th> <td><?php echo \$logement->getAdaptable() ?></td>
                    </tr>
                    <tr>
                        <th>Logement adapté :</th> <td><?php echo \$logement->getAdapte() ?></td>
                    </tr>
                </table>
            </div>

EOF;

    //create new PDF document (document units are set by default to millimeters)
    $pdf = new sfTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);

    // set document information
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor(PDF_AUTHOR);
    $pdf->SetTitle($doc_title);

    //set default header data
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

    //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 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);

    // Fixe la taille de la page
    $pdf->SetDisplayMode(90);

    //initialize document
    $pdf->SetFont('helvetica', '', 10);
    $pdf->AddPage();

    // output some HTML code


    $pdf->writeHTML($html , true, false, true, false, '');

    //reset pointer to the last page
    $pdf->lastPage();  

    // Close and output PDF document
    $pdf->Output('fichelogement.pdf', 'I');

    // Stop symfony process
    throw new sfStopException();

Source: (StackOverflow)

Creating PDF with tcpdf shows blank on iphone

I am using tcpdf to produce PDF's from HTML. Everything is working fine and when I view the PDF on my computer I can see it just fine, but for some reason when I look at the PDF on my iPhone it shows up blank. All I can see are the borders I created that contain values in them but there are no values showing.

Here is my code

require_once('/tcpdf/tcpdf/config/lang/eng.php');
require_once('/tcpdf/tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$pdf->SetFont('dejavusans', '', 10);
$pdf->AddPage();
$html = file_get_contents('http://www.website.com/invoice.php?invoice_id='.$invoice_id);
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
$pdf->Output('/html/admin/emailattachements/invoice.pdf', 'F');

In that last line. I copy the PDF to that directory when I grab it later with an email script and sends it off to a customer.

Blank PDF

Edit: SOLVED

I discovered it was the font I was using to produce the PDF. iPhone's can't read dejavusans :) I changed it to 'times' and it works fine

Edit: Update

Since this article I have had to create many more PDF's with tcpdf and while I can't really explain why some fonts were not working while others where I recently applied some of the suggestions over at http://www.tcpdf.org/fonts.php and applied

$fontname = $pdf->addTTFfont('/path-to-font/DejaVuSans.ttf', 'TrueTypeUnicode', '', 32);

By adding a font manually and setting the font file path and uploading the file manually I was able to get existing font's that did not work and actually get them to work.


Source: (StackOverflow)

Manual Page Break in TCPDF

I am using TCPDF to generate the PDF in one of my projects. I simply create a HTML file and give it to the TCPDF to handle the PDF generation. But now I have some HTML where multiple certificates are added one after the other and I want to have a page break in it. Page Break should be decided by HTML i.e. I want to know if there is any identifier in HTML which TCPDF understands and then accordingly adds a page break into the generated PDF.

How could I do this?


Source: (StackOverflow)

TCPDF: HTML table and page breaks

I am creating a large HTML table and I have problem with page breaks as you can see in the following image: http://i.stack.imgur.com/HB0yL.jpg Is there a method settle down the problem automatically? Or what is the way to do it?


Source: (StackOverflow)

Attach footer at very bottom to every page in tcpdf

I need to attach footer at the very bottom of every page. I am using tcpdf for generating pdf's. i tried many solution on google but did not found any luck. My current framework is yii and i am using tcpdf extension.


Source: (StackOverflow)

How to position the text next to images properly in PDF?

I'm using PHP, Smarty and TCPDF library to generate the PDF copy of a document. The document contains images of mathematical expressions from WIRIS editor along with the text content.

I'm having a problem positioning the text coming next to the expression image properly.

I tried every thing in CSS float properties, but nothing happened. I'm attaching the screen shot of exactly what I want with this mail.

This is the smarty template code to print the question and its options:

{foreach from=$question_data item=qstn_ans key=key}
    <table border="0" width="100%" cellpadding="2" cellspacing="0">
        <tr>
            <td valign="top" >{if $qstn_ans.question_directions}{$qstn_ans.question_directions}<br /><b>Question {$que_seq_no} : </b>{/if}{$qstn_ans.question_text}</td>
        </tr>
        {if $qstn_ans.question_file}
        <tr>
            <td><img src="{$ques_thum_image_path}{$qstn_ans.question_id}_{$qstn_ans.question_file}" /></td>
        </tr>
        {/if}
        {if $qstn_ans.question_has_sub_ques==0}
            {if $qstn_ans.answer}
                {foreach from=$qstn_ans.answer item=ans key=ans_no}
                    <td valign="top" >
                        {if $ans.answer_is_right==1}{assign var='correct_ans' value=$ans_no+1}{/if}
                            <b>{$ans_no+1}.</b>&nbsp;&nbsp;{if $ans.answer_text!=''}{$ans.answer_text}{/if}
                            {if $ans.answer_file!=''}<img src="{$ans_thumb_img_path}{$ans.answer_id}_{$ans.answer_file}" />{/if}
                     </td>
                </tr>
                {/foreach}
        <tr>
            <td></td>
        </tr>
    </table>
{/foreach}

This code snippet may contain some errors, as I pasted it randomly without checking the loop and brackets completion, but that's not the issue here.

The only important part from this code are the lines to print the question text and question image if it is present.

I researched for the right solution, but couldn't get the desired one. Can anyone help me out.

Screenshot


Source: (StackOverflow)

PHP / TCPDF: Template Bug?

I have been using TCPDF for sometime. It's simple to use, outputs low size PDF and is under active development. Following is the code for a page which should only have Hello World and a footer showing page number. However I get an additional Horizontal Line at the top of the page. http://yfrog.com/2tapdfj It's bugging me. How do i get rid of it?

<?php
require_once('config/lang/eng.php');
require_once('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

// 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);//if i comment this out the lower line disappears

//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
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

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

// add a page
$pdf->AddPage();


// define some HTML content with style
$html = <<<EOF
Hello World
EOF;

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

// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_061.pdf', 'I');

?>

Solution:

$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);

http://stackoverflow.com/questions/2217132/changing-or-eliminating-header-footer-in-tcpdf


Source: (StackOverflow)

tcpdf edit footer

How do I edit a footer using tcpdf? I want to add current date & time at the footer. Please help.


Source: (StackOverflow)

Print multipage PDF on different printer-trays

I am generating a PDF by PHP with FPDF. This works well.

Now what I want:
From a multipage PDF all pages expect the last one have to print with paper from tray1 and the last page from tray2.

Now the Question:
How is this possible? Is this a Acrobat Reader issue? Can it be done with JavaScript in PDF?


Source: (StackOverflow)

Hindi language not displaying correctly on tcpdf

i have created below code for displaying hindi text using arial unicode font in tcpdf

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

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


//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

$pdf->addTTFfont('fonts/ARIALUNI.TTF', 'TrueTypeUnicode', '', 32);
$pdf->SetFont('arialuni', '', 10,'false');

$txt = 'hindi text with arial unicode समृध्दि';

$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_038.pdf', 'I');

but it is not getting displayed properly

But in php it showing correct text.

Please tell me if there is anything wrong.


Source: (StackOverflow)