使用 Yii 创建 PDF 或 Word 文档?

发布于 2024-12-17 08:07:47 字数 273 浏览 0 评论 0原文

您好,我正在使用 Yii 构建一个应用程序,现在它将生成报告。我的客户想要在生成报告后对其进行编辑。我认为最好的选择是创建一个 Word 文档,以便我的客户能够编辑它,但我找不到使用 Yii Framework 创建 Word 文档的信息或扩展。

我还见过但尚未测试几个 PDF 扩展,例如 DOMPDF、tcpdf 和 Zend_PDF。但如果我生成 PDF 报告,那么我的客户将如何编辑该文件?

伙计们,我需要有关如何解决此要求的建议。生成 Word 或 PDF 文档?哪个解决方案开发速度最快?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟花易冷人易散 2024-12-24 08:07:47

更新1:
目前我已经可以使用 PDF 了。我是这样做的:首先,我从其 站点 下载 TCPdf 并在 Yii 中打开它作为第三方库。然后:

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'));

无论如何,我希望能够生成一个Word文档,因为要求表示报告将在生成后由用户编辑。

更新2:
对于 Word 文档的报告生成这就是我正在做的

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.

青柠芒果 2024-12-24 08:07:47

Yii 中提供了生成 PDF 文档的扩展。 tcpdf (http://www.yiiframework.com/extension/tcpdf/) 例如..

查看这篇文章,了解可用于 PDF 和 Excel 的选项的综合综述
http://www.yiiframework.com/wiki/74/

但是,如果您需要要创建 Word 文档,那么您可以尝试以下

在 Yii 中编写扩展来生成 Word 文档(请参阅此链接,其中显示了如何在 PHP/Linux 中执行此操作 - 在 Linux 中使用 PHP 创建 Word 文档

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)

回梦 2024-12-24 08:07:47

要创建Word文档,您可以使用phpword库
要使用,请将库提取到文件夹 protected\extensions\PHPWord
解压后在此文件夹中,您将拥有文件夹: Examples, PHPWord 和一个文件: PHPWord.php
在您的控制器/代码中,您需要像本示例中那样调用:

    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');

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');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文