简体   繁体   English

使用Composer的TCPDF Hello世界示例

[英]TCPDF hello world example using composer

What is the minimum "hello world" example for TCPDF? TCPDF的最小“ hello world”示例是什么?

I see over 60 examples at https://tcpdf.org/examples/ and none of them work with composer and they are all very complicated. 我在https://tcpdf.org/examples/上看到了60多个示例,但它们都不能与作曲家一起使用,而且它们都很复杂。

I'm looking for something simple so I can start learning off of that. 我正在寻找简单的东西,因此我可以开始学习。

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. 该帖子的标题指定他们希望将TCPDF与Composer一起使用,而我发现接受的答案没有利用Composer来执行此操作。

First, include TCPDF in Composer. 首先,在Composer中包含TCPDF。 Add the following code to your composer.json file: 将以下代码添加到您的composer.json文件:

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

If there is an existing composer.lock file in the directory, then run from the command-line: 如果目录中存在现有的composer.lock文件,请从命令行运行:

composer install

Otherwise, run from the command-line: 否则,请从命令行运行:

composer update

Create a PHP file with the following code: 使用以下代码创建一个PHP文件:

<?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. 从网络浏览器打开此页面,您应该看到一个示例PDF文档,上面写着Hello World。

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

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