Commit f7d6fb6e authored by hj's avatar hj

更新提交0

parent bbc25e68
...@@ -88,4 +88,18 @@ class MsdsController extends Controller ...@@ -88,4 +88,18 @@ class MsdsController extends Controller
} }
} }
public function viewPdf($path)
{
try{
ob_end_clean();
$file = app(FileService::class)->loadFile($path);
header('content-type: application/pdf');
echo $file;
}catch(\Throwable $exception){
dd($exception->getMessage());
$this->returnErrorExecptionResponse($exception);
}
}
} }
...@@ -35,10 +35,12 @@ class ChemicalsMsdsService ...@@ -35,10 +35,12 @@ class ChemicalsMsdsService
preg_match('/<body>[\s]*?<style>(?<bodyStyle>[\s\S]*?)<\/style>/i',$msds_html, $bodyStyle); preg_match('/<body>[\s]*?<style>(?<bodyStyle>[\s\S]*?)<\/style>/i',$msds_html, $bodyStyle);
$msds_html = preg_replace('/<body>[\s]*?<style>(?<bodyStyle>[\s\S]*?)<\/style>/i', '11123', $msds_html); $msds_html = preg_replace('/<body>[\s]*?<style>(?<bodyStyle>[\s\S]*?)<\/style>/i', '11123', $msds_html);
$bodyStyle['bodyStyle'] = "<body><style>body{ font-family: 'msyh'; font-size: 0.8rem; font-weight: bold; display: block;} " . $bodyStyle['bodyStyle']."</style></body>"; $bodyStyle['bodyStyle'] = "<style>body{ font-family: 'msyh'; font-size: 0.8rem; font-weight: bold; display: block;} " . $bodyStyle['bodyStyle']."</style><body>";
$msds_html = preg_replace('/11123/i', $bodyStyle['bodyStyle'], $msds_html); $msds_html = preg_replace('/11123/i', $bodyStyle['bodyStyle'], $msds_html);
file_put_contents('./test.html', $msds_html);
$this->getPdfApp()->loadHTML($msds_html, 'utf-8'); $this->getPdfApp()->loadHTML($msds_html, 'utf-8');
//echo $htmlTemp; //echo $htmlTemp;
$this->getPdfApp()->render(); $this->getPdfApp()->render();
......
...@@ -19,6 +19,7 @@ $api->version('v1', function($api) { ...@@ -19,6 +19,7 @@ $api->version('v1', function($api) {
$api->group(['namespace'=>'App\Http\Controllers\V1\Chemicals','middleware' => ['throttle:60,1']], function($api) { $api->group(['namespace'=>'App\Http\Controllers\V1\Chemicals','middleware' => ['throttle:60,1']], function($api) {
$api->get('/storage/download/{path}', ['uses'=>'MsdsController@downloadFile']); $api->get('/storage/download/{path}', ['uses'=>'MsdsController@downloadFile']);
$api->get('/storage/pdf/{path}', ['uses'=>'MsdsController@viewPdf']);
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment