b13 / format
v2.1.0
2021-04-15 09:08 UTC
Requires
- php: >=5.5.0 <7.5
- phpoffice/phpspreadsheet: ^1.5
- typo3/cms-core: ^7.6.0 || ^8.7.0 || ^9.5.0 || ^10
Suggests
This package is auto-updated.
Last update: 2024-09-09 18:03:28 UTC
README
这是一个实用扩展,可以将数据以不同的格式存储,例如:
- CSV
- Excel
安装
只需使用Composer或扩展管理器安装扩展。如果您想使用PDF生成,请包括TypoScript。
用法
CSV
使用CsvService
的公共API生成CSV文件或直接输出CSV字符串。
Excel
没有包装功能来帮助创建Excel文件。但是,作为Composer依赖项,需要phpoffice/phpspreadsheet
库,因此可以在基于Composer的安装中直接使用。
PDF功能依赖于wkhtmltopdf,必须在服务器上可用。有几种提供二进制文件的方法。请参阅wkhtmltopdf文档。
该扩展提供了PdfService。以下是一个使用示例
$pdfService = GeneralUtility::makeInstance(PdfService::class);
$pdfService->setContent($myHtml);
$absolutepathToFile = $pdfService->saveToFile('myPdf');
这将创建一个myPdf.pdf
文件,其中包含$myHtml
的内容,该目录可以在TypoScript中配置。整个TypoScript配置(constants.typoscript
)
plugin.tx_format {
settings {
pdf {
// Path to the wkhtmltopdf binary
binaryFilePath = /usr/local/bin/wkhtmltopdf
// Path were the PDFs are stored
tempDirectoryPath = /tmp/
// Default file name of the generated PDF
tempFileName =
// If set the fileName will be appended with X characters of the md5 hash of the content
md5Length = 0
// Use print media-type instead of screen
printMediaTypeAttribute = 1
// Generates lower quality pdf/ps. Useful to shrink the result document space
lowQualityAttribute = 0
// Adds a html footer
footerHtmlAttribute =
// URL to render (instead of content)
url =
// Minimum font size
minimumFontSize = 15
// Set the page left margin (default 10mm)
marginLeft = 10
// Set the page right margin (default 10mm)
marginRight = 10
// Set the page top margin
marginTop = 10
// Set the page bottom margin
marginBottom = 10
// The default page size of the rendered document is A4, but using this
// --page-size optionthis can be changed to almost anything else, such as: A3,
// Letter and Legal. For a full list of supported pages sizes please see
// <http://qt-project.org/doc/qt-4.8/qprinter.html#PaperSize-enum>.
pageSize =
// Wait some milliseconds for javascript finish (default 200)
javaScriptDelay = 200
// Set orientation to Landscape or Portrait (default Portrait)
orientation = Portrait
// Whether a generated PDF should be kept at the end of the process. By default it is deleted.
persistPDF = 0
// For all supported attributes refer to https://wkhtmltopdf.org/usage/wkhtmltopdf.txt
additionalAttributes =
}
}
}
在运行时可以覆盖每个设置
$pdfService = GeneralUtility::makeInstance(PdfService::class);
$pdfService->setSettings(
[
'orientation' => 'Landscape,
'marginLeft' => 25,
'tempDirectoryPath' => PATH_site . 'something/public/'
]
);
分享我们的专业知识
查看更多我们开发的TYPO3扩展,这些扩展帮助我们为客户项目创造价值。作为我们工作方式的一部分,我们专注于测试和最佳实践,以确保所有代码的长期性能、可靠性和结果。