|
...
|
...
|
@@ -3,11 +3,10 @@ |
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use App\Http\Controllers\File\FileController;
|
|
|
|
use App\Models\ProjectAssociation\ProjectAssociation;
|
|
|
|
use App\Models\File\DataFile;
|
|
|
|
use App\Models\ProjectAssociation\ProjectAssociation;
|
|
|
|
use App\Services\CosService;
|
|
|
|
use Dompdf\Dompdf;
|
|
|
|
use Dompdf\Options;
|
|
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Http\File;
|
|
|
|
|
|
...
|
...
|
@@ -57,6 +56,17 @@ class ProjectFilePDF extends Command |
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
// public function handle()
|
|
|
|
// {
|
|
|
|
// $project_data = [];
|
|
|
|
// $html = $this->html($project_data);
|
|
|
|
// $filename = hash('md5', $this->time . '-' . '$project_id' . '-' . '$friend_id' . '-' . '$user_id');
|
|
|
|
// $this->savePDF($html, $filename);
|
|
|
|
//// $this->testStreamPdf($html, $filename);
|
|
|
|
//// $file_path = $this->savePDF2($html, $filename);
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
public function start(): int
|
|
|
|
{
|
|
|
|
# 0 - 未生成
|
|
...
|
...
|
@@ -115,37 +125,21 @@ class ProjectFilePDF extends Command |
|
|
|
*/
|
|
|
|
public function savePDF($html, $filename)
|
|
|
|
{
|
|
|
|
|
|
|
|
$pdf_path = public_path('PDF/');
|
|
|
|
if (!file_exists($pdf_path)) {
|
|
|
|
mkdir($pdf_path, 0777, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 指定保存路径和文件名
|
|
|
|
$savePath = $pdf_path . $filename . '.pdf';
|
|
|
|
if (file_exists($savePath)) {
|
|
|
|
echo '文件已经存在';
|
|
|
|
// return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// todo 生成中文有问题
|
|
|
|
# 实例化并使用dompdf类
|
|
|
|
// $options = new Options();
|
|
|
|
// $options->setDefaultFont('arial');
|
|
|
|
// $dompdf = new Dompdf($options);
|
|
|
|
$dompdf = new Dompdf();
|
|
|
|
$dompdf->loadHtml($html);
|
|
|
|
#(可选)设置纸张大小和方向
|
|
|
|
$dompdf->setPaper('A4', 'landscape');
|
|
|
|
|
|
|
|
# 将HTML渲染为PDF
|
|
|
|
$dompdf->render();
|
|
|
|
|
|
|
|
// 获取PDF内容
|
|
|
|
$pdfContent = $dompdf->output();
|
|
|
|
$path = '/V6/PDF/' . $this->time;
|
|
|
|
|
|
|
|
// 将PDF内容保存到文件
|
|
|
|
@file_put_contents($savePath, $pdfContent);
|
|
|
|
$pdf = PDF::loadHTML($html);
|
|
|
|
$pdf->save($savePath);
|
|
|
|
|
|
|
|
$path = '/V6/PDF/' . $this->time;
|
|
|
|
// 创建一个文件实例
|
|
|
|
$file = new File($savePath);
|
|
|
|
return $this->CosService->uploadFile($file, $path, $filename . '.pdf');
|
|
...
|
...
|
@@ -158,12 +152,7 @@ class ProjectFilePDF extends Command |
|
|
|
*/
|
|
|
|
protected function html($item)
|
|
|
|
{
|
|
|
|
$html = '<html>';
|
|
|
|
$html .= '<body style="font-family:arial">';
|
|
|
|
$html .= '<h1>Hello, World!</h1>';
|
|
|
|
$html .= '<p>中文内容ffffff</p>';
|
|
|
|
$html .= '</body>';
|
|
|
|
$html .= '</html>';
|
|
|
|
return $html;
|
|
|
|
$font_path = storage_path('fonts\msyh.ttf');
|
|
|
|
return '<html><head><title>Laravel</title><meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'/><style>body{ font-family: \'msyh\'; } @font-face { font-family: \'msyh\'; font-style: normal; font-weight: normal; src: url(' . $font_path . ') format(\'truetype\'); }</style></head><body><div class=\'container\'><div class=\'content\'><p style=\'font-family: msyh, DejaVu Sans,sans-serif;\'>献给母亲的爱</p><div style=\'font-family: msyh, DejaVu Sans,sans-serif;\' class=\'title\'>Laravel 5中文测试</div><div class=\'title\'>测试三askjdhfkjasdhf</div></div></div></body></html>';
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|