File.php 725 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace app\common;
  3. //use Barryvdh\DomPDF\Facade\Pdf;
  4. use Dompdf\Dompdf;
  5. class File
  6. {
  7. public static function exportPdf($content, $fileName)
  8. {
  9. $dompdf = new Dompdf();
  10. $dompdf->loadHtml($content);
  11. $dompdf->setPaper('A4', 'portrait');
  12. $dompdf->render();
  13. $pdfData = $dompdf->output();
  14. $savePath = public_path('storage/files/') . date('Ymd') . '/pdf';
  15. if (!is_dir($savePath)) {
  16. mkdir($savePath, 0777, true);
  17. }
  18. $filePath = $savePath . '/' . $fileName;
  19. file_put_contents($filePath, $pdfData);
  20. $url = getenv('STORAGE_DOMAIN') . '/storage/files/' . date('Ymd') . '/pdf/' . $fileName;
  21. return $url;
  22. }
  23. }