运行作业时转换失败(API Convertapi:docx至pdf)

时间:2019-11-25 01:16:41

标签: laravel convertapi

尝试将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;
}

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

错误消息SSL certificate problem: unable to get local issuer certificate暗示某些CA证书丢失。我建议更新/安装根证书。

在Windows上:

以下链接可能有帮助:

https://stackoverflow.com/a/32095378/316536

http://woshub.com/updating-trusted-root-certificates-in-windows-10/

在Ubuntu上:

安装

sudo apt-get install ca-certificates

更新

sudo update-ca-certificates