1

I tried below code in my TestController.php but I do not understand how to put text on rectangle

$pdf = new Zend_Pdf();
    $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
     // $this->_setFontRegular($page, 10);
        $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
        $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
        $page->setLineWidth(0.5);

        $this->y -= 10;

        $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));

    $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

    define('FONT_SIZE'      , 12);
    define('MARGIN_LEFT'    , 40);
    define('MARGIN_TOP'     , 40);
    define('COL_WIDTH'      , 100);
    define('COL_LEFT_MARGIN', 10);
    define('COL_SEPARATOR'  , '|');
    define('ROW_HEIGHT'     , 20);

    $row = 1;
    $x = MARGIN_LEFT;
    $y = MARGIN_TOP;
$linecolor = "#cccccc";
$fillcolor = "#000000";
    $page->setFont($font, FONT_SIZE);
    $page->drawText('Text on Rectangle', $x, $page->getHeight() - $y);
    $page->setFillColor(Zend_Pdf_Color_Html::color($fillcolor));
$page->setFillColor(Zend_Pdf_Color_Html::color($linecolor));
    //$page->drawRectangle(10, 50, 200, 450);
    $page->drawRectangle(25, 0, 570, $page->getHeight() - 45);

    $x += COL_WIDTH;

    $x += COL_LEFT_MARGIN;

    $x = MARGIN_LEFT;
    $y += ROW_HEIGHT;
    //echo "<pre>";
    //print_r($page->getContents());
    $pdf->pages[] = $page;
    //$pdf->save("test_{$now->getTimestamp()}.pdf");
    $this->_prepareDownloadResponse('invoice.pdf', $pdf->render(), 'application/pdf');

I want to similar like below image in pdf

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.