|
@@ -3,11 +3,10 @@ |
|
@@ -3,11 +3,10 @@ |
|
3
|
namespace App\Console\Commands;
|
3
|
namespace App\Console\Commands;
|
|
4
|
|
4
|
|
|
5
|
use App\Http\Controllers\File\FileController;
|
5
|
use App\Http\Controllers\File\FileController;
|
|
6
|
-use App\Models\ProjectAssociation\ProjectAssociation;
|
|
|
|
7
|
use App\Models\File\DataFile;
|
6
|
use App\Models\File\DataFile;
|
|
|
|
7
|
+use App\Models\ProjectAssociation\ProjectAssociation;
|
|
8
|
use App\Services\CosService;
|
8
|
use App\Services\CosService;
|
|
9
|
-use Dompdf\Dompdf;
|
|
|
|
10
|
-use Dompdf\Options;
|
9
|
+use Barryvdh\DomPDF\Facade\Pdf;
|
|
11
|
use Illuminate\Console\Command;
|
10
|
use Illuminate\Console\Command;
|
|
12
|
use Illuminate\Http\File;
|
11
|
use Illuminate\Http\File;
|
|
13
|
|
12
|
|
|
@@ -57,6 +56,17 @@ class ProjectFilePDF extends Command |
|
@@ -57,6 +56,17 @@ class ProjectFilePDF extends Command |
|
57
|
parent::__construct();
|
56
|
parent::__construct();
|
|
58
|
}
|
57
|
}
|
|
59
|
|
58
|
|
|
|
|
59
|
+// public function handle()
|
|
|
|
60
|
+// {
|
|
|
|
61
|
+// $project_data = [];
|
|
|
|
62
|
+// $html = $this->html($project_data);
|
|
|
|
63
|
+// $filename = hash('md5', $this->time . '-' . '$project_id' . '-' . '$friend_id' . '-' . '$user_id');
|
|
|
|
64
|
+// $this->savePDF($html, $filename);
|
|
|
|
65
|
+//// $this->testStreamPdf($html, $filename);
|
|
|
|
66
|
+//// $file_path = $this->savePDF2($html, $filename);
|
|
|
|
67
|
+// return 0;
|
|
|
|
68
|
+// }
|
|
|
|
69
|
+
|
|
60
|
public function start(): int
|
70
|
public function start(): int
|
|
61
|
{
|
71
|
{
|
|
62
|
# 0 - 未生成
|
72
|
# 0 - 未生成
|
|
@@ -115,37 +125,21 @@ class ProjectFilePDF extends Command |
|
@@ -115,37 +125,21 @@ class ProjectFilePDF extends Command |
|
115
|
*/
|
125
|
*/
|
|
116
|
public function savePDF($html, $filename)
|
126
|
public function savePDF($html, $filename)
|
|
117
|
{
|
127
|
{
|
|
118
|
-
|
|
|
|
119
|
$pdf_path = public_path('PDF/');
|
128
|
$pdf_path = public_path('PDF/');
|
|
120
|
if (!file_exists($pdf_path)) {
|
129
|
if (!file_exists($pdf_path)) {
|
|
121
|
mkdir($pdf_path, 0777, true);
|
130
|
mkdir($pdf_path, 0777, true);
|
|
122
|
}
|
131
|
}
|
|
123
|
-
|
|
|
|
124
|
// 指定保存路径和文件名
|
132
|
// 指定保存路径和文件名
|
|
125
|
$savePath = $pdf_path . $filename . '.pdf';
|
133
|
$savePath = $pdf_path . $filename . '.pdf';
|
|
126
|
if (file_exists($savePath)) {
|
134
|
if (file_exists($savePath)) {
|
|
127
|
echo '文件已经存在';
|
135
|
echo '文件已经存在';
|
|
128
|
-// return 0;
|
136
|
+ return 0;
|
|
129
|
}
|
137
|
}
|
|
130
|
- // todo 生成中文有问题
|
|
|
|
131
|
- # 实例化并使用dompdf类
|
|
|
|
132
|
-// $options = new Options();
|
|
|
|
133
|
-// $options->setDefaultFont('arial');
|
|
|
|
134
|
-// $dompdf = new Dompdf($options);
|
|
|
|
135
|
- $dompdf = new Dompdf();
|
|
|
|
136
|
- $dompdf->loadHtml($html);
|
|
|
|
137
|
- #(可选)设置纸张大小和方向
|
|
|
|
138
|
- $dompdf->setPaper('A4', 'landscape');
|
|
|
|
139
|
-
|
|
|
|
140
|
- # 将HTML渲染为PDF
|
|
|
|
141
|
- $dompdf->render();
|
|
|
|
142
|
-
|
|
|
|
143
|
- // 获取PDF内容
|
|
|
|
144
|
- $pdfContent = $dompdf->output();
|
|
|
|
145
|
- $path = '/V6/PDF/' . $this->time;
|
|
|
|
146
|
-
|
|
|
|
147
|
- // 将PDF内容保存到文件
|
|
|
|
148
|
- @file_put_contents($savePath, $pdfContent);
|
138
|
+
|
|
|
|
139
|
+ $pdf = PDF::loadHTML($html);
|
|
|
|
140
|
+ $pdf->save($savePath);
|
|
|
|
141
|
+
|
|
|
|
142
|
+ $path = '/V6/PDF/' . $this->time;
|
|
149
|
// 创建一个文件实例
|
143
|
// 创建一个文件实例
|
|
150
|
$file = new File($savePath);
|
144
|
$file = new File($savePath);
|
|
151
|
return $this->CosService->uploadFile($file, $path, $filename . '.pdf');
|
145
|
return $this->CosService->uploadFile($file, $path, $filename . '.pdf');
|
|
@@ -158,12 +152,7 @@ class ProjectFilePDF extends Command |
|
@@ -158,12 +152,7 @@ class ProjectFilePDF extends Command |
|
158
|
*/
|
152
|
*/
|
|
159
|
protected function html($item)
|
153
|
protected function html($item)
|
|
160
|
{
|
154
|
{
|
|
161
|
- $html = '<html>';
|
|
|
|
162
|
- $html .= '<body style="font-family:arial">';
|
|
|
|
163
|
- $html .= '<h1>Hello, World!</h1>';
|
|
|
|
164
|
- $html .= '<p>中文内容ffffff</p>';
|
|
|
|
165
|
- $html .= '</body>';
|
|
|
|
166
|
- $html .= '</html>';
|
|
|
|
167
|
- return $html;
|
155
|
+ $font_path = storage_path('fonts\msyh.ttf');
|
|
|
|
156
|
+ 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>';
|
|
168
|
}
|
157
|
}
|
|
169
|
} |
158
|
} |