mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
58 lines
1.1 KiB
PHP
Executable File
58 lines
1.1 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Jingga
|
|
*
|
|
* PHP Version 8.1
|
|
*
|
|
* @package phpOMS\Utils\Parser\Document
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 2.0
|
|
* @version 1.0.0
|
|
* @link https://jingga.app
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace phpOMS\Utils\Parser\Document;
|
|
|
|
use PhpOffice\PhpWord\IOFactory;
|
|
use PhpOffice\PhpWord\Writer\HTML;
|
|
|
|
/**
|
|
* Document parser class.
|
|
*
|
|
* @package phpOMS\Utils\Parser\Document
|
|
* @license OMS License 2.0
|
|
* @link https://jingga.app
|
|
* @since 1.0.0
|
|
*/
|
|
class DocumentParser
|
|
{
|
|
/**
|
|
* Document to string
|
|
*
|
|
* @param string $path Path
|
|
*
|
|
* @return string
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public static function parseDocument(string $path, string $output = 'html') : string
|
|
{
|
|
if ($output === 'html') {
|
|
$doc = IOFactory::load($path);
|
|
|
|
$writer = new HTML($doc);
|
|
|
|
return $writer->getContent();
|
|
} elseif ($output === 'pdf') {
|
|
$doc = IOFactory::load($path);
|
|
|
|
$writer = new DocumentWriter($doc);
|
|
|
|
return $writer->toPdfString();
|
|
}
|
|
|
|
return '';
|
|
}
|
|
}
|