?
Solved

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

Posted on 2014-11-09
6
Medium Priority
?
639 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
LVL 111

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 111

Expert Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

770 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