smnandre / pandoc
Pandoc PHP - Document Converter for Mardown, HTML, Latex, PDF, RST
Fund package maintenance!
smnandre
Requires
- php: ^8.3
- psr/log: ^2.0 || ^3.0
- symfony/process: ^7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.65
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.5
- symfony/var-dumper: ^7.2
README
Pandoc PHP - Advanced Document Converter
Markdown - HTML - PDF - DOCX - RST - LaTeX - Reveal Slides
This PHP library offers a modern PHP wrapper for the Pandoc document converter.
Installation
composer require smnandre/pandoc
Basic Usage
Convert single file
use Pandoc\Options; use Pandoc\Pandoc; use Symfony\Component\Finder\Finder; // 1. Convert a single file with options: $options = Options::create() ->setInput(['input.md']) ->setOutput('output.pdf') ->setFormat('pdf') ->tableOfContent(); Pandoc::create()->convert($options);
Convert multiple files using Finder
$finder = Finder::create()->files()->in('docs')->name('*.md'); $options = Options::create() ->setInput($finder) ->setOutputDir('output') ->setFormat('html'); Pandoc::create()->convert($options); ## Options ### Default Options ```php $defaultOptions = Options::create() ->setFormat('html') ->tableOfContent(); $pandoc = Pandoc::create(defaultOptions: $defaultOptions);
Override default options
Use default options, override output for this specific file:
$options = Options::create()->setInput(['chapter1.md'])->setOutput('chapter1.html'); $pandoc->convert($options);
Advanced Options
$defaultOptions = Options::create() ->setInput(Finder::create()->files()->in('docs')->name('*.md')) ->setOutputDir('output') ->setFormat('html'); $pandoc = Pandoc::create(null, $defaultOptions); $pandoc->convert(Options::create()); // Will use default options
Input / Output
Default Output
$options = Options::create() ->setInput(['input.md']) ->setFormat('html') ->tableOfContent(); Pandoc::create()->convert($options);
Technical Details
Formats
- list input formats
- list output formats
Resources
Pandoc
Pandoc Docker
GitHub Actions
Any contribution is welcome!
Suggestions
You can suggest new features or improvements by opening an RFC or a Pull Request on the GitHub repository of Pandoc PHP.
Issues
If you encounter any issues, please open an issue on the GitHub repository of Pandoc PHP.
Testing
Before submitting a Pull Request, make sure to run the following commands, and that they all pass.
If you have any questions, feel free to ask on the GitHub repository of Pandoc PHP.
php vendor/bin/php-cs-fixer check php vendor/bin/phpstan analyse php vendor/bin/phpunit
Pandoc PHP is maintained by Simon André
Pandoc is a project by John MacFarlane and contributors.## Contributing
Credits
License
This project is licensed under the MIT License - see the LICENSE file for details.