Example #1
8
 public function testPdfOutput()
 {
     // create new PDF document
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Nicola Asuni');
     $pdf->SetTitle('TCPDF Example 012');
     $pdf->SetSubject('TCPDF Tutorial');
     $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     // disable header and footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // set some language-dependent strings (optional)
     $pdf->setLanguageArray($this->langSettings);
     // ---------------------------------------------------------
     // set font
     $pdf->SetFont('helvetica', '', 10);
     // add a page
     $pdf->AddPage();
     $style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,20,5,10', 'phase' => 10, 'color' => array(255, 0, 0));
     $style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0));
     $style3 = array('width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => array(255, 0, 0));
     $style4 = array('L' => 0, 'T' => array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => '20,10', 'phase' => 10, 'color' => array(100, 100, 255)), 'R' => array('width' => 0.5, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => array(50, 50, 127)), 'B' => array('width' => 0.75, 'cap' => 'square', 'join' => 'miter', 'dash' => '30,10,5,10'));
     $style5 = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128));
     $style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,10', 'color' => array(0, 128, 0));
     $style7 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 128, 0));
     // Line
     $pdf->Text(5, 4, 'Line examples');
     $pdf->Line(5, 10, 80, 30, $style);
     $pdf->Line(5, 10, 5, 30, $style2);
     $pdf->Line(5, 10, 80, 10, $style3);
     // Rect
     $pdf->Text(100, 4, 'Rectangle examples');
     $pdf->Rect(100, 10, 40, 20, 'DF', $style4, array(220, 220, 200));
     $pdf->Rect(145, 10, 40, 20, 'D', array('all' => $style3));
     // Curve
     $pdf->Text(5, 34, 'Curve examples');
     $pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, null, $style6);
     $pdf->Curve(80, 40, 70, 75, 150, 45, 100, 75, 'F', $style6);
     $pdf->Curve(140, 40, 150, 55, 180, 45, 200, 75, 'DF', $style6, array(200, 220, 200));
     // Circle and ellipse
     $pdf->Text(5, 79, 'Circle and ellipse examples');
     $pdf->SetLineStyle($style5);
     $pdf->Circle(25, 105, 20);
     $pdf->Circle(25, 105, 10, 90, 180, null, $style6);
     $pdf->Circle(25, 105, 10, 270, 360, 'F');
     $pdf->Circle(25, 105, 10, 270, 360, 'C', $style6);
     $pdf->SetLineStyle($style5);
     $pdf->Ellipse(100, 103, 40, 20);
     $pdf->Ellipse(100, 105, 20, 10, 0, 90, 180, null, $style6);
     $pdf->Ellipse(100, 105, 20, 10, 0, 270, 360, 'DF', $style6);
     $pdf->SetLineStyle($style5);
     $pdf->Ellipse(175, 103, 30, 15, 45);
     $pdf->Ellipse(175, 105, 15, 7.5, 45, 90, 180, null, $style6);
     $pdf->Ellipse(175, 105, 15, 7.5, 45, 270, 360, 'F', $style6, array(220, 200, 200));
     // Polygon
     $pdf->Text(5, 129, 'Polygon examples');
     $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
     $pdf->Polygon(array(5, 135, 45, 135, 15, 165));
     $pdf->Polygon(array(60, 135, 80, 135, 80, 155, 70, 165, 50, 155), 'DF', array($style6, $style7, $style7, 0, $style6), array(220, 200, 200));
     $pdf->Polygon(array(120, 135, 140, 135, 150, 155, 110, 155), 'D', array($style6, 0, $style7, $style6));
     $pdf->Polygon(array(160, 135, 190, 155, 170, 155, 200, 160, 160, 165), 'DF', array('all' => $style6), array(220, 220, 220));
     // Polygonal Line
     $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 164)));
     $pdf->PolyLine(array(80, 165, 90, 160, 100, 165, 110, 160, 120, 165, 130, 160, 140, 165), 'D', array(), array());
     // Regular polygon
     $pdf->Text(5, 169, 'Regular polygon examples');
     $pdf->SetLineStyle($style5);
     $pdf->RegularPolygon(20, 190, 15, 6, 0, 1, 'F');
     $pdf->RegularPolygon(55, 190, 15, 6);
     $pdf->RegularPolygon(55, 190, 10, 6, 45, 0, 'DF', array($style6, 0, $style7, 0, $style7, $style7));
     $pdf->RegularPolygon(90, 190, 15, 3, 0, 1, 'DF', array('all' => $style5), array(200, 220, 200), 'F', array(255, 200, 200));
     $pdf->RegularPolygon(125, 190, 15, 4, 30, 1, null, array('all' => $style5), null, null, $style6);
     $pdf->RegularPolygon(160, 190, 15, 10);
     // Star polygon
     $pdf->Text(5, 209, 'Star polygon examples');
     $pdf->SetLineStyle($style5);
     $pdf->StarPolygon(20, 230, 15, 20, 3, 0, 1, 'F');
     $pdf->StarPolygon(55, 230, 15, 12, 5);
     $pdf->StarPolygon(55, 230, 7, 12, 5, 45, 0, 'DF', array('all' => $style7), array(220, 220, 200), 'F', array(255, 200, 200));
     $pdf->StarPolygon(90, 230, 15, 20, 6, 0, 1, 'DF', array('all' => $style5), array(220, 220, 200), 'F', array(255, 200, 200));
     $pdf->StarPolygon(125, 230, 15, 5, 2, 30, 1, null, array('all' => $style5), null, null, $style6);
     $pdf->StarPolygon(160, 230, 15, 10, 3);
     $pdf->StarPolygon(160, 230, 7, 50, 26);
     // Rounded rectangle
     $pdf->Text(5, 249, 'Rounded rectangle examples');
     $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
     $pdf->RoundedRect(5, 255, 40, 30, 3.5, '1111', 'DF');
     $pdf->RoundedRect(50, 255, 40, 30, 6.5, '1000');
     $pdf->RoundedRect(95, 255, 40, 30, 10.0, '1111', null, $style6);
     $pdf->RoundedRect(140, 255, 40, 30, 8.0, '0101', 'DF', $style6, array(200, 200, 200));
     // Arrows
     $pdf->Text(185, 249, 'Arrows');
     $pdf->SetLineStyle($style5);
     $pdf->SetFillColor(255, 0, 0);
     $pdf->Arrow(200, 280, 185, 266, 0, 5, 15);
     $pdf->Arrow(200, 280, 190, 263, 1, 5, 15);
     $pdf->Arrow(200, 280, 195, 261, 2, 5, 15);
     $pdf->Arrow(200, 280, 200, 260, 3, 5, 15);
     // - . - . - . - . - . - . - . - . - . - . - . - . - . - . -
     // ellipse
     // add a page
     $pdf->AddPage();
     $pdf->Cell(0, 0, 'Arc of Ellipse');
     // center of ellipse
     $xc = 100;
     $yc = 100;
     // X Y axis
     $pdf->SetDrawColor(200, 200, 200);
     $pdf->Line($xc - 50, $yc, $xc + 50, $yc);
     $pdf->Line($xc, $yc - 50, $xc, $yc + 50);
     // ellipse axis
     $pdf->SetDrawColor(200, 220, 255);
     $pdf->Line($xc - 50, $yc - 50, $xc + 50, $yc + 50);
     $pdf->Line($xc - 50, $yc + 50, $xc + 50, $yc - 50);
     // ellipse
     $pdf->SetDrawColor(200, 255, 200);
     $pdf->Ellipse($xc, $yc, 30, 15, 45, 0, 360, 'D', array(), array(), 2);
     // ellipse arc
     $pdf->SetDrawColor(255, 0, 0);
     $pdf->Ellipse($xc, $yc, 30, 15, 45, 45, 90, 'D', array(), array(), 2);
     $this->comparePdfs($pdf);
 }
