peternbenke/pb-pdf

用于各种用途的PDF生成

安装次数: 123

依赖关系: 0

建议者: 0

安全性: 0

星标: 1

关注者: 3

分支: 1

开放问题: 1

类型:typo3-cms-extension

11.5.3 2023-07-28 08:32 UTC

This package is auto-updated.

Last update: 2024-09-28 10:59:40 UTC


README

1 描述

用于各种用途的PDF生成

2 安装

使用Composer安装

推荐使用Composer来安装扩展。

在您的基于Composer的TYPO3项目中运行以下命令

composer require peterbenke/pb-pdf

从TYPO3扩展存储库(TER)安装作为扩展

使用扩展管理模块下载并安装扩展。

3 使用方法

PHP文件

<?php
namespace [YourVendor]\[YourExtension]\[...];


use PeterBenke\Pdf\Service\PdfService;
use TYPO3\CMS\Core\Utility\GeneralUtility;


class YourClass
{

  public function yourFunction()
  {
  
  
    $absoluteJobPdfPath = '/var/www/html/fileadmin/user_upload/your-pdf-file.pdf';
    $assign = [];
  
    // Create instance
  
    /** @var PdfService $pdfService */
    $pdfService = GeneralUtility::makeInstance(
        PdfService::class,
        'your_extension_key', // extension key
        '/Resources/Private/Templates/Pdf/your-template.html', // template path
        $absoluteJobPdfPath,  // absolute! pdf path to pdf file
        null,                 // tmp directory, if empty => '/tmp' will be set
        $assign               // optional assign array (fluid)
    );
    
    // Create pdf file
    
    try{
        $pdfService->create();
    }catch(Exception $e){
        echo $e->getMessage();
    }
    
  
  }

}

模板

<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>{title}</title>
	<link rel="stylesheet" type="text/css" href="[absolute_path_to_css_file]" />
</head>
<body>
...
</body>
</html>