du512053619 2017-03-14 18:59
浏览 1724
已采纳

使用composer的TCPDF hello world示例

What is the minimum "hello world" example for TCPDF?

I see over 60 examples at https://tcpdf.org/examples/ and none of them work with composer and they are all very complicated.

I'm looking for something simple so I can start learning off of that.

  • 写回答

1条回答 默认 最新

  • dousikuai5417 2017-11-19 17:46
    关注

    The title of the post specifies that they want to use TCPDF with Composer and I found that the accepted answer does not utilize Composer to do this.

    First, include TCPDF in Composer. Add the following code to your composer.json file:

    "require": {
        "tecnickcom/tcpdf": "^6.2.13"
    }
    

    If there is an existing composer.lock file in the directory, then run from the command-line:

    composer install
    

    Otherwise, run from the command-line:

    composer update
    

    Create a PHP file with the following code:

    <?php
    // Load autoloader (using Composer)
    require __DIR__ . '/vendor/autoload.php';
    $pdf = new TCPDF();                 // create TCPDF object with default constructor args
    $pdf->AddPage();                    // pretty self-explanatory
    $pdf->Write(1, 'Hello world');      // 1 is line height
    
    $pdf->Output('hello_world.pdf');    // send the file inline to the browser (default).
    
    ?>
    

    Open this page from your web browser and you should see an example PDF document saying Hello World.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序