3

Hello I'm building an application with Yii that will now generate reports. My client wants to edit the reports after these are generated. I think the best option is creating a Word document so my client will be able to edit it, but I can't find information or extensions to create Word documents with Yii Framework.

I've also seen but not test yet a couple of PDF extensions such as DOMPDF, tcpdf and Zend_PDF. But if I generate a PDF report, then, how is my client going to edit this file?

Guys I need recommendations on how to tackle this requirement. Generate Word or PDF documents? Which will be the fastest to develop solution?

Kara
  • 6,115
  • 16
  • 50
  • 57
ivantxo
  • 719
  • 5
  • 18
  • 36

3 Answers3

3

UPDATE 1: At the moment I got PDFs working. This is how I did it: First I downloaded TCPdf from its site and open it in Yii as a 3rd-party library. Then:

Controller: protected/controllers/mycontroller.php
public function actionGeneratePdf() {
    Yii::import('application.vendors.*');
    require_once('tcpdf/tcpdf.php');
    require_once('tcpdf/config/lang/eng.php');
    $pdf = new TCPDF();
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Nicola Asuni');
    $pdf->SetTitle('TCPDF Example 001');
    $pdf->SetSubject('TCPDF Tutorial');
    $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
    $pdf->SetHeaderData('', 0, PDF_HEADER_TITLE, '');
    $pdf->setHeaderFont(Array('helvetica', '', 8));
    $pdf->setFooterFont(Array('helvetica', '', 6));
    $pdf->SetMargins(15, 18, 15);
    $pdf->SetHeaderMargin(5);
    $pdf->SetFooterMargin(10);
    $pdf->SetAutoPageBreak(TRUE, 0);
    $pdf->SetFont('dejavusans', '', 7);
    $pdf->AddPage();
    $pdf->writeHTML("<span>Hello World!</span>", true, false, true, false, '');
    $pdf->LastPage();
    $pdf->Output("example_002.pdf", "I");
}

View: Wherever you want to place a trigger to your controller:
echo CHtml::link('Generate PDF', array('mycontroller/generatePdf'));

Anyway I want to be able to generate a word document as the requirement says the report is going to be edited by the user after generation.

UPDATE 2: For the Word document's report generation this is what I am doing.

Community
  • 1
  • 1
ivantxo
  • 719
  • 5
  • 18
  • 36
1

To create word document you can use phpword library And to use, extract the library to folder protected\extensions\PHPWord In this folder after extract you will have folders: Examples, PHPWord and one file: PHPWord.php . In your controller/code you need to call like in this example:

    spl_autoload_unregister(array('YiiBase','autoload'));
    Yii::import('ext.phpword.phpword', true);
    $PHPWord = new PHPWord();
    spl_autoload_register(array('YiiBase','autoload'));
    $document = $PHPWord->loadTemplate($path);
    $document->setValue('Value1', 'Sun');
    ....
    $document->save('path\file.docx');
TotPeRo
  • 6,561
  • 4
  • 47
  • 60
1

Extensions are available in Yii to generate PDF documents. tcpdf (http://www.yiiframework.com/extension/tcpdf/) for example..

Check this article on a general roundup of options available for PDF and Excel http://www.yiiframework.com/wiki/74/

However, if you need to create word documents, then you can try the following

Write a extension in Yii to generate word document (please see this link which shows how to do it in PHP/Linux - Create Word Document using PHP in Linux)

Community
  • 1
  • 1
akb
  • 118
  • 6
  • Sorry for the late reply. I'm trying with TCPDF but I can not get it to work. I put the code for the PDF in a controller function. It reaches it but it doesn't do anything. I got this error: Constant K_PATH_CACHE already defined (/var/www/wattquotes/protected/extensions/tcpdf/ETcPdf.php:85). I think is not correctly set up and I don't find enough information on this library. – ivantxo Nov 28 '11 at 23:20
  • How to set up this extension? The documentation is wrong. It is confusing! – ivantxo Nov 29 '11 at 00:39
  • The article you mentioned [link](http://www.yiiframework.com/wiki/74/) said that tcpdf does not work properly. What is the best option to generate pdfs with Yii, then. Have you done it? Please send me a sample! – ivantxo Nov 29 '11 at 01:15