#### What Will I Learn? In this tutorial you will learn - How to install/add a package in your laravel project. - Create PDFs in your web system. #### What do you need? Requirements - A Laravel version > 5.0 installed. - Basic programming and architecture MVC knowledges. - Text editor (Atom, Sublime Text, etc)... - XAMPP (local server). - CSS and HTML knowledge. #### Difficulty - Intermediate #### Preliminary There are web systems that need generates documents, cards, registrations or custom templates to users. <br> DomPDF is a package created and developed by Barryvdh that allows generate pdfs, just display in browser or download. #### Install package: First open **“composer.json”** file of your project and add in section require the next line: <br> **"barryvdh/laravel-dompdf": "^0.8.2",** <center>  <h6> You could use another DomPdf version greater than 0.6 </h6> </center> <br> Then, open terminal or console and go to the root directory of project. In my case:  <h6> cd C:\xampp\htdocs\consultoria </h6> <br> Run the following command <h5> $ composer update </h5>  <h6> $ means instructions to run in console. </h6> > This command checks if there are new dependencies in the file composer.json and update your system/application. Go to <strong>“config” </strong> folder, later open <strong> “app.php” </strong> file and write in service “providers” <h6> Barryvdh\DomPDF\ServiceProvider::class, </h6>  >Providers enables that new class in application's service container. <br> In the same file <strong> “app.php” </strong> in <strong> “aliases" </strong> section, add this line about facade: <h6> 'PDF' => Barryvdh\DomPDF\Facade::class, </h6>  ### Creating PDFs: After to prepare the environment, your system is ready to generate pdfs. #### Using a controller: 1. Create a route to a function that generates the pdfs, remember <h6>Route::get('name_of_your_route/{your_parameters}','name_of_controller@controllers_method'); </h6>  The method in your controller should be  <h6> public function pdf($your_parameters) <br> { <br> $variables=$your_parameters; <br> $pdf=PDF::loadView(‘views_name’,compact(‘$variables)); <br> return $pdf->stream(‘pdf’); <br> } </h6> We need declare a variable of type PDF. This variable is responsible to generate a PDF of our view. In the App variable (pdf) is necessary include another data that user requests since a form or to the database, **compact** is the word used, compact creates an array with values. Some people use “with” but in my case it doesn’t work properly. <br> In last setence is used the method <strong>stream</strong> to encodes the display of PDF in your browser without download. If you prefer download replace stream for download. <h6> #### Considerations: - When you create a blade view for a pdf, you should only write html and css setences. Don’t include javascript or css frameworks.  <h6>My view </h6> #### Result PDF: - The access to the pdf since browser using your route: **localhost/name_of_your_project/public/name_of_your_route**  <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@angelggomz/how-to-create-pdfs-in-laravel-with-dompdf">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>
author | angelggomz | ||||||
---|---|---|---|---|---|---|---|
permlink | how-to-create-pdfs-in-laravel-with-dompdf | ||||||
category | utopian-io | ||||||
json_metadata | {"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":1863329,"name":"laravel","full_name":"laravel/laravel","html_url":"https://github.com/laravel/laravel","fork":false,"owner":{"login":"laravel"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","programming","php","laravel","technology"],"users":["controllers","angelggomz"],"links":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1521931786/twqwvhqnv3ulxlre1zhx.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521931747/qwqhlguyccg0wcqmdlpq.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521931941/mt1nkq5kpfznooqbtavr.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521932350/sqy6fuk2mpnm2uzztuvk.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521932965/bbynxizarynifwbtak7f.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521933395/szbtq6lmwsd29rdrumjm.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521933710/hdkc72psjabjhexfr9xq.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521937470/j6imdmh9zoh4qtx8fpxu.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521939251/v3ldd0opzunpocoihdpo.png"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1521931786/twqwvhqnv3ulxlre1zhx.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521931747/qwqhlguyccg0wcqmdlpq.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521931941/mt1nkq5kpfznooqbtavr.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521932350/sqy6fuk2mpnm2uzztuvk.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521932965/bbynxizarynifwbtak7f.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521933395/szbtq6lmwsd29rdrumjm.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521933710/hdkc72psjabjhexfr9xq.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521937470/j6imdmh9zoh4qtx8fpxu.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521939251/v3ldd0opzunpocoihdpo.png"],"moderator":{"account":"miguepersa","time":"2018-03-25T17:32:53.287Z","flagged":true,"reviewed":false,"pending":false},"questions":[],"score":null} | ||||||
created | 2018-03-25 03:07:30 | ||||||
last_update | 2018-03-25 17:32:54 | ||||||
depth | 0 | ||||||
children | 5 | ||||||
last_payout | 2018-04-01 03:07:30 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.073 HBD | ||||||
curator_payout_value | 0.010 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 4,186 | ||||||
author_reputation | 675,554,169,735 | ||||||
root_title | "How to create PDFs in Laravel with DomPDF" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 46,431,497 | ||||||
net_rshares | 42,234,799,775 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
zenkly | 0 | 9,843,340,347 | 100% | ||
elbauldeolc | 0 | 3,197,546,169 | 100% | ||
zapper | 0 | 124,537,983 | 1% | ||
mario-trivelli | 0 | 1,204,873,560 | 100% | ||
angelggomz | 0 | 675,445,684 | 100% | ||
crypaf | 0 | 582,548,671 | 100% | ||
alexos | 0 | 73,464,294 | 16% | ||
ths | 0 | 588,147,396 | 100% | ||
mamicco | 0 | 1,215,779,868 | 100% | ||
andreacrangel | 0 | 599,978,728 | 100% | ||
mosqueteros | 0 | 22,826,846,279 | 32% | ||
malchut | 0 | 83,086,300 | 50% | ||
ryanmiswat | 0 | 640,971,901 | 100% | ||
carlosjgomez | 0 | 578,232,595 | 100% |
Excelente explicación mi estimado Angel. Te felicito por dominar estos temas. Un fuerte abrazo desde Chile!!!!
author | mario-trivelli |
---|---|
permlink | re-angelggomz-how-to-create-pdfs-in-laravel-with-dompdf-20180329t143125294z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-03-29 14:31:27 |
last_update | 2018-03-29 14:31:27 |
depth | 1 |
children | 0 |
last_payout | 2018-04-05 14:31:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 110 |
author_reputation | 10,127,226,324,505 |
root_title | "How to create PDFs in Laravel with DomPDF" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 47,287,472 |
net_rshares | 0 |
Your contribution cannot be approved because it does not follow the [Utopian Rules](https://utopian.io/rules). - Your post is a machine translated version of <a href="https://styde.net/generar-pdf-en-laravel-5-1-con-dompdf/">THIS</a> tutorial. You can contact us on [Discord](https://discord.gg/uTyJkNm). **[[utopian-moderator]](https://utopian.io/moderators)**
author | miguepersa |
---|---|
permlink | re-angelggomz-how-to-create-pdfs-in-laravel-with-dompdf-20180325t173518063z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"} |
created | 2018-03-25 17:35:27 |
last_update | 2018-03-26 19:22:39 |
depth | 1 |
children | 3 |
last_payout | 2018-04-01 17:35:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.696 HBD |
curator_payout_value | 0.229 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 363 |
author_reputation | 295,179,405,283 |
root_title | "How to create PDFs in Laravel with DomPDF" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 46,542,758 |
net_rshares | 361,016,584,582 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
miguepersa | 0 | 612,421,336 | 100% | ||
utopian.tip | 0 | 360,404,163,246 | 35.47% |
Hey @miguepersa, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
author | utopian.tip |
---|---|
permlink | re-re-angelggomz-how-to-create-pdfs-in-laravel-with-dompdf-20180325t173518063z-20180325t194236 |
category | utopian-io |
json_metadata | "" |
created | 2018-03-25 19:42:36 |
last_update | 2018-03-25 19:42:36 |
depth | 2 |
children | 2 |
last_payout | 2018-04-01 19:42:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 160 |
author_reputation | 238,310,597,885 |
root_title | "How to create PDFs in Laravel with DomPDF" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 46,560,954 |
net_rshares | 566,489,736 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
miguepersa | 0 | 566,489,736 | 100% |
I was student with styde.net, but if you read my tutorial the only thing similar is the installation process and it is for obvious reasons.
author | angelggomz |
---|---|
permlink | re-utopiantip-re-re-angelggomz-how-to-create-pdfs-in-laravel-with-dompdf-20180325t194236-20180326t215850207z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-03-26 21:58:51 |
last_update | 2018-03-26 21:58:51 |
depth | 3 |
children | 1 |
last_payout | 2018-04-02 21:58:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 139 |
author_reputation | 675,554,169,735 |
root_title | "How to create PDFs in Laravel with DomPDF" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 46,775,640 |
net_rshares | 0 |