Files
2026-04-28 21:14:25 +03:00

38 lines
942 B
PHP

<?php
use Barryvdh\DomPDF\Facade\Pdf;
function file_force_contents( $fullPath, $contents, $flags = 0 ){
$parts = explode( '/', $fullPath );
array_pop( $parts );
$dir = implode( '/', $parts );
if( !is_dir( $dir ) )
mkdir( $dir, 0777, true );
file_put_contents( $fullPath, $contents, $flags );
}
function pdf_create($path, $html)
{
$pdf = App::make('dompdf.wrapper');
$pdf->setPaper('A4',$j['paper']);
$pdf->setOption(['dpi' => $j['dpi'], ]);
$pdf->loadHTML($html);
$path = "$path.pdf";
Storage::delete($path);
Storage::put($path, $pdf->output());
}
function html_create($path, $html, $paper="portrait")
{
$path = "$path.html";
Storage::delete($path);
Storage::put($path, $html);
$htmlPath = "storage/documents/" . $path;
$pdfPath = str_replace(".html", ".pdf", $htmlPath);
html_to_pdf($htmlPath, $pdfPath, $paper);
unlink($htmlPath);
} ?>