×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

FPDF Text Beside Thumbnails

FPDF Text Beside Thumbnails

FPDF Text Beside Thumbnails

(OP)
I created a function for creating a PDF from MySQL database entries and it is working but I am unable to put the thumbnail images onto the same line as the text. I understand that FPDF does not support this for some reason so I added an extension but it seems to do nothing more than it would without it. Is anyone familiar with FDPF who may know how to accomplish what I need?

CODE --> PHP

function Store2PDF($MemberOnly = FALSE) {
	require(RelativePath . '/internals/functions/fpdf/extensions.php');
	global $last_type;
	$DB = new clsDB();
	$LocalPath = SitePath("Viewers");

	if ($MemberOnly === FALSE) {
		$Where = " AND MembersOnly <> 1 ";
	} else {
		$Where = "";
	}

	$Query = "SELECT i.ID, CONCAT_WS('', 'http://www.livedomain.com/?ItemID=',i.ID) AS LinkID, 
			  CASE 
				WHEN (it.ItemType LIKE '%Member') THEN CONCAT(it.ItemType,'s Only') 
				WHEN (it.ItemType LIKE '%Other%') THEN REPLACE(it.ItemType, 'Other', 'Others') 
				WHEN (it.ItemType LIKE '%Current Issue%') THEN it.ItemType 
				ELSE CONCAT(it.ItemType, 's')
			  END AS ItemType, 
			  ImageID1 AS ImageID, Thumbnail, ItemName, PhotoCode, i.Description, Price, Discount, StockQuantity, MembersOnly
			  FROM ((items i 
			  LEFT JOIN coverart_assignments ca ON i.RecordID = ca.RecordingUsed) 
			  LEFT JOIN recordings r ON i.RecordID = r.ID) 
			  LEFT JOIN item_types it ON i.ItemType = it.ID
			  WHERE i.StockQuantity > 0 $Where
			  ORDER BY it.ItemType";
	$DB->query($Query);

	$pdf=new PDF_HTML('P','mm','Letter');
	$pdf->SetMargins(12,12,12);
	$pdf->SetAutoPageBreak(TRUE,0);
	$pdf->AliasNbPages();
	$pdf->AddPage();
	$pdf->SetFont('Arial','B',15);
	$pdf->MultiCell(0,20,"Store Items",0,'C',FALSE);

	while($DB->next_record())	:
		$ItemID = $DB->f("ID");
		$LinkID = $DB->f("LinkID");
		$ItemType = $DB->f("ItemType");
		$ItemName = $DB->f("ItemName");
		$RecordingImage = $DB->f("ImageID");
		$OtherImage = $DB->f("Thumbnail");
		$StockQuantity = $DB->f("StockQuantity");
		$Description = $DB->f("Description");
		$Discount = $DB->f("Discount");
		$MembersOnly = $DB->f("MembersOnly");
		$NetPrice = $DB->f("Price");

		if ($OtherImage) {
			$ImageID = $OtherImage;
			$ImageType = 9;
		} else {+
			$ImageID = $RecordingImage;
			$ImageType = 2;
		}

		$ImgFile = "http://".$_SERVER['HTTP_HOST'].$LocalPath."show_image.php?ID=$ImageID&Type=$ImageType";
		list($Imgwidth, $Imgheight, $ImgType, $attr) = getimagesize($ImgFile);

		switch ($ImgType) :
			case 1 : $MimeType = "GIF"; break;
			case 2 : $MimeType = "JPG"; break;
			case 3 : $MimeType = "PNG"; break;
			case 6 : $MimeType = "JPG"; break;
			default : $MimeType = "JPG";
		endswitch;

		$Imgwidth =($Imgwidth*25.4)/72;
		$Imgheight =($Imgheight*25.4)/72;
		
		$Replacements = array("Recordings", "<br>");
		$TextDesc = str_replace($Replacements, " ", $Description);

		$ItemPrice = (CCGetUserID() && CCGetGroupID() >= 2 && $NetPrice > 7.5 && $MembersOnly != 1 && $Discount) ? ($NetPrice) - ($NetPrice * $Discount) : $NetPrice;

		if ($ItemType != $last_type) {
			$pdf->SetFont('Arial','B',12);
			$pdf->Cell(0,8,$ItemType,1,0,'L');
			$pdf->Ln();
			$pdf->SetFont('Arial','I',10);
			$pdf->Cell(NULL,8,'Select title or image for more details and to purchase',1,0,'L');
			$last_type = $ItemType;
			$pdf->Ln();
		} else {
			$pdf->Ln();
		}

		pdf->Image($ImgFile,NULL,NULL,$Imgwidth,$Imgheight,$MimeType),1,NULL,'L',FALSE);
		$pdf->floatingImage($ImgFile, $Imgheight, $Imgwidth, $MimeType);
		$pdf->SetFont('Arial','',12);
		$pdf->Cell(0,8,$pdf->WriteHTML($ItemName.' - '.$TextDesc .' Regular price: $'.$ItemPrice),1,0,'L');

		$pdf->Ln(); 
	endwhile;
	$pdf->Ln();
 $pdf->Output();
} 

Here is the extension but as it was originally it was duplicating code in the above and was stretching the images out of proportion so I reworked it:

The original:

CODE --> PHP

class FloatPDF extends FPDF
{
    public function floatingImage($imgPath, $height) {
        list($w, $h) = getimagesize($imgPath);
        $ratio = $w / $h;
        $imgWidth = $height * $ratio;

        $this->Image($imgPath, $this->GetX(), $this->GetY());
        $this->x += $imgWidth;
    }
} 

My reworked version, as part of other extensions including WriteHTML():

CODE --> PHP

function floatingImage($imgPath, $imgHeight, $imgWidth, $MimeType) {
	$this->Image($imgPath,NULL,NULL, $imgWidth, $imgHeight, $MimeType);
	$this->GetX();
	$this->x += $imgWidth;
} 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close