Virtuemart 2产品详细信息PDF

时间:2012-04-20 07:16:43

标签: joomla joomla-extensions tcpdf virtuemart

有谁知道如何修改Virtuemart 2产品详情pdf视图。我已经找到了修改文档正文的位置,但我需要修改: - 标题字体和文字 - 将公司徽标插入标题。

1 个答案:

答案 0 :(得分:0)

我想我找到了一个解决方案:

您需要扩展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);

    }

}