尝试将 docx 文件转换为 pdf 时,我遇到了以下问题:当我转换一个文件时转换有效,但当我想使用 Laravel 作业转换它们时失败。
这是我在 failed_jobs 表中得到的错误:
ConvertApi\Error\Client: SSL certificate problem: unable to get local issuer certificate in C:\laragon\www\webapp_adminLTE\vendor\convertapi\convertapi-php\lib\ConvertApi\Client.php:119
这是我在控制器中调用作业的地方:
public function menusEdition(Request $request){
$menus = Menu::where('day',$request->day)->get();
foreach($menus as $menu){
$job = new MenusEdition($menu);
$this->dispatch($job);
}
return back();
}
这是我的工作课程:
<?php
namespace App\Jobs;
use App\Http\Controllers\MenusController;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class MenusEdition implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $menu;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($menu)
{
$this->menu = $menu;
}
/**
* Execute the job.
*
* @return void
*/
public function handle(MenusController $menusController)
{
$menu = $this->menu;
$menusController->templateEdition($menu->id);
return;
}
}
这是我的工作类调用的方法:
public function templateEdition($menuId)
{
$menuModel = new Menu();
$breakfast = $menuModel->getTitleMacroPerMeal($menuId,"Breakfast");
$snack1 = $menuModel->getTitleMacroPerMeal($menuId,"Snack 1");
$lunch = $menuModel->getTitleMacroPerMeal($menuId,"Lunch");
$snack2 = $menuModel->getTitleMacroPerMeal($menuId,"Snack 2");
$dinner = $menuModel->getTitleMacroPerMeal($menuId,"Dinner");
$menu = Menu::find($menuId);
$filepath = $menuModel->editMenuTemplate(
$menu,
$menu->meal_plan,
$menu->date,
$menu->customer_name,
$breakfast,
$snack1,
$lunch,
$snack2,
$dinner,
$menu->calories,
$menu->carbs,
$menu->proteins,
$menu->fats
);
$result = ConvertApi::convert('pdf', ['File' => $filepath]);
# save to file
$pdfFile = str_replace('docx','pdf',$filepath);
$result->getFile()->save($pdfFile);
$storedFile = Storage::disk('public')->putFileAs('menus', new File($pdfFile), $menu->date.'-'.$menu->customer_name.'.pdf');
return $storedFile;
}
非常感谢你们的帮助。