Solved

How to get titles and images embedded in cells in fpdf or tcpdf

Posted on 2014-11-09
6
417 Views
Last Modified: 2014-11-13
Hi

I have looked at all of the example in fpdf and tcpdf and I cannot find a way to embed an image or a series of images inside a cell. For example the image below, I know the embedded images are fuzzy but the cell has a title with a coloured background and images inside. As far as I can see i need http://tracker.interpid.eu/projects/pdf-addons/wiki/Fpdf-table-examples for this?

Any help much appreciated as im finding writing a pdf is not as easy as one might hope
images-in-cells.PNG
more-images-in-cells.PNG
0
Comment
Question by:andieje
  • 3
  • 3
6 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40432451
Sorry I do not have enough time to work on this today, but I can tell you what has worked best for me, and that is absolute positioning.  It takes some experimentation so you might want to set up an easy-to-use test case so that you can adjust the X:Y coordinates and see quickly what changed.

Here is image positioning in TCPDF.
http://iconoun.com/demo/tcpdf_image_position.php
<?php // demo/tcpdf_image_position.php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');

// SYNTHESIZE THE PDF FILE NAME
$pdf_file_link    = 'storage/tcpdf_example.pdf';
$pdf_file_name    = getcwd() . DIRECTORY_SEPARATOR . $pdf_file_link;

// THE TCPDF CLASS AND CONFIGURATION
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');

// EXTEND THE TCPDF OBJECT
class PDF extends TCPDF
{
    // NULLIFY AUTOMATIC HEADER AND FOOTER
    public function Header() {}
    public function Footer() {}
}

echo "<br />Starting PDF creation" . PHP_EOL;

// INSTANTIATE THE OBJECT
$pdf = new PDF('P', 'mm', 'LETTER', true, 'UTF-8', false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(0,0,0,TRUE);
$pdf->SetAutoPageBreak(FALSE);
$pdf->setLanguageArray($l);
$pdf->SetFont('times', '', 13);
$pdf->setCellPaddings(0,0,0,0);
$pdf->setCellMargins(0,0,0,0);

// DO NOT DO THIS
// $pdf->setFillColor(255,255,224);


// CELL BORDERS, IF NEEDED
$bdr = '1TRBL';

// IF NO CELL BORDER IS NEEDED
$bdr = 0;

// ADD A PAGE
$pdf->AddPage('P', 'LETTER', TRUE);

// ADD AN IMAGE
// http://www.tcpdf.org/doc/classTCPDF.html#a714c2bee7d6b39d4d6d304540c761352
$img = 'images/ray_padded.png';

// I HAVE NO IDEA WHAT THIS IS DOING TO IMAGE SCALE - EXPERIMENT WITH IT
$pdf->setImageScale(1.53);

// GET THE IMAGE, I HOPE
$pdf->Image
( $img
, 0             // $x
, 0             // $y
, 0             // WIDTH
, 0             // HEIGHT
, 'PNG'         // TYPE
, '#'           // LINK URL
, 'T'           // SET POINTER TOP LEFT
, FALSE         // NO RESIZING
, 300           // DPI
, 'L'           // PALIGN
, FALSE         // ISMASK
, FALSE         // IMGMASK
, 0             // BORDER
, FALSE         // FIT TO BOX
, FALSE         // HIDDEN
, FALSE         // FIT ON PAGE
)
;

// ADD SOME TEXT ON TOP OF THE IMAGE
$pdf->Text
( 24            // $x,
, 24            // $y,
, 'HELLO WORLD'
, FALSE         // $fstroke           = false,
, FALSE         // $fclip             = false,
, TRUE          // $ffill             = true,
, $bdr          // $border            = whatever,
, 2             // $ln                = 0, 2=PUT CURSOR BELOW
, ''            // $align             = '', DEFAULT LEFT
, FALSE         // $fill              = false, CELL BACKGROUND
, ''            // $link              = '', NOT A LINK
, 0             // $stretch           = 0, NO TEXT STRETCH
, FALSE         // $ignore_min_height = false,
, 'A'           // $calign            = 'T', A=FONT TOP INSIDE CELL
, 'T'           // $valign            = 'M', T=VERTICAL ALIGN INSIDE CELL
, TRUE          // $rtloff            = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
)
;

// WRITE THE PDF FILE TO THE SERVER
echo "<br />Writing PDF\n";
$pdf->Output($pdf_file_name, 'F');

// PRESENT A CLICKABLE LINK SO WE CAN D/L AND PRINT THE PDF
echo '<br /><a target="my_PDF" href="' . $pdf_file_link . '"><strong>Print the PDF</strong></a>';

Open in new window

0
 

Author Comment

by:andieje
ID: 40432869
So are you saying to get images inside boxes or cells i should use absolute positioning to write them over the top of the box? I haven't been able to find anything that puts an image inside a box with a border except for that plugin I mention in the question. I would have hoped it would have been simpler to create the types of formatting I require. :)
0
 

Author Comment

by:andieje
ID: 40433274
In your example Ray is the text supposed to be on top of the image as its by the side. Just a small point
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40433819
The text appears to be at the side of the image, however it's actually on top of the image. The image is located here.  Check the dimensions.
http://iconoun.com/demo/images/ray_padded.png
0
 

Author Closing Comment

by:andieje
ID: 40441054
much obliged as always
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40441680
Thanks for the points -- best of luck with it!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now