Example #2
2
 public function testPdfOutput()
 {
     // create new PDF document
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Nicola Asuni');
     $pdf->SetTitle('TCPDF Example 027');
     $pdf->SetSubject('TCPDF Tutorial');
     $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     // set default header data
     $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 027', PDF_HEADER_STRING);
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // set some language-dependent strings (optional)
     $pdf->setLanguageArray($this->langSettings);
     // ---------------------------------------------------------
     // set a barcode on the page footer
     $pdf->setBarcode('2015-06-18 09:12:27');
     // set font
     $pdf->SetFont('helvetica', '', 11);
     // add a page
     $pdf->AddPage();
     // print a message
     $txt = "You can also export 1D barcodes in other formats (PNG, SVG, HTML). Check the examples inside the barcodes directory.\n";
     $pdf->MultiCell(70, 50, $txt, 0, 'J', false, 1, 125, 30, true, 0, false, true, 0, 'T', false);
     $pdf->SetY(30);
     // -----------------------------------------------------------------------------
     $pdf->SetFont('helvetica', '', 10);
     // define barcode style
     $style = array('position' => '', 'align' => 'C', 'stretch' => false, 'fitwidth' => true, 'cellfitalign' => '', 'border' => true, 'hpadding' => 'auto', 'vpadding' => 'auto', 'fgcolor' => array(0, 0, 0), 'bgcolor' => false, 'text' => true, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4);
     // PRINT VARIOUS 1D BARCODES
     // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
     $pdf->Cell(0, 0, 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9', 0, 1);
     $pdf->write1DBarcode('CODE 39', 'C39', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // CODE 39 + CHECKSUM
     $pdf->Cell(0, 0, 'CODE 39 + CHECKSUM', 0, 1);
     $pdf->write1DBarcode('CODE 39 +', 'C39+', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // CODE 39 EXTENDED
     $pdf->Cell(0, 0, 'CODE 39 EXTENDED', 0, 1);
     $pdf->write1DBarcode('CODE 39 E', 'C39E', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // CODE 39 EXTENDED + CHECKSUM
     $pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
     $pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // CODE 93 - USS-93
     $pdf->Cell(0, 0, 'CODE 93 - USS-93', 0, 1);
     $pdf->write1DBarcode('TEST93', 'C93', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // Standard 2 of 5
     $pdf->Cell(0, 0, 'Standard 2 of 5', 0, 1);
     $pdf->write1DBarcode('1234567', 'S25', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // Standard 2 of 5 + CHECKSUM
     $pdf->Cell(0, 0, 'Standard 2 of 5 + CHECKSUM', 0, 1);
     $pdf->write1DBarcode('1234567', 'S25+', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // Interleaved 2 of 5
     $pdf->Cell(0, 0, 'Interleaved 2 of 5', 0, 1);
     $pdf->write1DBarcode('1234567', 'I25', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // Interleaved 2 of 5 + CHECKSUM
     $pdf->Cell(0, 0, 'Interleaved 2 of 5 + CHECKSUM', 0, 1);
     $pdf->write1DBarcode('1234567', 'I25+', '', '', '', 18, 0.4, $style, 'N');
     // add a page ----------
     $pdf->AddPage();
     // CODE 128 AUTO
     $pdf->Cell(0, 0, 'CODE 128 AUTO', 0, 1);
     $pdf->write1DBarcode('CODE 128 AUTO', 'C128', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // CODE 128 A
     $pdf->Cell(0, 0, 'CODE 128 A', 0, 1);
     $pdf->write1DBarcode('CODE 128 A', 'C128A', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // CODE 128 B
     $pdf->Cell(0, 0, 'CODE 128 B', 0, 1);
     $pdf->write1DBarcode('CODE 128 B', 'C128B', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // CODE 128 C
     $pdf->Cell(0, 0, 'CODE 128 C', 0, 1);
     $pdf->write1DBarcode('0123456789', 'C128C', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // EAN 8
     $pdf->Cell(0, 0, 'EAN 8', 0, 1);
     $pdf->write1DBarcode('1234567', 'EAN8', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // EAN 13
     $pdf->Cell(0, 0, 'EAN 13', 0, 1);
     $pdf->write1DBarcode('1234567890128', 'EAN13', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // UPC-A
     $pdf->Cell(0, 0, 'UPC-A', 0, 1);
     $pdf->write1DBarcode('12345678901', 'UPCA', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // UPC-E
     $pdf->Cell(0, 0, 'UPC-E', 0, 1);
     $pdf->write1DBarcode('04210000526', 'UPCE', '', '', '', 18, 0.4, $style, 'N');
     // add a page ----------
     $pdf->AddPage();
     // 5-Digits UPC-Based Extension
     $pdf->Cell(0, 0, '5-Digits UPC-Based Extension', 0, 1);
     $pdf->write1DBarcode('51234', 'EAN5', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // 2-Digits UPC-Based Extension
     $pdf->Cell(0, 0, '2-Digits UPC-Based Extension', 0, 1);
     $pdf->write1DBarcode('34', 'EAN2', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // MSI
     $pdf->Cell(0, 0, 'MSI', 0, 1);
     $pdf->write1DBarcode('80523', 'MSI', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // MSI + CHECKSUM (module 11)
     $pdf->Cell(0, 0, 'MSI + CHECKSUM (module 11)', 0, 1);
     $pdf->write1DBarcode('80523', 'MSI+', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // CODABAR
     $pdf->Cell(0, 0, 'CODABAR', 0, 1);
     $pdf->write1DBarcode('123456789', 'CODABAR', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // CODE 11
     $pdf->Cell(0, 0, 'CODE 11', 0, 1);
     $pdf->write1DBarcode('123-456-789', 'CODE11', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // PHARMACODE
     $pdf->Cell(0, 0, 'PHARMACODE', 0, 1);
     $pdf->write1DBarcode('789', 'PHARMA', '', '', '', 18, 0.4, $style, 'N');
     $pdf->Ln();
     // PHARMACODE TWO-TRACKS
     $pdf->Cell(0, 0, 'PHARMACODE TWO-TRACKS', 0, 1);
     $pdf->write1DBarcode('105', 'PHARMA2T', '', '', '', 18, 2, $style, 'N');
     // add a page ----------
     $pdf->AddPage();
     // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
     $pdf->Cell(0, 0, 'IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200', 0, 1);
     $pdf->write1DBarcode('01234567094987654321-01234567891', 'IMB', '', '', '', 15, 0.6, $style, 'N');
     $pdf->Ln();
     // POSTNET
     $pdf->Cell(0, 0, 'POSTNET', 0, 1);
     $pdf->write1DBarcode('98000', 'POSTNET', '', '', '', 15, 0.6, $style, 'N');
     $pdf->Ln();
     // PLANET
     $pdf->Cell(0, 0, 'PLANET', 0, 1);
     $pdf->write1DBarcode('98000', 'PLANET', '', '', '', 15, 0.6, $style, 'N');
     $pdf->Ln();
     // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
     $pdf->Cell(0, 0, 'RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)', 0, 1);
     $pdf->write1DBarcode('SN34RD1A', 'RMS4CC', '', '', '', 15, 0.6, $style, 'N');
     $pdf->Ln();
     // KIX (Klant index - Customer index)
     $pdf->Cell(0, 0, 'KIX (Klant index - Customer index)', 0, 1);
     $pdf->write1DBarcode('SN34RDX1A', 'KIX', '', '', '', 15, 0.6, $style, 'N');
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     // TEST BARCODE ALIGNMENTS
     // add a page
     $pdf->AddPage();
     // set a background color
     $style['bgcolor'] = array(255, 255, 240);
     $style['fgcolor'] = array(127, 0, 0);
     // Left position
     $style['position'] = 'L';
     $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // Center position
     $style['position'] = 'C';
     $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // Right position
     $style['position'] = 'R';
     $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
     $style['fgcolor'] = array(0, 127, 0);
     $style['position'] = '';
     $style['stretch'] = false;
     // disable stretch
     $style['fitwidth'] = false;
     // disable fitwidth
     // Left alignment
     $style['align'] = 'L';
     $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // Center alignment
     $style['align'] = 'C';
     $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // Right alignment
     $style['align'] = 'R';
     $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
     $style['fgcolor'] = array(0, 64, 127);
     $style['position'] = '';
     $style['stretch'] = false;
     // disable stretch
     $style['fitwidth'] = true;
     // disable fitwidth
     // Left alignment
     $style['cellfitalign'] = 'L';
     $pdf->write1DBarcode('LEFT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // Center alignment
     $style['cellfitalign'] = 'C';
     $pdf->write1DBarcode('CENTER', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // Right alignment
     $style['cellfitalign'] = 'R';
     $pdf->write1DBarcode('RIGHT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
     $style['fgcolor'] = array(127, 0, 127);
     // Left alignment
     $style['position'] = 'L';
     $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // Center alignment
     $style['position'] = 'C';
     $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
     $pdf->Ln(2);
     // Right alignment
     $style['position'] = 'R';
     $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     // TEST BARCODE STYLE
     // define barcode style
     $style = array('position' => '', 'align' => '', 'stretch' => true, 'fitwidth' => false, 'cellfitalign' => '', 'border' => true, 'hpadding' => 'auto', 'vpadding' => 'auto', 'fgcolor' => array(0, 0, 128), 'bgcolor' => array(255, 255, 128), 'text' => true, 'label' => 'CUSTOM LABEL', 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4);
     // CODE 39 EXTENDED + CHECKSUM
     $pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
     $pdf->SetLineStyle(array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
     $pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', 120, 25, 0.4, $style, 'N');
     $this->comparePdfs($pdf);
 }
Example #3
0
 public function testPdfOutput()
 {
     // create new PDF document
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Nicola Asuni');
     $pdf->SetTitle('TCPDF Example 035');
     $pdf->SetSubject('TCPDF Tutorial');
     $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     // set default header data
     $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 035', PDF_HEADER_STRING);
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // set some language-dependent strings (optional)
     $pdf->setLanguageArray($this->langSettings);
     // ---------------------------------------------------------
     // set font
     $pdf->SetFont('times', 'BI', 16);
     // add a page
     $pdf->AddPage();
     $pdf->Write(0, 'Example of SetLineStyle() method', '', 0, 'L', true, 0, false, false, 0);
     $pdf->Ln();
     $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 4, 'color' => array(255, 0, 0)));
     $pdf->SetFillColor(255, 255, 128);
     $pdf->SetTextColor(0, 0, 128);
     $text = "DUMMY";
     $pdf->Cell(0, 0, $text, 1, 1, 'L', 1, 0);
     $pdf->Ln();
     $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 255)));
     $pdf->SetFillColor(255, 255, 0);
     $pdf->SetTextColor(0, 0, 255);
     $pdf->MultiCell(60, 4, $text, 1, 'C', 1, 0);
     $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 255, 0)));
     $pdf->SetFillColor(0, 0, 255);
     $pdf->SetTextColor(255, 255, 0);
     $pdf->MultiCell(60, 4, $text, 'TB', 'C', 1, 0);
     $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 255)));
     $pdf->SetFillColor(0, 255, 0);
     $pdf->SetTextColor(255, 0, 255);
     $pdf->MultiCell(60, 4, $text, 1, 'C', 1, 1);
     $this->comparePdfs($pdf);
 }
Example #4
0
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', 'BI', 16);
// add a page
$pdf->AddPage();
// print a line using Cell()
$pdf->Cell(0, 12, 'Example 035', 1, 1, 'C');
$pdf->Ln();
$pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 4, 'color' => array(255, 0, 0)));
$pdf->SetFillColor(255, 255, 128);
$pdf->SetTextColor(0, 0, 128);
$text = "DUMMY";
$pdf->Cell(0, 0, $text, 1, 1, 'L', 1, 0);
$pdf->Ln();
$pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 255)));
$pdf->SetFillColor(255, 255, 0);
$pdf->SetTextColor(0, 0, 255);
$pdf->MultiCell(60, 4, $text, 1, 'C', 1, 0);
$pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 255, 0)));
$pdf->SetFillColor(0, 0, 255);
$pdf->SetTextColor(255, 255, 0);
$pdf->MultiCell(60, 4, $text, 'TB', 'C', 1, 0);
$pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 255)));
$pdf->SetFillColor(0, 255, 0);
Example #5
0
$pdf->SetTextColor(0, 0, 0);
//set up a page
$pdf->AddPage();
$pdf->SetDisplayMode('real');
$pdf->SetFontSize(8);
// ширина квитанции
$width = 190;
// Высота половинки
$height = 75;
// ширина слушебного поля
$field_width = 80;
// Начальные координаты
$x = 10;
$y = 10;
// Первая рамка
$pdf->SetLineStyle(array('dash' => 2));
$pdf->SetXY($x, $y);
$pdf->Cell($width, $height, '', 1, 0, 'C', 0);
$pdf->SetXY($field_width + $x - 40, $y + 5);
$pdf->Write(5, "Извещение" . PHP_EOL);
$pdf->SetXY($x + 10, $height + $y - 10);
//Some test
$pdf->Write(5, "Кассир" . PHP_EOL);
$pdf->SetXY($field_width, $y);
$pdf->Cell($width - $field_width, $height, '', 'L', 0, 'C', 0);
// Наименование
$x = $field_width;
textfield($pdf, $x + 2, $y + 3, 110, $recipient, '(наименование получателя платежа)');
// Инн получателя
$y += 8;
textfield($pdf, $x + 2, $y + 3, 35, $inn, '(ИНН получателя платежа)');
Example #6
0
$pdf->Text(5, 7, "Line examples");
$pdf->Line(5, 10, 80, 30, $style);
$pdf->Line(5, 10, 5, 30, $style2);
$pdf->Line(5, 10, 80, 10, $style3);
// Rect
$pdf->Text(100, 7, "Rectangle examples");
$pdf->Rect(100, 10, 40, 20, "DF", $style4, array(220, 220, 200));
$pdf->Rect(145, 10, 40, 20, "D", array("all" => $style3));
// Curve
$pdf->Text(5, 37, "Curve examples");
$pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, null, $style6);
$pdf->Curve(80, 40, 70, 75, 150, 45, 100, 75, "F", $style6);
$pdf->Curve(140, 40, 150, 55, 180, 45, 200, 75, "DF", $style6, array(200, 220, 200));
// Circle and ellipse
$pdf->Text(5, 82, "Circle and ellipse examples");
$pdf->SetLineStyle($style5);
$pdf->Circle(25, 105, 20);
$pdf->Circle(25, 105, 10, 90, 180, null, $style6);
$pdf->Circle(25, 105, 10, 270, 360, "F");
$pdf->Circle(25, 105, 10, 270, 360, "C", $style6);
$pdf->SetLineStyle($style5);
$pdf->Ellipse(100, 105, 40, 20);
$pdf->Ellipse(100, 105, 20, 10, 0, 90, 180, null, $style6);
$pdf->Ellipse(100, 105, 20, 10, 0, 270, 360, "DF", $style6);
$pdf->SetLineStyle($style5);
$pdf->Ellipse(175, 105, 30, 15, 45);
$pdf->Ellipse(175, 105, 15, 7.5, 45, 90, 180, null, $style6);
$pdf->Ellipse(175, 105, 15, 7.5, 45, 270, 360, "F", $style6, array(220, 200, 200));
// Polygon
$pdf->Text(5, 132, "Polygon examples");
$pdf->SetLineStyle(array("width" => 0.5, "cap" => "butt", "join" => "miter", "dash" => 0, "color" => array(0, 0, 0)));
Example #7
0
$pdf->Text(5, 4, 'Line examples');
$pdf->Line(5, 10, 80, 30, $style);
$pdf->Line(5, 10, 5, 30, $style2);
$pdf->Line(5, 10, 80, 10, $style3);
// Rect
$pdf->Text(100, 4, 'Rectangle examples');
$pdf->Rect(100, 10, 40, 20, 'DF', $style4, array(220, 220, 200));
$pdf->Rect(145, 10, 40, 20, 'D', array('all' => $style3));
// Curve
$pdf->Text(5, 34, 'Curve examples');
$pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, null, $style6);
$pdf->Curve(80, 40, 70, 75, 150, 45, 100, 75, 'F', $style6);
$pdf->Curve(140, 40, 150, 55, 180, 45, 200, 75, 'DF', $style6, array(200, 220, 200));
// Circle and ellipse
$pdf->Text(5, 79, 'Circle and ellipse examples');
$pdf->SetLineStyle($style5);
$pdf->Circle(25, 105, 20);
$pdf->Circle(25, 105, 10, 90, 180, null, $style6);
$pdf->Circle(25, 105, 10, 270, 360, 'F');
$pdf->Circle(25, 105, 10, 270, 360, 'C', $style6);
$pdf->SetLineStyle($style5);
$pdf->Ellipse(100, 103, 40, 20);
$pdf->Ellipse(100, 105, 20, 10, 0, 90, 180, null, $style6);
$pdf->Ellipse(100, 105, 20, 10, 0, 270, 360, 'DF', $style6);
$pdf->SetLineStyle($style5);
$pdf->Ellipse(175, 103, 30, 15, 45);
$pdf->Ellipse(175, 105, 15, 7.5, 45, 90, 180, null, $style6);
$pdf->Ellipse(175, 105, 15, 7.5, 45, 270, 360, 'F', $style6, array(220, 200, 200));
// Polygon
$pdf->Text(5, 129, 'Polygon examples');
$pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
Example #8
0
    $grid_x = $X_offset + $box_width + $X_spacing + $wall_thickness;
    $pdf->rect($grid_x, $grid_y, $box_inner_width, $box_inner_height);
    $grid_y += ($box_height + $Y_spacing) * 2;
    $pdf->rect($grid_x, $grid_y, $box_inner_width, $box_inner_height);
    $grid_y = $Y_offset + $wall_thickness + $Y_spacing + $box_height;
    $grid_x = $X_offset + $wall_thickness;
    $pdf->rect($grid_x, $grid_y, $box_inner_width, $box_inner_height);
    $grid_x += $box_width + $X_spacing;
    $pdf->rect($grid_x, $grid_y, $box_inner_width, $box_inner_height);
    $grid_x += $box_width + $X_spacing;
    $pdf->rect($grid_x, $grid_y, $box_inner_width, $box_inner_height);
    $grid_x += $box_width + $X_spacing;
    $pdf->rect($grid_x, $grid_y, $box_inner_width, $box_inner_height);
}
// draw top and bottom
$pdf->SetLineStyle($shape_style);
shift_points($points_lid, $box_width + $X_spacing + $X_offset, $Y_offset);
$pdf->Polygon($points_lid, '', $shape_style, array(), true);
// true denotes a closed polygon, very important
shift_points($points_lid, 0, ($box_height + $Y_spacing) * 2);
$pdf->Polygon($points_lid, '', $shape_style, array(), true);
// draw four sides
shift_points($points_side, $X_offset, $box_height + $Y_spacing + $Y_offset);
$pdf->Polygon($points_side, '', $shape_style, array(), true);
shift_points($points_side, $box_width + $X_spacing, 0);
$pdf->Polygon($points_side, '', $shape_style, array(), true);
shift_points($points_side, $box_width + $X_spacing, 0);
$pdf->Polygon($points_side, '', $shape_style, array(), true);
shift_points($points_side, $box_width + $X_spacing, 0);
$pdf->Polygon($points_side, '', $shape_style, array(), true);
// ---------------------------------------------------------
 public function RenderAsPDF(TCPDF $oPdf, DisplayableGraph $oGraph, $fScale, $aContextDefs)
 {
     $bReached = $this->GetProperty('is_reached');
     $oPdf->SetFillColor(255, 255, 255);
     if ($bReached) {
         $aBorderColor = array(100, 100, 100);
     } else {
         $aBorderColor = array(200, 200, 200);
     }
     $oPdf->SetLineStyle(array('width' => 2 * $fScale, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => $aBorderColor));
     $sIconUrl = $this->GetProperty('icon_url');
     $sIconPath = str_replace(utils::GetAbsoluteUrlModulesRoot(), APPROOT . 'env-' . utils::GetCurrentEnvironment() . '/', $sIconUrl);
     $oPdf->SetAlpha(1);
     $oPdf->Circle($this->x * $fScale, $this->y * $fScale, $this->GetWidth() / 2 * $fScale, 0, 360, 'DF');
     if ($bReached) {
         $oPdf->SetAlpha(1);
     } else {
         $oPdf->SetAlpha(0.4);
     }
     $oPdf->Image($sIconPath, ($this->x - 17) * $fScale, ($this->y - 17) * $fScale, 16 * $fScale, 16 * $fScale);
     $oPdf->Image($sIconPath, ($this->x + 1) * $fScale, ($this->y - 17) * $fScale, 16 * $fScale, 16 * $fScale);
     $oPdf->Image($sIconPath, ($this->x - 8) * $fScale, ($this->y + 1) * $fScale, 16 * $fScale, 16 * $fScale);
     $oPdf->SetFont('dejavusans', '', 24 * $fScale, '', true);
     $width = $oPdf->GetStringWidth($this->GetProperty('label'));
     $oPdf->SetTextColor(0, 0, 0);
     $oPdf->Text($this->x * $fScale - $width / 2, ($this->y + 25) * $fScale, $this->GetProperty('label'));
 }
