简体   繁体   English

如何在LARAVEL 4上使用TCPDF

[英]How to use TCPDF on LARAVEL 4

Good Day, 美好的一天,

Can anyone help me how to use TCPDF in Laravel 4, I mean from installing on via composer update to generating a pdf from the view or through the controller. 谁能帮助我如何在Laravel 4中使用TCPDF,我的意思是从通过composer update安装到从视图或通过控制器生成pdf。 Ive tried to search on Google but I cant find a comprehensive tutorial on how to use it on Laravel 4. Sorry for this noobish question :) . 我曾试图在Google上搜索,但我找不到关于如何在Laravel 4上使用它的全面教程。抱歉这个noobish问题:)。

Thanks for the help. 谢谢您的帮助。 I will really appreciate it. 我真的很感激。 Have a good day! 祝你有美好的一天!

The definitive version of TCPDF can be added to your Laravel application by adding the tecnick.com/tcpdf package to your composer.json file as follows: 通过将tecnick.com/tcpdf包添加到composer.json文件中,可以将最终版本的TCPDF添加到Laravel应用程序中,如下所示:

"require": {
    "laravel/framework": "4.0.*",
    "tecnick.com/tcpdf": "6.0.*", // This is the line to add

Running composer update will add the library to your project. 运行composer update会将库添加到项目中。

You can then instantiate instances of TCPDF and work with it as per the documentation. 然后,您可以实例化TCPDF实例,并根据文档使用它。

Here's an example of a method that you could add to a controller that would construct a very simple PDF file and send it to the browser for download: 下面是一个方法示例,您可以将其添加到控制器中,该控制器将构建一个非常简单的PDF文件并将其发送到浏览器进行下载:

public function getPdftest()
{
    $pdf = new TCPDF();

    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->AddPage();
    $pdf->Text(90, 140, 'This is a test');
    $filename = storage_path() . '/test.pdf';
    $pdf->output($filename, 'F');

    return Response::download($filename);
}

To install TCPDF, add this in your composer.json file require block, 要安装TCPDF,请在composer.json文件require块中添加它,

"laurentbrieu/tcpdf": "dev-master"

Now it looks like, 现在看起来像,

....

"require": {
        "laravel/framework": "4.0.*",
        "laurentbrieu/tcpdf": "dev-master"
    },
......

Then update using composer, run the following in your project root. 然后使用composer进行更新,在项目根目录中运行以下命令。

composer update

Now you can call TCPDF functions in your laravel project by adding alias. 现在,您可以通过添加别名来调用laravel项目中的TCPDF函数。

See this for more details - https://packagist.org/packages/laurentbrieu/tcpdf 有关更多详细信息,请参阅此处 - https://packagist.org/packages/laurentbrieu/tcpdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM