{"id":176,"date":"2022-06-22T20:48:00","date_gmt":"2022-06-22T11:48:00","guid":{"rendered":"https:\/\/www.agathion.net\/?p=176"},"modified":"2024-02-18T16:23:46","modified_gmt":"2024-02-18T07:23:46","slug":"laravel9-dompdf","status":"publish","type":"post","link":"https:\/\/www.agathion.net\/?p=176","title":{"rendered":"Laravel9 + domPDF"},"content":{"rendered":"\n<p>\u696d\u52d9\u3067domPDF\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u304c\u3001\u30ea\u30ea\u30fc\u30b9\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u82e5\u5e72\u624b\u9806\u304c\u9055\u3046\u306e\u304b\u3001\u8907\u6570\u30b5\u30a4\u30c8\u3067\u60c5\u5831\u304c\u5fae\u5999\u306b\u7570\u306a\u3063\u3066\u3044\u305f\u3002\u3042\u3061\u3053\u3061\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u305f\u306e\u3067\u3001\u79c1\u306e\u8a66\u3057\u305f\u65b9\u6cd5\u3082\u4e00\u4f8b\u3068\u3057\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u25a0 \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n\n\n\n<p>\u30e9\u30a4\u30d6\u30e9\u30ea\u306fcomposer\u30b3\u30de\u30f3\u30c9\u306e\u307f\u3067\u3059\u3002config\/app.php \u306a\u3069\u306e\u8ffd\u8a18\u306f\u3057\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u6700\u5f8c\u306b\u300ccomposer dump-autoload\u300d\u306f\u5b9f\u65bd\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer require barryvdh\/laravel-dompdf<\/code><\/pre>\n\n\n\n<p>\u30d5\u30a9\u30f3\u30c8\u3092Web\u30b5\u30a4\u30c8\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u914d\u7f6e\u3057\u307e\u3059\u3002\u79c1\u306f<a href=\"https:\/\/moji.or.jp\/ipafont\/ipaex00401\/\" target=\"_blank\" rel=\"noopener\">IPAex\u30d5\u30a9\u30f3\u30c8<\/a>\u3092\u5229\u7528\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u30d5\u30a9\u30f3\u30c8\u3092\u300cstorage\/fonts\u300d\u3092\u4f5c\u6210\u3057\u3066\u914d\u7f6e\u3057\u307e\u3059\u3002Linux\u3067 fonts\u30d5\u30a9\u30eb\u30c0\u3092777\u6a29\u9650\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4e0b\u8a18\u306e\u30b3\u30de\u30f3\u30c9\u3067domPDF\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb(config\/dompdf.php)\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan vendor:publish --provider=\"Barryvdh\\DomPDF\\ServiceProvider\"<\/code><\/pre>\n\n\n\n<p>config\/dompdf.php \u3067\u306f\u3001\u30d5\u30a9\u30f3\u30c8\u306e\u57cb\u3081\u8fbc\u307f\u8a2d\u5b9a\u3060\u3051\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>enable_font_subsetting = false<\/code><\/pre>\n\n\n\n<p>dompdf\u3092\u4f7f\u3063\u305f\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u30d5\u30a9\u30f3\u30c8\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u5f53\u521d\u306f\u3001\u30d5\u30a9\u30f3\u30c8\u30d5\u30a1\u30a4\u30eb\u3068\u30ad\u30e3\u30c3\u30b7\u30e5\u3067\u968f\u6642\u4f5c\u3089\u308c\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u30d5\u30a9\u30eb\u30c0\u3092\u5206\u3051\u3088\u3046\u3068font_cache\u306e\u8a2d\u5b9a\u3092\u5909\u66f4\u3057\u3066\u307f\u305f\u306e\u3067\u3059\u304c\u3001fonts\u30d5\u30a9\u30eb\u30c0\u306b\u4f5c\u3089\u308c\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u3082\u3042\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u306f\u9055\u3044\u307e\u3059\u304c\u30012\u7b87\u6240\u306b\u968f\u6642\u4f5c\u3089\u308c\u308b\u30d5\u30a1\u30a4\u30eb\u304c\u3067\u304d\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306b\u623b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u25a0 \u5b9f\u88c5\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public function testDompdf(Request $request) {\r\n\r\n    \/\/ \u30c0\u30df\u30fc\u30c7\u30fc\u30bf\r\n    $list = array();\r\n    for ($i=0;$i&lt;50;$i++) {\r\n        $list&#91;] = $i;\r\n    }\r\n\r\n    $pdf = \\PDF::loadView('dompdf_sample', &#91;'sample_list' => $list]);\r\n    \/\/ \u30d6\u30e9\u30a6\u30b6\u8868\u793a\r\n    return $pdf->stream('dispname.pdf');\r\n\r\n    \/\/ \u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\r\n    \/\/ return $pdf->download();\r\n}\r<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;html lang=\"ja\">\r\n    &lt;head>\r\n        &lt;title>dompdf-sample&lt;\/title>\r\n        &lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\"\/>\r\n        &lt;style>\r\n            @font-face{\r\n                font-family: ipaexm;\r\n                font-style: normal;\r\n                font-weight: normal;\r\n                src: url(\"{{ storage_path('fonts\/ipaexm.ttf')}}\") format('truetype');\r\n            }\r\n            body {\r\n                font-family: ipaexm !important;\r\n            }\r\n        &lt;\/style>\r\n    &lt;\/head>\r\n    &lt;body>\r\n        &lt;h2>domPDF\u306e\u51fa\u529b\u30b5\u30f3\u30d7\u30eb&lt;\/h2>\r\n\r\n        &lt;div>\u6587\u5b57\u3092\u51fa\u529b&lt;\/div>\r\n       \r\t\u30c6\u30fc\u30d6\u30eb\u3092\u51fa\u529b\r\n        &lt;table>\r\n            &lt;tr>\r\n                &lt;th>\u5217\u898b\u51fa\u3057&lt;\/th>\r\n            &lt;\/tr>\r\n            @foreach ($sample_list as $value)\r\n            &lt;tr>\r\n                &lt;td>{{ $value }}&lt;\/td>\r\n            &lt;\/tr>\r\n            @endforeach\r\n        &lt;\/table>\r\n    &lt;\/body>\r\n&lt;\/html><\/code><\/pre>\n\n\n\n<p>\u5b9f\u88c5\u30b5\u30f3\u30d7\u30eb\u306e\u7d30\u304b\u3044\u8aac\u660e\u306f\u7701\u304d\u307e\u3059\u304c\u3001\u306a\u308b\u3079\u304f\u6700\u5c0f\u9650\u306e\u5b9f\u4f8b\u3068\u3057\u3066\u3044\u308b\u3064\u3082\u308a\u3067\u3059\u3002HTML\u5185\u306b@font-face\u3092\u8a18\u8f09\u3057\u306a\u3044\u5b9f\u88c5\u4f8b\u3082\u898b\u304b\u3051\u307e\u3057\u305f\u304c\u3001\u79c1\u306f\u66f8\u304b\u306a\u3044\u3068\u65e5\u672c\u8a9e\u304c\u3046\u307e\u304f\u8868\u793a\u3055\u308c\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u307e\u305f\u3001return view()\u3092\u5229\u7528\u3057\u305f\u30b5\u30a4\u30c8\u3082\u3042\u308a\u307e\u3057\u305f\u304c\u3001PDF\u306b\u306a\u3089\u306a\u304b\u3063\u305f\u306e\u3067$pdf->stream\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u696d\u52d9\u3067domPDF\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u304c\u3001\u30ea\u30ea\u30fc\u30b9\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u82e5\u5e72\u624b\u9806\u304c\u9055\u3046\u306e\u304b\u3001&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-it","wpcat-2-id"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.agathion.net\/index.php?rest_route=\/wp\/v2\/posts\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.agathion.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.agathion.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.agathion.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.agathion.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176"}],"version-history":[{"count":1,"href":"https:\/\/www.agathion.net\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":177,"href":"https:\/\/www.agathion.net\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions\/177"}],"wp:attachment":[{"href":"https:\/\/www.agathion.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.agathion.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.agathion.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}