Example #10
0
 /**
  * Render
  * 
  * @param string $type
  * @return string
  */
 public function render($type)
 {
     $result = '';
     $session = new session();
     // main switch
     switch ($type) {
         case 'pdf':
             // document properties
             $this->header['pdf']['orientation'] = isset($this->header['pdf']['orientation']) ? $this->header['pdf']['orientation'] : 'P';
             $this->header['pdf']['unit'] = 'mm';
             $this->header['pdf']['format'] = isset($this->header['pdf']['format']) ? $this->header['pdf']['format'] : 'LETTER';
             $this->header['pdf']['encoding'] = isset($this->header['pdf']['encoding']) ? $this->header['pdf']['encoding'] : 'UTF-8';
             $this->header['pdf']['font'] = isset($this->header['pdf']['font']) ? $this->header['pdf']['font'] : array('family' => 'helvetica', 'style' => '', 'size' => 8);
             //include 'tcpdf/tcpdf.php';
             // create new PDF document
             $pdf = new TCPDF($this->header['pdf']['orientation'], $this->header['pdf']['unit'], $this->header['pdf']['format'], true, $this->header['pdf']['encoding'], false);
             // set margins
             $pdf->SetMargins(0, 0, 0);
             $pdf->setPrintHeader(false);
             // disable auto break
             $pdf->SetAutoPageBreak(false, 0);
             // set default font subsetting mode
             $pdf->setFontSubsetting(true);
             // set color for background
             $pdf->SetFillColor(255, 255, 255);
             // set font
             $pdf->SetFont($this->header['pdf']['font']['family'], $this->header['pdf']['font']['style'], $this->header['pdf']['font']['size']);
             // stats
             $page_counter = 1;
             $page_y = 0;
             $flag_new_page = true;
             $flag_filter = true;
             $flag_first_row = true;
             $columns = array();
             $all_columns = array();
             // gethering all columns
             foreach ($this->data as $k => $v) {
                 if ($v['t'] == 'columns') {
                     $all_columns[] = $v;
                 }
             }
             // looping through the data
             foreach ($this->data as $k => $v) {
                 if ($v['t'] == 'columns') {
                     continue;
                 }
                 if ($flag_new_page) {
                     // add new page
                     $pdf->AddPage($this->header['pdf']['orientation'], '', true);
                     // drawing header
                     $pdf->MultiCell(40, 5, format::datetime(format::now()), 0, 'L', 1, 0, 5, 5, true, 0, false, true, 10, 'T');
                     // company + book name
                     $pw = $pdf->getPageWidth();
                     $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']);
                     // todo: fix here
                     $pdf->MultiCell($pw - 90, 5, $session->company_name . ': ' . $session->book_name, 0, 'C', 1, 0, 40, 5, true, 0, false, true, 10, 'T');
                     // page counter
                     $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']);
                     $pdf->MultiCell(40, 5, 'Page ' . $page_counter, 0, 'R', 1, 0, $pw - 45, 5, true, 0, false, true, 10, 'T');
                     // report name
                     $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']);
                     $report_name = $this->header['name'] . ' (' . implode('-', application::get(array('mvc', 'controllers'))) . ')';
                     $pdf->MultiCell($pw - 10, 5, $report_name, 0, 'L', 1, 0, 5, 10, true, 0, false, true, 10, 'T');
                     if (isset($this->header['description'])) {
                         $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']);
                         $pdf->MultiCell(205, 5, $this->header['description'], 0, 'L', 1, 0, 5, 15, true, 0, false, true, 10, 'T');
                         $page_y = 25;
                     } else {
                         $page_y = 20;
                     }
                     // if we need to add a filter
                     if ($flag_filter) {
                         if (isset($this->header['filter'])) {
                             foreach ($this->header['filter'] as $k2 => $v2) {
                                 $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']);
                                 $pdf->MultiCell(50, 5, $k2 . ':', 0, 'L', 1, 0, 5, $page_y, true, 0, false, true, 10, 'T');
                                 $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']);
                                 $number_of_cells = $pdf->MultiCell($pdf->getPageWidth() - 60, 5, $v2, 0, 'L', 1, 0, 55, $page_y, true, 0, false, true, 10, 'T');
                                 if ($number_of_cells > 1) {
                                     $page_y += 5 * ($number_of_cells - 1);
                                 }
                                 $page_y += 5;
                             }
                         }
                         $flag_filter = false;
                         // adding one line space
                         $page_y += 5;
                     }
                     // page counter
                     $page_counter++;
                     $flag_new_page = false;
                 }
                 // rendering rows
                 if ($flag_first_row) {
                     if (empty($columns)) {
                         $columns = current($all_columns);
                         // repopulate width
                         $count_empty = 0;
                         $taken = 0;
                         foreach ($columns['d'] as $k2 => $v2) {
                             if (empty($v2['w'])) {
                                 $count_empty++;
                             } else {
                                 $taken += $v2['w'];
                             }
                         }
                         if (!empty($count_empty)) {
                             $new_width = floor(($pdf->getPageWidth() - 10 - $taken) / $count_empty);
                             foreach ($v['d'] as $k2 => $v2) {
                                 $columns['d'][$k2]['w'] = $new_width;
                             }
                         }
                     }
                     $flag_first_row = false;
                     // columns
                     foreach ($all_columns as $k20 => $v20) {
                         $x = 5;
                         foreach ($columns['d'] as $k10 => $v10) {
                             foreach (array('v', 'c', 'a', 'b', 's', 't', 'u') as $v30) {
                                 if (isset($v20['d'][$k10][$v30])) {
                                     $v10[$v30] = $v20['d'][$k10][$v30];
                                 }
                             }
                             $new_width = @$v10['w'];
                             if (!empty($v10['c'])) {
                                 // we need to get width of next elements
                                 for ($i = $k10 + 1; $i < $k10 + $v10['c']; $i++) {
                                     $new_width += $columns['d'][$k10]['w'];
                                 }
                             }
                             $align = str_replace(array('left', 'right', 'center'), array('L', 'R', 'C'), @$v10['a']);
                             if (empty($align)) {
                                 $align = 'L';
                             }
                             if (@$v10['b']) {
                                 $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']);
                             } else {
                                 $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']);
                             }
                             $pdf->MultiCell($new_width, 5, @$v10['v'], $this->flag_pdf_show_borders, $align, 1, 0, $x, $page_y, true, 0, false, true, 10, 'T');
                             // underline
                             if (@$v10['u']) {
                                 $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
                                 $pdf->Line($x, $page_y + 5, $x + @$v10['w'], $page_y + 5);
                             }
                             $x += @$v10['w'];
                         }
                         $page_y += 5;
                     }
                 }
                 $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']);
                 $x = 5;
                 foreach ($columns['d'] as $k10 => $v10) {
                     // we do do render cells if no data
                     if (isset($v['d'][$k10]['v'])) {
                         $align = str_replace(array('left', 'right', 'center'), array('L', 'R', 'C'), @$v['d'][$k10]['a']);
                         if (empty($align)) {
                             $align = 'L';
                         }
                         if (@$v['d'][$k10]['b']) {
                             $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']);
                         } else {
                             $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']);
                         }
                         // if we override width
                         $width = $v10['w'];
                         if (isset($v['d'][$k10]['w'])) {
                             $width = $v['d'][$k10]['w'];
                         } else {
                             if (isset($v['d'][$k10]['c'])) {
                                 // colspan
                                 // we need to get width of next elements
                                 for ($i = $k10 + 1; $i < $k10 + $v['d'][$k10]['c']; $i++) {
                                     $width += @$columns['d'][$i]['w'];
                                 }
                             }
                         }
                         $value = @$v['d'][$k10]['v'];
                         $value = str_replace('&nbsp;', ' ', $value);
                         // rendering cell
                         $pdf->MultiCell($width, 5, $value, $this->flag_pdf_show_borders, $align, 1, 0, $x, $page_y, true, 0, false, true, 10, 'T');
                         // underline
                         if (@$v['d'][$k10]['u']) {
                             $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
                             $pdf->Line($x, $page_y + 5, $x + $v10['w'], $page_y + 5);
                         }
                         // subtotal
                         if (@$v['d'][$k10]['s']) {
                             $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
                             $pdf->Line($x + 1, $page_y, $x + $v10['w'] - 1, $page_y);
                         }
                         // total
                         if (@$v['d'][$k10]['t']) {
                             $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
                             $pdf->Line($x + 1, $page_y, $x + $v10['w'] - 1, $page_y);
                             $pdf->Line($x + 1, $page_y - 0.75, $x + $v10['w'] - 1, $page_y - 0.75);
                         }
                     }
                     $x += @$v10['w'];
                 }
                 // incrementing
                 $page_y += 5;
                 if ($page_y > $pdf->getPageHeight() - 10) {
                     $flag_new_page = true;
                     $flag_first_row = true;
                 }
             }
             $pdf->Output($this->header['name'] . '.pdf', 'I');
             exit;
             break;
         case 'csv':
         case 'txt':
         case 'xlsx':
             $sheet = strip_tags($this->header['name']);
             $sheet = str_replace(['/', '\\'], '', $sheet);
             // generating header
             $header = [];
             $header[$sheet][] = [format::datetime(format::now()), '', $session->company_name . ': ' . $session->book_name, '', 'Page 1'];
             $controllers = application::get(['mvc', 'controllers']);
             $header[$sheet][] = [strip_tags($this->header['name']) . ' (' . implode('-', $controllers) . ')'];
             if (isset($this->header['description'])) {
                 $header[$sheet][] = [$this->header['description']];
             }
             $header[$sheet][] = [' '];
             $temp = $header;
             // displaying filter
             if (isset($this->header['filter'])) {
                 $temp2 = [];
                 foreach ($this->header['filter'] as $k => $v) {
                     $temp[$sheet][] = [strip_tags($k), strip_tags($v)];
                 }
                 $temp[$sheet][] = [' '];
             }
             // converting data
             foreach ($this->data as $k => $v) {
                 $temp2 = [];
                 foreach ($v['d'] as $k2 => $v2) {
                     if (is_array($v2)) {
                         $value = $v2['v'] ?? null;
                     } else {
                         $value = $v2;
                     }
                     // replaces
                     $value = str_replace('&nbsp;', ' ', $value);
                     $temp2[] = strip_tags($value);
                 }
                 $temp[$sheet][] = $temp2;
             }
             // get output buffering
             helper_ob::clean_all();
             // content
             switch ($type) {
                 case 'xlsx':
                     echo io::array_to_excel($temp, io::$formats[$type]['excel_code'], null);
                     break;
                 default:
                     // csv or text
                     header('Content-Type: ' . numbers_frontend_exports_csv_base::$formats[$type]['content_type']);
                     header('Content-Disposition: attachment; filename="' . $sheet . '.' . $type . '"');
                     header('Cache-Control: max-age=0');
                     echo numbers_frontend_exports_csv_base::array_to_csv($temp, numbers_frontend_exports_csv_base::$formats[$type]['delimiter'], numbers_frontend_exports_csv_base::$formats[$type]['enclosure']);
             }
             exit;
             break;
         case 'html':
         case 'html2':
         default:
             // rendering data
             $table = ['options' => []];
             $counter = 1;
             foreach ($this->data as $k => $v) {
                 $flag_colspan = 0;
                 $row = [];
                 if (!empty($v['d'])) {
                     foreach ($v['d'] as $k2 => $v2) {
                         if ($flag_colspan > 0) {
                             $flag_colspan--;
                             continue;
                         }
                         $colspan = '';
                         if ($v2['c'] ?? null) {
                             $colspan = $v2['c'];
                             $flag_colspan = $v2['c'] - 1;
                         }
                         $align = 'left';
                         $title = '';
                         $style = '';
                         if (is_array($v2)) {
                             $value = $v2['v'] ?? null;
                             if (!empty($v2['h'])) {
                                 $v2['h']['value'] = $value;
                                 $value = html::a($v2['h']);
                             }
                             if (!empty($v2['a'])) {
                                 $align = $v2['a'];
                             }
                             if (!empty($v2['l'])) {
                                 $title = $v2['l'];
                             }
                             // bold lines
                             if ($v2['b'] ?? null) {
                                 $value = '<b>' . $value . '</b>';
                             }
                             // todo: convert styles to classes
                             if ($v2['s'] ?? null) {
                                 $style .= 'border-top: 1px solid #000;';
                             }
                             if ($v2['t'] ?? null) {
                                 $style .= 'border-top: 3px double #000;';
                             }
                             if ($v2['u'] ?? null) {
                                 $style .= 'border-bottom: 1px solid #000;';
                             }
                         } else {
                             $value = $v2;
                         }
                         $row[$k2] = ['value' => $value, 'align' => $align, 'colspan' => $colspan, 'style' => $style, 'title' => $title, 'nowrap' => true];
                     }
                 } else {
                     $row[0] = ['value' => '&nbsp;'];
                 }
                 $table['options'][$counter] = $row;
                 $counter++;
             }
             $result = html::table($table);
             // printable export
             if ($type == 'html2') {
                 $header = ['options' => []];
                 $header['options'][] = [0 => format::datetime(format::now()), 1 => '', 2 => $session->company_name . ': ' . $session->book_name, 3 => '', 4 => 'Page 1'];
                 $controllers = application::get(['mvc', 'controllers']);
                 $header['options'][] = [['value' => strip_tags($this->header['name']) . ' (' . implode('-', $controllers) . ')', 'colspan' => 5]];
                 if (isset($this->header['description'])) {
                     $header['options'][] = [$this->header['description']];
                 }
                 $header['options'][] = ['&nbsp;'];
                 // displaying filter
                 if (isset($this->header['filter'])) {
                     $temp2 = [];
                     foreach ($this->header['filter'] as $k => $v) {
                         $header['options'][] = [strip_tags($k) . ':', strip_tags($v)];
                     }
                     $header['options'][] = ['&nbsp;'];
                 }
                 $header = html::table($header);
                 layout::render_as($header . $result, 'text/html');
             }
     }
     return $result;
 }
