$lang = 'pl'; if (isset($_GET['lang']) && $_GET['lang'] == 'en') { $lang = 'en'; } if ($lang != 'pl') { require_once(dirname(__FILE__).'/../lib/tcpdf/config/lang/eng.php'); } else { require_once(dirname(__FILE__).'/../lib/tcpdf/config/lang/pol.php'); } require_once(dirname(__FILE__).'/../lib/tcpdf/tcpdf.php'); function toUpper($str) { $str = strtoupper($str); $str = str_replace("ą", "Ą", $str); $str = str_replace("ć", "Ć", $str); $str = str_replace("ę", "Ę", $str); $str = str_replace("ł", "Ł", $str); $str = str_replace("ń", "Ń", $str); $str = str_replace("ó", "Ó", $str); $str = str_replace("ś", "Ś", $str); $str = str_replace("ź", "Ź", $str); $str = str_replace("ż", "Ż", $str); return $str; } class MyPdf extends TCPDF { public $thinLine = 0.25; public $normalLine = 0.35; public $thickLine = 0.75; public $blackColor = array(0x00, 0x00, 0x00); public $vsmallFontSize = 8; public $smallFontSize = 9.4; public $normalFontSize = 12; public $big1FontSize = 14; public $bigFontSize = 16; public function Header() { $this->setJPEGQuality(90); } public function Footer() { $this->SetY(-15); $this->SetFont(PDF_FONT_NAME_MAIN, 'I', 8); $this->Cell(0, 10, '', 0, false, 'C'); } public function drawText($str, $x = 0, $y = 0, $width = 0, $height = 10, $fontsize = 10, $fontstyle = '', $color = array(0, 0, 0), $bgColor = '', $align = 'L') { if (is_array($bgColor)) { $this->SetXY($x, $y); $this->setFillColor($bgColor[0], $bgColor[1], $bgColor[2]); } $this->SetXY($x, $y); $this->SetTextColor($color[0], $color[1], $color[2]); $this->SetFont("freeserif", $fontstyle, $fontsize); $this->Cell($width, $height, $str, 0, false, $align); } public function drawVerticalText($str, $x = 0, $y = 0, $width = 0, $height = 10, $fontsize = 10, $fontstyle = '', $color = array(0, 0, 0), $bgColor = '', $align = 'L') { $this->StartTransform(); $this->Rotate(-90, $x, $y); $this->drawText($str, $x, $y, $width, $height, $fontsize, $fontstyle, $color, $bgColor, $align); $this->StopTransform(); } public function drawRect($x, $y, $width, $height, $style = array()) { if (isset($style['bg'])) { $this->SetXY($x, $y); $this->setFillColor($style['bg'][0], $style['bg'][1], $style['bg'][2]); $this->Cell($width, $height, "", 0, false, "", true); } if (isset($style['fg']) && $style['fg'] == '') { return; } $this->Line($x, $y, $x+$width, $y, $style); $this->Line($x+$width, $y, $x + $width, $y + $height, $style); $this->Line($x+$width, $y+$height, $x, $y + $height, $style); $this->Line($x, $y+$height, $x, $y, $style); } public function drawCircle($x, $y, $r, $style = array()) { $this->Circle($x, $y, $r, 0, 360, '', $style); } public function drawTextField($x, $y, $width, $height, $style = array()) { $this->Line($x, $y, $x, $y+$height, $style); $this->Line($x, $y+$height, $x + $width, $y + $height, $style); $this->Line($x+$width, $y+$height, $x+$width, $y, $style); } } // create a PDF object $pdf = new MyPdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->setLanguageArray($l); // set document (meta) information $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle('Advertisement'); $pdf->SetSubject('Advertisement'); $pdf->SetKeywords('Advertisement'); $pdf->AddPage(); $margin = 10; $pdf->SetTopMargin($margin); $pdf->SetAutoPageBreak(true, $margin); // Formularz $x = 2*$margin; $y = $margin; $width = 170; $right = $x + $width; $lineHeight = 6; $header = 'Lorem ipsum dolor sit amet'; $msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at magna posuere neque euismod euismod.\n" . "Quisque ac commodo augue. Ut ut est id lectus varius feugiat ut eu nulla. Duis ac ornare arcu. Nullam\n" . "tincidunt arcu velit, et aliquet mi. Ut velit velit, consectetur quis posuere vitae, tincidunt a lectus.\n" . "Vestibulum sit amet quam ligula. Integer id ante vel dui mattis tincidunt ut vitae mauris. Curabitur non\n" . "tellus a tellus vestibulum congue vel in sem.\n"; $contact = "Nazwa ogłoszeniodawcy\n" . "tel. 123 456 789\n" . "adres ogłoszeniodawcy\n"; $bold = "" . "Dodatkowa uwaga napisana pogrubionym drukiem pod treścią ogłoszenia!\n" . "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at magna posuere neque euismod\n" . "euismod. Quisque ac commodo augue. Ut ut est id lectus\n"; $tickets = "Nazwa ogłoszeniodawcy\n" . "tel. 123 456 789\n" . "adres ogłoszeniodawcy"; if ($lang == 'en') { $header = 'Lorem ipsum dolor sit amet'; $msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at magna posuere neque euismod euismod.\n" . "Quisque ac commodo augue. Ut ut est id lectus varius feugiat ut eu nulla. Duis ac ornare arcu. Nullam\n" . "tincidunt arcu velit, et aliquet mi. Ut velit velit, consectetur quis posuere vitae, tincidunt a lectus.\n" . "Vestibulum sit amet quam ligula. Integer id ante vel dui mattis tincidunt ut vitae mauris. Curabitur non\n" . "tellus a tellus vestibulum congue vel in sem.\n"; $contact = "Issuer name\n" . "tel. 123 456 789\n" . "issuer address\n"; $bold = "" . "Extra caution note written in bold under the advertisement!\n" . "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at magna posuere neque euismod\n" . "euismod. Quisque ac commodo augue. Ut ut est id lectus\n"; $tickets = "Issuer name\n" . "tel. 123 456 789\n" . "issuer address"; } //$pdf->drawRect($x, $y, $width, 280, array('width' => $pdf->thinLine, 'dash' => 0, 'color' => $pdf->blackColor)); $pdf->drawText($header, $x, $y, 10, 10, $pdf->bigFontSize, 'B'); $y += 1.5*$lineHeight; //$pdf->drawText($subheader, $x + 10, $y, 10, 10, $pdf->bigFontSize, 'B'); $lines = explode("\n", $msg); for ($i = 0; $i < count($lines); $i++) { $pdf->drawText($lines[$i], $x, $y, 10, 10, $pdf->normalFontSize, ''); $y += $lineHeight; } $lines = explode("\n", $contact); for ($i = 0; $i < count($lines); $i++) { $pdf->drawText($lines[$i], $x, $y, 10, 10, $pdf->normalFontSize, ''); $y += $lineHeight; } $lines = explode("\n", $bold); for ($i = 0; $i < count($lines); $i++) { $pdf->drawText($lines[$i], $x, $y, 10, 10, $pdf->normalFontSize, 'b'); $y += $lineHeight; } $lines = explode("\n", $tickets); $x += 1.5*$lineHeight; $y += $lineHeight; for ($j = 0; $j < 9; $j++) { for ($i = count($lines)-1; $i >= 0; $i--) { $pdf->drawVerticalText($lines[$i], $x, $y, 10, 10, $pdf->smallFontSize, ''); $x += 0.75*$lineHeight; } $pdf->Line($x - $lineHeight/2, $y, $x - $lineHeight/2, $y+9*$lineHeight, array()); $x += $lineHeight; } $pdf->Output();