Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FPDF Text Beside Thumbnails

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
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?

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('', '[URL unfurl="true"]http://www.livedomain.com/?ItemID=',i.ID)[/URL] 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 = "[URL unfurl="true"]http://".$_SERVER[/URL]['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:

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():

PHP:
function floatingImage($imgPath, $imgHeight, $imgWidth, $MimeType) {
	$this->Image($imgPath,NULL,NULL, $imgWidth, $imgHeight, $MimeType);
	$this->GetX();
	$this->x += $imgWidth;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top