Информация о продукте Virtuemart 2 PDF

Кто-нибудь знает, как изменить представление информации о продукте Virtuemart 2 в формате PDF. Я нашел, где изменить тело документа, но мне нужно изменить: - шрифт и текст заголовка - вставить логотип компании в заголовок.


person di3sel    schedule 20.04.2012    source источник


Ответы (1)


Я думаю, что нашел решение:

вам нужно расширить класс TCPDF и отредактировать function display() в view.pdf.php в components/com_virtuemart/views/pdf/

что-то типа:

function display($tpl = 'pdf'){

    if(!file_exists(JPATH_VM_LIBRARIES.DS.'tcpdf'.DS.'tcpdf.php')){
        vmError('View pdf: For the pdf invoice, you must install the tcpdf library at '.JPATH_VM_LIBRARIES.DS.'tcpdf');
    } else {

        $viewName = jRequest::getWord('view','productdetails');
        // custom pdf for product details
        if($viewName == 'productdetails'){
            $class= 'VirtueMartView'.ucfirst($viewName);
            if(!class_exists($class)) require(JPATH_VM_SITE.DS.'views'.DS.$viewName.DS.'view.html.php');
            $view = new $class ;
            //$format = 'pdf';
            //generating pdf body and caching the buffer
            ob_start();
            $view->display($tpl);
            $html = ob_get_contents();
            ob_end_clean();

            // create pdf
            $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

            // set document information
            $pdf->SetCreator('Creator Name');
            $pdf->SetAuthor('Author Name');

            $pdf->SetTitle('PDF Title');
            $pdf->SetSubject('PDF Subject');
            $pdf->SetKeywords('PDF list keyword');
            // set header and footer fonts
            $pdf->setHeaderFont(Array('helvetica', '', 8));
            $pdf->setFooterFont(Array('helvetica', '', 10));

            // 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 default font subsetting mode
            $pdf->setFontSubsetting(true);

            // Set font
            // dejavusans is a UTF-8 Unicode font, if you only need to
            // print standard ASCII chars, you can use core fonts like
            // helvetica or times to reduce file size.
            $pdf->SetFont('helvetica', '', 8, '', true);

            // if you want to add something to pdf body
            //$html .= "foobar";

            // Add a page
            // This method has several options, check the source code documentation for more information.
            $pdf->AddPage();

            // Print text using writeHTMLCell()
            $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

            // Close and output PDF document
            // This method has several options, check the source code documentation for more information.
            // 
            $pdf->Output('filename.pdf','I');

            exit; //avoid mixing pdf and html output that cause duplicate header error
        }
        else
        {
            //If not in productdetails
            echo "yadda yadda yadda";
        }
    }
}

а также

if(!class_exists('TCPDF'))  require_once(JPATH_VM_LIBRARIES.DS.'tcpdf'.DS.'tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

    public function __construct() {

        parent::__construct();


    }

    //Page header
    public function Header() {
     // Logo
        //$image_file = K_PATH_IMAGES.'logo_example.jpg';
        //$this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        // Set font
        $this->SetFont('helvetica', 'B', 20);
        // Title
        $this->Cell(0, 15, 'Custom header text', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }


    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);

        //vmdebug('$vendor',$vendor);
        $html = "Custom footer txt";
        // Page number
        $this->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

    }

}
person gaffiere    schedule 03.08.2012