Problem med linje skrift i PDF ved hjælp af fpdf
Jeg har sidt og leget lidt med fpdf men jeg har nogle problemmer med linje skrift: http://www.kogebogen.a-mweb.dk/PDF.php?PDF=3Som det kan ses så hvær gang den laver et linje skift så er det at den tager mellemrummet med, hvordan kan det løses.
Det ser nemlig ikke ud til at være et problem her: http://www.fpdf.org/ --> Tutorials --> Multi-columns og Line breaks and colors.
Min kode (som er blevet temlig lag ses her)...
<?php
require('MySQL/PDF/fpdf.php');
class PDF extends FPDF
{
var $B;
var $I;
var $U;
var $HREF;
function Header()
{
global $title;
//Arial bold 15
$this->SetFont('Arial','B',15);
//Calculate width of title and position
$w=$this->GetStringWidth($title)+6;
$this->SetX((210-$w)/2);
//Colors of frame, background and text
$this->SetDrawColor(255,255,255);
$this->SetFillColor(255,255,255);
$this->SetTextColor(0,0,0);
//Thickness of frame (1 mm)
$this->SetLineWidth(1);
//Title
$this->Cell($w,9,$title,1,1,'C',true);
//Line break
$this->Ln(10);
}
function Footer()
{
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFont('Arial','I',8);
//Text color in gray
$this->SetTextColor(128);
//Page number
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
function PDF($orientation='P',$unit='mm',$format='A4')
{
//Call parent constructor
$this->FPDF($orientation,$unit,$format);
//Initialization
$this->B=0;
$this->I=0;
$this->U=0;
$this->HREF='';
}
function WriteHTML($html)
{
//HTML parser
$html=str_replace("\n",' ',$html);
$a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
foreach($a as $i=>$e)
{
if($i%2==0)
{
//Text
if($this->HREF)
$this->PutLink($this->HREF,$e);
else
$this->Write(5,$e);
}
else
{
//Tag
if($e[0]=='/')
$this->CloseTag(strtoupper(substr($e,1)));
else
{
//Extract attributes
$a2=explode(' ',$e);
$tag=strtoupper(array_shift($a2));
$attr=array();
foreach($a2 as $v)
{
if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3))
$attr[strtoupper($a3[1])]=$a3[2];
}
$this->OpenTag($tag,$attr);
}
}
}
}
function OpenTag($tag,$attr)
{
//Opening tag
if($tag=='B' || $tag=='I' || $tag=='U')
$this->SetStyle($tag,true);
if($tag=='A')
$this->HREF=$attr['HREF'];
if($tag=='BR')
$this->Ln(5);
}
function CloseTag($tag)
{
//Closing tag
if($tag=='B' || $tag=='I' || $tag=='U')
$this->SetStyle($tag,false);
if($tag=='A')
$this->HREF='';
}
function SetStyle($tag,$enable)
{
//Modify style and select corresponding font
$this->$tag+=($enable ? 1 : -1);
$style='';
foreach(array('B','I','U') as $s)
{
if($this->$s>0)
$style.=$s;
}
$this->SetFont('',$style);
}
function PutLink($URL,$txt)
{
//Put a hyperlink
$this->SetTextColor(0,0,255);
$this->SetStyle('U',true);
$this->Write(5,$txt,$URL);
$this->SetStyle('U',false);
$this->SetTextColor(0);
}
}
include "/rod/opret-forbindelse.php"; //opretter forbindelse
$query = mysql_query("SELECT * FROM kogebogen WHERE id='".$_GET["PDF"]."' ORDER BY navn"); //Sætter forsprøgsel
while($row = mysql_fetch_assoc($query)) //Lav en while der kører alle rækker igennem
{
//echo '<strong>Overskrift: </strong>' . $row['navn'] . '<br />';
//echo '<strong>Oprindelse: </strong>' . $row['oprindelse'] . '<br />';
//echo '<strong>Indsat den: </strong>' . $row['dato'] . '<br />';
include "MySQL/Plugin/stjerner_MySQL.php";
//<
if (preg_match("/^<img src=\"([^\"]+)\" width=\"75\" height=\"14\" alt=\"([^\"]+)\" \/> \(([0-9]) \/ ([0-9])\)$/", $snit, $star))
{
$stem = "(" . $star[3] . " / " . $star[4] . ")";
}
else
{
$stem = "(FEJL / FEJL)";
}
//echo '<strong>Billede sti: </strong>' . $regs[1] . '<br />';
//echo '<strong>Stemmmer: </strong>' . $stem . '<br />';
//echo '<strong>Biopatisk venlig:</strong> ' . $row['hm'] . '<br />';
if (preg_match("/^([^\.]+)\.(jpg|png|gif)$/", $row['billede'], $regs))
{
$thumbdestination = "Billeder/" . $regs[1] . "_thumb." . $regs[2];
$realdestination = "Billeder/" . $regs[1] . "_real." . $regs[2];
if (is_file("$thumbdestination") || is_file("$realdestination"))
{
//echo '<strong>Billede: </strong>'.$thumbdestination.'<br />';
}
else
{
$thumbdestination = "Billeder/Intet-billede.jpg";
//echo '<strong>Billede: </strong>'.$thumbdestination.'<br />';
}
}
else
{
$thumbdestination = "Billeder/Intet-billede.jpg";
//echo '<strong>Billede: </strong>'.$thumbdestination.'<br />';
}
//echo '<strong>Ingredienser: </strong>' . $row['ingredienser'] . '<br />';
//echo '<strong>Opskrift: </strong>' . $row['tekst'] . '<br />';
$ingredienser = $row['ingredienser'];
$opskrift = $row['tekst'];
$pdf=new PDF();
$title= $row['navn'];
$pdf->SetTitle($title);
$pdf->SetAuthor('A-Mweb.dk');
$pdf->AddPage(); //Tilføj en side til dokumentet
//Fakta
$pdf->SetFont("times", "B", 14); //Bestem fonten
$pdf->SetXY(20, 30); //Sæt position
$pdf->Write(0, "Fakta"); //Indsæt streng
//-Oprindelse
$pdf->SetFont("times", "B", 12); //Bestem fonten
$pdf->SetXY(20, 35); //Sæt position
$pdf->Write(0, "Oprindelse:"); //Indsæt streng
$pdf->SetFont("times", "", 12); //Bestem fonten
$pdf->SetXY(42, 35); //Sæt position
$pdf->Write(0, $row['oprindelse']); //Indsæt streng
//-Indsat den
$pdf->SetFont("times", "B", 12); //Bestem fonten
$pdf->SetXY(20, 40); //Sæt position
$pdf->Write(0, "Indsat den:"); //Indsæt streng
$pdf->SetFont("times", "", 12); //Bestem fonten
$pdf->SetXY(41, 40); //Sæt position
$pdf->Write(0, $row['dato']); //Indsæt streng
//-Indsat den
$pdf->SetFont("times", "B", 12); //Bestem fonten
$pdf->SetXY(20, 45); //Sæt position
$pdf->Write(0, "Bedømelse:"); //Indsæt streng
$pdf->Image($star[1], 43, 42.5, 21, 4); //Indsæt billede
$pdf->SetFont("times", "", 12); //Bestem fonten
$pdf->SetXY(64, 45); //Sæt position
$pdf->Write(0, $stem); //Indsæt streng
//-Indsat den
$pdf->SetFont("times", "B", 12); //Bestem fonten
$pdf->SetXY(20, 50); //Sæt position
$pdf->Write(0, "Biopatisk venlig:"); //Indsæt streng
$pdf->SetFont("times", "", 12); //Bestem fonten
$pdf->SetXY(51, 50); //Sæt position
$pdf->Write(0, $row['hm']); //Indsæt streng
//Billede
$pdf->Image($thumbdestination, 140, 30, 45, 45); //Indsæt billede
//Ingredienser
$pdf->SetFont("times", "B", 14); //Bestem fonten
$pdf->SetXY(20, 88); //Sæt position
$pdf->Write(0, "Ingredienser"); //Indsæt streng
//-Ingredienser
$pdf->SetXY(20, 93); //Sæt position
$pdf->SetFont("times", "", 12); //Bestem fonten
$pdf->SetLeftMargin(19);
$pdf->SetRightMargin(120);
$pdf->WriteHTML($ingredienser);
//Opskrift
$pdf->SetFont("times", "B", 14); //Bestem fonten
$pdf->SetXY(70, 88); //Sæt position
$pdf->SetLeftMargin(85);
$pdf->SetRightMargin(19);
$pdf->Write(0, "Opskrift"); //Indsæt streng
//-Opskrift
$pdf->SetXY(86, 93); //Sæt position
$pdf->SetFont("times", "", 12); //Bestem fonten
$pdf->SetLeftMargin(85);
$pdf->SetRightMargin(19);
$pdf->WriteHTML($opskrift);
$pdf->Output();
}
?>