Example #11
0
/**
 *  图文混排
 *  @author zhaoning <*****@*****.**>
 */
function pdf_nine()
{
    // Include the main TCPDF library (search for installation path).
    require_once 'tcpdf.php';
    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // set document information
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Nicola Asuni');
    $pdf->SetTitle('TCPDF Example 064');
    $pdf->SetSubject('TCPDF Tutorial');
    $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
    // set default header data
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 064', PDF_HEADER_STRING);
    // set header and footer fonts
    $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    // set some language-dependent strings (optional)
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    // ---------------------------------------------------------
    // set font
    $pdf->SetFont('helvetica', '', 8);
    // define some html content for testing
    $txt = '<p style="text-align:justify;color:blue;font-size:12pt;"><span style="color:red;font-size:14pt;font-weight:bold;">TEST PAGE REGIONS:</span> <span style="color:green;">A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code. A region is always aligned on the left or right side of the page ad is defined using a vertical segment. You can set multiple regions for the same page. You can combine several adjacent regions to approximate curved shapes.</span> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sed imperdiet lectus. Phasellus quis velit velit, non condimentum quam. Sed neque urna, ultrices ac volutpat vel, laoreet vitae augue. Sed vel velit erat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras eget velit nulla, eu sagittis elit. Nunc ac arcu est, in lobortis tellus. Praesent condimentum rhoncus sodales. In hac habitasse platea dictumst. Proin porta eros pharetra enim tincidunt dignissim nec vel dolor. Cras sapien elit, ornare ac dignissim eu, ultricies ac eros. Maecenas augue magna, ultrices a congue in, mollis eu nulla. Nunc venenatis massa at est eleifend faucibus. Vivamus sed risus lectus, nec interdum nunc.
Fusce et felis vitae diam lobortis sollicitudin. Aenean tincidunt accumsan nisi, id vehicula quam laoreet elementum. Phasellus egestas interdum erat, et viverra ipsum ultricies ac. Praesent sagittis augue at augue volutpat eleifend. Cras nec orci neque. Mauris bibendum posuere blandit. Donec feugiat mollis dui sit amet pellentesque. Sed a enim justo. Donec tincidunt, nisl eget elementum aliquam, odio ipsum ultrices quam, eu porttitor ligula urna at lorem. Donec varius, eros et convallis laoreet, ligula tellus consequat felis, ut ornare metus tellus sodales velit. Duis sed diam ante. Ut rutrum malesuada massa, vitae consectetur ipsum rhoncus sed. Suspendisse potenti. Pellentesque a congue massa.
Integer non sem eget neque mattis accumsan. Maecenas eu nisl mauris, sit amet interdum ipsum. In pharetra erat vel lectus venenatis elementum. Nulla non elit ligula, sit amet mollis urna. Morbi ut gravida est. Mauris tincidunt sem et turpis molestie malesuada. Curabitur vel nulla risus, sed mollis erat. Suspendisse vehicula accumsan purus nec varius. Donec fermentum lorem id felis sodales dictum. Quisque et dolor ipsum. Nam luctus consectetur dui vitae fermentum. Curabitur sodales consequat augue, id ultricies augue tempor ac. Aliquam ac magna id ipsum vehicula bibendum. Sed elementum congue tristique. <img src="examples/images/image_demo.jpg" width="5mm" height="5mm" /> Phasellus vel lorem eu lectus porta sodales. Etiam neque tortor, sagittis id pharetra quis, laoreet vel arcu.
Cras quam mi, ornare laoreet laoreet vel, vehicula at lacus. Maecenas a lacus accumsan augue convallis sagittis sed quis odio. Morbi sit amet turpis diam, dictum convallis urna. Cras eget interdum augue. Cras eu nisi sit amet dolor faucibus porttitor. Suspendisse potenti. Nunc vitae dolor risus, at cursus libero. Suspendisse bibendum tellus non nibh hendrerit tristique. Mauris eget orci elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porta libero non ante laoreet semper. Proin volutpat sodales mi, ac fermentum erat sagittis in. Vivamus at viverra felis. Ut pretium facilisis ante et pharetra.
Nulla facilisi. Cras varius quam eget libero aliquam vitae tincidunt leo rutrum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque a nisl massa, quis pretium urna. Proin vel porttitor tortor. Cras rhoncus congue velit in bibendum. Donec pharetra semper augue id lacinia. Quisque magna quam, hendrerit eu aliquam et, pellentesque ut tellus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas nulla quam, rutrum eu feugiat at, elementum eu libero. Maecenas ullamcorper leo et turpis rutrum ac laoreet eros faucibus. Phasellus condimentum lorem quis neque imperdiet quis molestie enim iaculis. Phasellus risus est, vestibulum ut convallis ultrices, dignissim nec erat. Etiam congue lobortis laoreet. Nulla ut neque sed velit dapibus semper. Quisque nec dolor id nibh eleifend iaculis. Vivamus vitae fermentum odio. Etiam malesuada quam in nulla aliquam sed convallis dui feugiat.</p>';
    // add a page
    $pdf->AddPage();
    // print some graphic content
    $pdf->Image('examples/images/image_demo.jpg', 155, 30, 40, 40, 'JPG', '', '', true);
    $pdf->Image('examples/images/image_demo.jpg', 15, 230, 40, 40, 'JPG', '', '', true);
    // define some graphic styles
    $styleA = array('width' => 0.254, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0));
    $styleB = array('width' => 0.254, 'cap' => 'butt', 'join' => 'miter', 'dash' => 3, 'color' => array(127, 127, 127));
    $pdf->SetFillColor(220, 255, 220);
    // write a trapezoid with some information about no-write page regions
    $pdf->Polygon(array(15, 90, 57, 90, 67, 140, 15, 140), 'DF', array($styleB, $styleA, $styleB, $styleB));
    $pdf->SetXY(15, 90);
    $pdf->Cell(42, 0, 'xt111,yt', 0, 0, 'R', false, '', 0, false, 'T', 'T');
    $pdf->SetXY(15, 140);
    $pdf->Cell(52, 0, 'xb,yb', 0, 0, 'R', false, '', 0, false, 'B', 'B');
    $pdf->SetXY(15, 115);
    $pdf->Cell(40, 0, 'side', 0, 0, 'R', false, '', 0, false, 'B', 'B');
    $pdf->SetLineStyle(array('width' => 0.254, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
    $pdf->Arrow(60, 115, 35, 115, 2, 5, 15);
    // write a trapezoid with some information about no-write page regions
    $pdf->Polygon(array(145, 130, 195, 130, 195, 180, 155, 180), 'DF', array($styleB, $styleB, $styleB, $styleA));
    $pdf->SetXY(145, 130);
    $pdf->Cell(42, 0, 'xt,yt', 0, 0, 'L', false, '', 0, false, 'T', 'T');
    $pdf->SetXY(155, 180);
    $pdf->Cell(52, 0, 'xb,yb', 0, 0, 'L', false, '', 0, false, 'B', 'B');
    $pdf->SetXY(160, 155);
    $pdf->Cell(30, 0, 'side', 0, 0, 'L', false, '', 0, false, 'B', 'B');
    $pdf->SetLineStyle(array('width' => 0.254, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
    $pdf->Arrow(155, 155, 180, 155, 2, 5, 15);
    // reset x,y position
    $pdf->SetXY(15, 30);
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // define no-write page regions to avoid text overlapping images
    /*
    	'page' => page number or empy for current page
    	'xt' => X top
    	'yt' => Y top
    	'yb' => Y bottom
    	'side' => page side ('L' = left or 'R' = right)
    */
    $regions = array(array('page' => '', 'xt' => 153, 'yt' => 30, 'xb' => 153, 'yb' => 70, 'side' => 'R'), array('page' => '', 'xt' => 60, 'yt' => 90, 'xb' => 70, 'yb' => 140, 'side' => 'L'), array('page' => '', 'xt' => 143, 'yt' => 130, 'xb' => 153, 'yb' => 180, 'side' => 'R'), array('page' => '', 'xt' => 58, 'yt' => 230, 'xb' => 58, 'yb' => 270, 'side' => 'L'));
    // set page regions, check also getPageRegions(), addPageRegion() and removePageRegion()
    $pdf->setPageRegions($regions);
    // write html text
    $pdf->writeHTML($txt, true, false, true, false, '');
    $pdf->Output('example.pdf', 'I');
}