{"id":10791,"date":"2022-08-01T07:00:46","date_gmt":"2022-07-31T22:00:46","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=10791"},"modified":"2022-07-21T18:29:12","modified_gmt":"2022-07-21T09:29:12","slug":"%e3%80%90laravel%e3%80%91excel%e3%80%81word%e3%80%81powerpoint-%e3%81%ae%e3%82%b5%e3%83%a0%e3%83%8d%e3%82%a4%e3%83%ab%e3%82%92%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e6%99%82%e3%81%ab","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=10791","title":{"rendered":"\u3010Laravel\u3011Excel\u3001Word\u3001PowerPoint \u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u6642\u306b\u3064\u304f\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u65e5\u9803\u696d\u52d9\u3092\u9032\u3081\u3066\u3044\u308b\u3068\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u69d8\u306e\u3054\u5e0c\u671b\u306b\u6cbf\u3048\u306a\u304b\u3063\u305f\u3082\u306e\u306e\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">\u300c\u3046\u30fc\u3093\u3001\u3053\u308c\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u81ea\u5206\u3067\u3084\u3063\u3066\u307f\u305f\u3044\u300d<\/strong><\/p>\n<p>\u3068\u611f\u3058\u308b\u3082\u306e\u304c\u51fa\u3066\u3053\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3068\u3069\u306e\u3064\u307e\u308a\u300c\u30dc\u30c4\u6848\u300d\u3068\u3044\u3046\u3084\u3064\u306a\u306e\u3067\u3059\u304c\u3001\u300c\u4ed5\u69d8\u306b\u5408\u308f\u306a\u304b\u3063\u305f\u3060\u3051\u3067\u4ed6\u306e\u5834\u6240\u3067\u306f\u4f7f\u3048\u308b\u3093\u3058\u3083\u306a\u3044\u304b\u300d\u3068\u601d\u3046\u6a5f\u80fd\u306a\u306e\u3067\u3001\u8208\u5473\u304c\u51fa\u3066\u3057\u307e\u3046\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u5148\u65e5\u3082\u305d\u3046\u3044\u3063\u305f\u6a5f\u80fd\u306b\u51fa\u4f1a\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u304c\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">Excel \u3084 Word \u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u3064\u304f\u308b<\/strong><\/p>\n<p>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f\u3001<code>Laravel<\/code>\u3092\u4f7f\u3063\u3066\u300c<strong>\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3055\u308c\u305f Office \u30d5\u30a1\u30a4\u30eb\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u3064\u304f\u308b<\/strong>\u300d\u3068\u3044\u3046\u6a5f\u80fd\u3092\u3064\u304f\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u4f55\u304b\u306e\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u3089\u5b09\u3057\u3044\u3067\u3059\u3002\ud83d\ude0a\u2728<\/p>\n<p>\u203b \u305f\u3060\u3057\u3001\u4eca\u56de\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u4f5c\u6210\u306f\u30d5\u30ea\u30fc\u30bd\u30d5\u30c8\u306e<code>libreoffice<\/code>\u3092\u4f7f\u3044\u307e\u3059\u306e\u3067\u3001<span style=\"text-decoration: underline;\">\u30c7\u30b6\u30a4\u30f3\u3084\u30de\u30af\u30ed\u306a\u3069\u3092\u4f7f\u3063\u305f\u90e8\u5206\u306f\u5b8c\u74a7\u306b\u518d\u73fe\u3067\u304d\u306a\u3044<\/span>\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3042\u3089\u304b\u3058\u3081\u3054\u4e86\u627f\u304f\u3060\u3055\u3044\u3002m(_ _)m<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9809 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/11\/no_9.png\" alt=\"\" width=\"370\" height=\"220\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/11\/no_9.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/11\/no_9-300x178.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/>\u300c\u59ea\u3063\u5b50\u304c<br \/>\n\u771f\u30fb\u4e09\u570b\u7121\u53cc\u306e\u5f71\u97ff\u3067<br \/>\n\u4e09\u56fd\u5fd7\u597d\u304d\u306b\u306a\u3063\u3066\u307e\u3057\u305f\ud83d\ude06\u300d<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 9.x\u3001PHP 8.1\u3001Ubuntu 20.20<\/p>\n<h1>\u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h1>\n<p>\u307e\u305a\u3001<code>Excel<\/code>\u3084<code>Word<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u753b\u50cf\u5316\u3059\u308b\u306e\u306f\u4ee5\u4e0b\u306e\u624b\u9806\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u3044\u3063\u305f\u3093 PDF \u5316\u3059\u308b<\/li>\n<li>PDF \u3092\u753b\u50cf\u5316\u3059\u308b<\/li>\n<li>\u304a\u597d\u307f\u3067\u30b5\u30a4\u30ba\u3092\u5909\u66f4\u3059\u308b<\/li>\n<\/ol>\n<p>\u3053\u308c\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u4ee5\u4e0b\uff13\u3064\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>libreoffice\uff1a Ubuntu \u5074<\/li>\n<li>poppler-utils\uff1a Ubuntu \u5074<\/li>\n<li>Intervention\uff1a Laravel \u5074<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u3082\u3057\u304b\u3057\u305f\u3089\u3059\u3067\u306b\u5165\u3063\u3066\u308b\u304b\u3082\u3067\u3059\uff09<\/p>\n<p><b>\uff08<strong>Laravel \u5074<\/strong>\uff09<\/b><\/p>\n<pre><strong>composer require intervention\/image<\/strong><\/pre>\n<p><b>\uff08<strong>Ubuntu \u5074<\/strong>\uff09<\/b><\/p>\n<pre><strong>sudo apt install libreoffice<\/strong><\/pre>\n<pre><strong>sudo apt install poppler-utils<\/strong><\/pre>\n<p>\u203b \u306a\u304a\u3001\u5143\u3005\u306f<code>Imagick<\/code>\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001<code>PostScript<\/code>\u3092\u4f7f\u3063\u305f\u30ea\u30b9\u30af\u304c\u767a\u751f\u3059\u308b\u3068\u306e\u3053\u3068\u3067\u3001<code>poppler-utils<\/code>\u306e<code>pdftoppm<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><strong>\ud83d\udcdd \u53c2\u8003\u30da\u30fc\u30b8\uff1a<\/strong> <a href=\"https:\/\/cromwell-intl.com\/open-source\/pdf-not-authorized.html\" target=\"_blank\" rel=\"noopener\">Solution to ImageMagick &#8220;not authorized&#8221; PDF Error<\/a><\/p>\n<p>\u203b \u306a\u304a\u3001<code>Imagick<\/code>\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3059\u308b\u5834\u5408\u306f <a href=\"#imagick_config\">\u3061\u306a\u307f\u306b\uff1aImagick \u306e\u8a31\u53ef\u3092\u3059\u308b<\/a> \u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u4eca\u56de\u306f\u5206\u304b\u308a\u3084\u3059\u3044\u3068\u601d\u3044\u307e\u3057\u305f\u306e\u3067\u3001\u307e\u305a\u306f\u30eb\u30fc\u30c8\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><strong>routes\/web.php<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\n<strong>use App\\Http\\Controllers\\OfficeToImageController;<\/strong>\r\n\r\n<strong>Route::prefix('office_to_image')-&gt;controller(OfficeToImageController::class)-&gt;group(function(){<\/strong>\r\n\r\n<strong>    Route::get('create', 'create')-&gt;name('office_to_image.create');<\/strong>\r\n<strong>    Route::post('\/', 'store')-&gt;name('office_to_image.store');<\/strong>\r\n\r\n<strong>});<\/strong><\/pre>\n<h1>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:controller OfficeToImageController<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Http\/Controllers\/OfficeToImageController.php<\/strong><\/p>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Http\\Controllers;<\/strong>\r\n\r\n<strong>use Illuminate\\Http\\Request;<\/strong>\r\n<strong>use Illuminate\\Support\\Str;<\/strong>\r\n\r\n<strong>class OfficeToImageController extends Controller<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    public function create()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        return view('office_to_image.index');<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function store(Request $request)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        \/\/ \u6ce8\u610f\uff1a \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u7701\u7565\u3057\u3066\u3044\u307e\u3059\uff01<\/strong>\r\n\r\n<strong>        $file = $request-&gt;file('file');<\/strong>\r\n<strong>        $extension = $file-&gt;getClientOriginalExtension();<\/strong>\r\n<strong>        $filename = now()-&gt;format('Y-m-d') .'-'. Str::random(10) . '.' . $extension;<\/strong>\r\n<strong>        $storage_path = $file-&gt;storeAs('office', $filename);<\/strong>\r\n<strong>        $office_path = storage_path('app\/' . $storage_path);<\/strong>\r\n<strong>        $image_path = $this-&gt;convertOfficeToImage($office_path);<\/strong>\r\n\r\n<strong>        return \\Image::make($image_path)-&gt;response('png'); \/\/\u3000\u78ba\u8a8d\u306e\u305f\u3081\u4f5c\u6210\u3057\u305f\u753b\u50cf\u3092\u8868\u793a\u3059\u308b<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    private function convertOfficeToImage($office_path)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $extension = pathinfo($office_path, PATHINFO_EXTENSION);<\/strong>\r\n<strong>        $target_extensions = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'];<\/strong>\r\n\r\n<strong>        if(in_array($extension, $target_extensions, true)) {<\/strong>\r\n\r\n<strong>            $pdf_path = $this-&gt;convertOfficeToPdf($office_path);<\/strong>\r\n<strong>            return $this-&gt;convertPdfToImage($pdf_path);<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        return null;<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    private function convertOfficeToPdf($office_path)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        putenv('HOME=\/tmp'); \/\/ libreoffice \u306e\u4f5c\u696d\u30b9\u30da\u30fc\u30b9\u3068\u3057\u3066 tmp \u3092\u4f7f\u3046<\/strong>\r\n\r\n<strong>        $pdf_dir = storage_path('app\/pdf');<\/strong>\r\n<strong>        $command_parts = [<\/strong>\r\n<strong>            'libreoffice',<\/strong>\r\n<strong>            '--headless',<\/strong>\r\n<strong>            '--convert-to pdf:writer_pdf_Export',<\/strong>\r\n<strong>            '--outdir '. $pdf_dir,<\/strong>\r\n<strong>            $office_path<\/strong>\r\n<strong>        ];<\/strong>\r\n<strong>        $command = implode(' ', $command_parts);<\/strong>\r\n<strong>        exec($command);<\/strong>\r\n\r\n<strong>        $filename = pathinfo($office_path, PATHINFO_FILENAME);<\/strong>\r\n<strong>        $pdf_path = $pdf_dir . '\/' . $filename . '.pdf';<\/strong>\r\n\r\n<strong>        return file_exists($pdf_path) ? $pdf_path : null;<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    private function convertPdfToImage($pdf_path)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        if(is_null($pdf_path)) {<\/strong>\r\n\r\n<strong>            return null;<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        $filename = pathinfo($pdf_path, PATHINFO_FILENAME);<\/strong>\r\n<strong>        $save_path = storage_path('app\/images\/' . $filename); \/\/ \u6700\u5f8c\u306b\u300c.png\u300d\u306f\u3064\u3051\u306a\u3044<\/strong>\r\n<strong>        $command = 'pdftoppm '. $pdf_path .' -png -singlefile '. $save_path;<\/strong>\r\n<strong>        exec($command);<\/strong>\r\n\r\n<strong>        $image_path = $save_path .'.png';<\/strong>\r\n<strong>        $this-&gt;correctImage($image_path);<\/strong>\r\n\r\n<strong>        return file_exists($image_path) ? $image_path : null;<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    private function correctImage($image_path)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $width = 300;<\/strong>\r\n<strong>        $img = \\Image::make($image_path);<\/strong>\r\n<strong>        $img-&gt;resize($width, null, function($constraint) { \/\/ \u753b\u50cf\u3092\u30ea\u30b5\u30a4\u30ba<\/strong>\r\n\r\n<strong>            $constraint-&gt;aspectRatio();<\/strong>\r\n\r\n<strong>        });<\/strong>\r\n<strong>        $img-&gt;save();<\/strong>\r\n<strong>    }<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u306a\u304a\u3001\u3053\u306e\u4e2d\u3067\u91cd\u8981\u306a\u306e\u304c\u3001\u4ee5\u4e0b\u306e\u90e8\u5206\u3067\u3059\u3002<\/p>\n<pre><strong>putenv('HOME=\/tmp');<\/strong><\/pre>\n<p>\u3068\u3044\u3046\u306e\u3082\u3001\u3069\u3046\u3084\u3089<code>libreoffice<\/code>\u306f\u4f5c\u696d\u3092\u3059\u308b\u969b\u306b\u96a0\u3057\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308b\u3088\u3046\u306a\u306e\u3067\u3059\u304c\u3001\u305d\u306e\u6a29\u9650\u304c\u306a\u3044\u305f\u3081\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3046\uff08PDF\u3092\u4f5c\u6210\u3067\u304d\u306a\u3044\uff09\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u4ee5\u4e0b\u306ePDF\u3092\u753b\u50cf\u5316\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u306f\u3001\u30bb\u30c3\u30c8\u3059\u308b<code>$save_path<\/code>\u306b\u306f<strong>\u62e1\u5f35\u5b50\u306f\u3064\u3051\u306a\u3044<\/strong>\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u81ea\u52d5\u3067\u30b3\u30de\u30f3\u30c9\u304c\u30bb\u30c3\u30c8\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u91cd\u8907\u3057\u3066\u3057\u307e\u3046\u304b\u3089\u3067\u3059\uff09<\/p>\n<pre><strong>$command = 'pdftoppm '. $pdf_path .' -png -singlefile '. $save_path;<\/strong><\/pre>\n<h1>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u6700\u5f8c\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u9001\u4fe1\u3059\u308b\u30d5\u30a9\u30fc\u30e0\u3092\u3064\u304f\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>resources\/views\/office_to_image\/index.blade.php<\/strong><\/p>\n<pre><strong>&lt;html&gt;<\/strong>\r\n<strong>&lt;head&gt;<\/strong>\r\n<strong>    &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.0.1\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;<\/strong>\r\n<strong>&lt;\/head&gt;<\/strong>\r\n<strong>&lt;body&gt;<\/strong>\r\n<strong>    &lt;div class=\"p-5\"&gt;<\/strong>\r\n<strong>        &lt;h1&gt;Office\u30d5\u30a1\u30a4\u30eb\uff08Excel\u3001Word\u3001PowerPoint\uff09\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3066\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u30b5\u30f3\u30d7\u30eb&lt;\/h1&gt;<\/strong>\r\n<strong>        &lt;form method=\"POST\" action=\"{{ route('office_to_image.store') }}\" enctype=\"multipart\/form-data\"&gt;<\/strong>\r\n<strong>            @csrf<\/strong>\r\n<strong>            &lt;div class=\"py-4\"&gt;<\/strong>\r\n<strong>                &lt;input type=\"file\" name=\"file\"&gt;<\/strong>\r\n<strong>            &lt;\/div&gt;<\/strong>\r\n<strong>            &lt;button class=\"btn btn-primary\" type=\"submit\"&gt;\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b&lt;\/button&gt;<\/strong>\r\n<strong>        &lt;\/form&gt;<\/strong>\r\n<strong>    &lt;\/div&gt;<\/strong>\r\n<strong>&lt;\/body&gt;<\/strong>\r\n<strong>&lt;\/html&gt;<\/strong><\/pre>\n<p>\u203b \u3061\u306a\u307f\u306b\u3001\u4e45\u3057\u3076\u308a\u306b<code>Ajax<\/code>\u3067\u306f\u306a\u3044\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u3064\u304f\u3063\u305f\u306e\u3067\u3001<code>enctype=\"multipart\/form-data\"<\/code>\u3084<code>@csrf<\/code>\u306e\u3053\u3068\u3092\u3059\u3063\u304b\u308a\u5fd8\u308c\u3066\u307e\u3057\u305f\ud83d\ude05<\/p>\n<h1 id=\"imagick_config\">\u3061\u306a\u307f\u306b\uff1a\uff08\u30dc\u30c4\u6848\u306b\u3057\u305f\uff09Imagick \u306e\u8a31\u53ef\u3092\u3059\u308b<\/h1>\n<p><code>Imagick<\/code>\u306f\u521d\u671f\u72b6\u614b\u3067<code>PDF<\/code>\u3092\u6271\u304a\u3046\u3068\u3059\u308b\u3068\u3001\u300c<strong>not authorized<\/strong>\u300d\u3068\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u3046\u307e\u304f\u3044\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u3069\u3046\u3084\u3089<strong>PostScript<\/strong>\uff08\u30a2\u30c9\u30d3\u306e\u958b\u767a\u3057\u3066\u3044\u308b\u8a00\u8a9e\uff09\u306e\u5f71\u97ff\u3067PDF\u306e\u53d6\u6271\u306b\u306f\u30ea\u30b9\u30af\u304c\u4f34\u3046\u3053\u3068\u304c\u7406\u7531\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u203b \u305d\u306e\u305f\u3081\u3001\u30ea\u30b9\u30af\u3092\u3054\u7406\u89e3\u3057\u305f\u4e0a\u3067\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u307e\u305a\u306f\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u3001<\/p>\n<pre><strong>sudo vi \/etc\/ImageMagick-6\/policy.xml<\/strong><\/pre>\n<p>\u4ee5\u4e0b\u306ePDF\u90e8\u5206\u306b\u8a31\u53ef\u3092\u4e0e\u3048\u307e\u3059\u3002<\/p>\n<pre>&lt;policy domain=\"coder\" rights=\"<strong>none<\/strong>\" pattern=\"PDF\" \/&gt;<\/pre>\n<p>\u2193 \u2193 \u2193<\/p>\n<pre>&lt;policy domain=\"coder\" rights=\"<strong>read|write<\/strong>\" pattern=\"PDF\" \/&gt;<\/pre>\n<p>\u3053\u308c\u3067OK\u3067\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001<code>pdftoppm<\/code>\u3067\u753b\u50cf\u5316\u3057\u305f\u5834\u5408\u3001\u81ea\u52d5\u7684\u306b\u80cc\u666f\u306f\u767d\u306b\u306a\u308a\u307e\u3059\u304c\u3001<code>Imagick<\/code>\u306e\u5834\u5408\u306f\u900f\u904e\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u4f5c\u6210\u3057\u305f\u753b\u50cf\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>Intervention<\/code>\u306e<code>canvas<\/code>\u306a\u3069\u3092\u4f5c\u3063\u3066\u5408\u6210\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre>private function correctImage($image_path)\r\n{\r\n    $width = 300;\r\n    $img = \\Image::make($image_path);\r\n    $img-&gt;resize($width, null, function($constraint) {\r\n\r\n        $constraint-&gt;aspectRatio();\r\n\r\n    });\r\n    $height = $img-&gt;height();\r\n\r\n    <strong>$canvas = \\Image::canvas($width, $height, '#ffffff');<\/strong>\r\n<strong>    $canvas-&gt;insert($img, 'center'); \/\/ \ud83d\udc48 \u3053\u3053\u3067\u5408\u6210<\/strong>\r\n<strong>    $canvas-&gt;save($image_path);<\/strong>\r\n}<\/pre>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p>\u4eca\u56de\u4f7f\u3046\u306e\u306f\u3001\u5185\u95a3\u5e9c\u304c\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u3067\u516c\u958b\u3057\u3066\u3044\u308b\u300c<strong>\u5185\u95a3\u4eba\u4e8b\u5c40\u7d4c\u8cbb(Excel\u5f62\u5f0f\uff1a102KB)<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002<\/p>\n<p>\u53c2\u8003\u30da\u30fc\u30b8\uff1a\u00a0<a href=\"https:\/\/www.cao.go.jp\/yosan\/review_3_4.html\" target=\"_blank\" rel=\"noopener\">\u4ee4\u548c\uff13\u5e74\u5ea6\u884c\u653f\u4e8b\u696d\u30ec\u30d3\u30e5\u30fc\u30b7\u30fc\u30c8 \u6700\u7d42\u516c\u8868<\/a><\/p>\n<p>\u307e\u305a\u306f\u3001\u300c<strong>https:\/\/******\/office_to_image\/create<\/strong>\u300d\u3078\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10795\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/07\/laravel_office_to_image_1.png\" alt=\"\" width=\"569\" height=\"289\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/07\/laravel_office_to_image_1.png 569w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/07\/laravel_office_to_image_1-300x152.png 300w\" sizes=\"auto, (max-width: 569px) 100vw, 569px\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001\u5148\u307b\u3069\u306e<code>Excel<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u9078\u629e\u3057\u3001\u300c<strong>\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b<\/strong>\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001<\/p>\n<p>\u3069\u3046\u306a\u308b\u3067\u3057\u3087\u3046\u304b\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\uff1f\uff1f\uff1f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10796\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/07\/laravel_office_to_image_2.png\" alt=\"\" width=\"300\" height=\"424\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/07\/laravel_office_to_image_2.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/07\/laravel_office_to_image_2-212x300.png 212w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u30b5\u30e0\u30cd\u30a4\u30eb\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\uff08\u4e0a\u306e\u753b\u50cf\u306f\u3001\u5b9f\u969b\u306b\u4f5c\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3067\u3059\uff09<\/p>\n<p>\u6210\u529f\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p>\u203b \u306a\u304a\u3001\u3084\u306f\u308a\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u306e\u30d5\u30a1\u30a4\u30eb\u306f<code>libreoffice<\/code>\u3067\u958b\u304f\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u306e\u3067\u3046\u307e\u304f\u3044\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u3082\u3057\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u3067\u958b\u304f\u5834\u5408\u306f<code>libreoffice<\/code>\u306e<code>macro<\/code>\u3092\u66f8\u3051\u3070\u3044\u3051\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Laravel<\/code>\u3092\u4f7f\u3063\u3066<code>Office<\/code>\u30d5\u30a1\u30a4\u30eb\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u5316\u3092\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u76f4\u63a5<code>libreoffice<\/code>\u3067\u753b\u50cf\u5316\u3067\u304d\u308c\u3070\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u4e00\u65e6<code>PDF<\/code>\u3092\u631f\u3093\u3067\u3044\u308b\u306e\u3067\u624b\u9593\u3068\u3044\u3048\u3070\u624b\u9593\u3067\u3057\u305f\u304c\u3001\u307b\u307c\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u5168\u3066\u3084\u3063\u3066\u304f\u308c\u308b\u306e\u3067\u60f3\u50cf\u3057\u3066\u3044\u305f\u3088\u308a\u7c21\u5358\u306b\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u307e\u305f\u3001\u4ee5\u524d\u300c<strong>Imagick\u306f\u5371\u967a\u3067\u3059<\/strong>\u300d\u3068\u3044\u3046\u3088\u3046\u306a\u8a18\u4e8b\u3092\u8aad\u3093\u3060\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u300c<strong>\u305d\u3063\u304b\u3001\u4eca\u56de\u307f\u305f\u3044\u306a\u30d1\u30bf\u30fc\u30f3\u304b\u2757<\/strong>\u300d\u3068\u4f0f\u7dda\u56de\u53ce\u3055\u308c\u305f\u3088\u3046\u306a\u6c17\u5206\u3067\u3057\u305f\uff08\u7b11\uff09<\/p>\n<p>\u305d\u3057\u3066\u6700\u5f8c\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u4eca\u56de\u306e\u30a2\u30a4\u30c7\u30a2\u3092\u304f\u3060\u3055\u3063\u305f\uff08\u8a18\u4e8b\u306b\u3059\u308b\u3053\u3068\u3082\u4e86\u627f\u3057\u3066\u3044\u305f\u3060\u3044\u305f\uff09\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u69d8\u306b\u5fc3\u3088\u308a\u611f\u8b1d\u3067\u3059\u3002m(_ _)m<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u3084\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6068 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/>\u300c\u59ea\u3063\u5b50\u306e\u305f\u3081\u306b\u3001<br \/>\n\u4eca\u5ea6\u306f\u6226\u56fd\u7121\u53cc\uff08\u4e2d\u53e4\uff09\u3082<br \/>\n\u8cb7\u3044\u307e\u3057\u305f\ud83d\ude06\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u65e5\u9803\u696d\u52d9\u3092\u9032\u3081\u3066\u3044\u308b\u3068\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u69d8\u306e\u3054\u5e0c\u671b\u306b\u6cbf\u3048\u306a\u304b\u3063\u305f\u3082\u306e\u306e\u3001 \u300c\u3046\u30fc\u3093\u3001\u3053\u308c\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u81ea\u5206\u3067\u3084\u3063\u3066\u307f\u305f\u3044\u300d \u3068\u611f\u3058\u308b\u3082\u306e\u304c\u51fa\u3066\u3053\u306a\u3044\u3067\u3057\u3087\u3046\u304b &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=10791\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u3010Laravel\u3011Excel\u3001Word\u3001PowerPoint \u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u6642\u306b\u3064\u304f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":10800,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-10791","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/10791","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10791"}],"version-history":[{"count":6,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/10791\/revisions"}],"predecessor-version":[{"id":10799,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/10791\/revisions\/10799"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/10800"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}