vrok/tex-wrapper
Composer 安装命令:
composer require vrok/tex-wrapper
包简介
PDFLatex wrapper class
README 文档
README
PHP class wrapping calls to PDFLaTeX/LuaLaTeX to generate PDF files from LaTeX generated by PHP itself.
Requires pdflatex/lualatex or another engine to be installed, e.g. in Debian package texlive-latex-base.
Usage
// autogenerate filename for TeX file in temp dir $wrapper = new TexWrapper\Wrapper(); // use existing TeX or store in custom path. // the resulting PDF will have the same filename with ".pdf" appended $wrapper = new TexWrapper\Wrapper('/my/path/texfile'); // generate the TeX file $texContent = '\documentclass{article} \begin{document} \title{Introduction to \LaTeX{}} \author{Author Name} \maketitle \section{Introduction} Here is the text of your introduction. \end{document}'; $wrapper->saveTex($texContent); // to customize log output or apply texfot to filter unnecessary messages $wrapper->setCommand('texfot '.$wrapper->getCommand().' 2>&1'); // to use lualatex instead of pdflatex $cmd = 'lualatex --file-line-error ' .' --interaction=nonstopmode --output-directory=%dir% %file%'; $wrapper->setCommand($cmd); // build PDF file in the same path where the TeX file lives $result = $wrapper->buildPdf(); if ($result) { echo "PDF file ".$wrapper->getPdfFile()." was created!"; } else { echo "PDF file wasn't generated!"; } // even when the PDF was generated there could be errors and the latex engine // or the post-processing command exited with an error code > 0 // getErrors() returns an array, possible indexes are: engine, missingFonts, // postProcessor var_dump($wrapper->getErrors()); // pdflatex always generates output, some warnings like missing fonts do not // generate errors, the output is always saved: var_dump($wrapper->getLog()); // returns string // if you don't need the TeX file anymore // it is automatically deleted on Wrapper destruction if no initial filename // was set $wrapper->deleteTex();
Post-Processing
To apply post-processing to the created PDF, e.g. to reduce file size use
postProcess($cmd).
The command must keep the PDF file in place, else postProcess will return false.
The placeholder %file% points to the previously created PDF file, %dir% to the
containing folder.
// Example: use ghostscript (debian package: ghostscript) to minimize PDF file // size. Test first: very simple documents can get larger through this! $postProcessor = 'gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4' .' -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH' .' -dDetectDuplicateImages -dCompressFonts=true -r150' .' -sOutputFile=%file%.tmp %file% && mv %file%.tmp %file%'; $result = $wrapper->postProcess($postProcessor); if ($result) { echo "post-processed ".$wrapper->getPdfFile(); } else { echo "post-processing failed!"; $errors = $wrapper->getErrors(); var_dump($errors['postProcessor']); }
Note on texfot
Texfot tries to remove unnecessary lines from the LaTeX engine output. But while pdflatex/lualatex outputs everything including all errors to the stdout, texfot writes errors to stderr, so we have to include them in stdout by using "2>&1" in the command for the wrapper to log them. Texfot uses the temporary file /tmp/fot which is not deleted after execution so it can cause errors when used by different users which can not write the others files.
Note on LuaLaTeX
The lualatex command requires access to a working directory in $HOME, e.g. $HOME/.texlive2017, depending on the installation and version. Make sure to create it for the user executing PHP before using the script.
vrok/tex-wrapper 适用场景与选型建议
vrok/tex-wrapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 92 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wrapper」 「latex」 「pdflatex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vrok/tex-wrapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vrok/tex-wrapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vrok/tex-wrapper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LaTeX formula to PNG
PHP library for (La)TeX abstraction
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
gv config package
pdflatex bundle
统计信息
- 总下载量: 92
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-09