After checking my inability to print in PDF, I looked for other ways to print documents. A feasible option is to use the docx files, from Microsoft Word. I did this test:
public function imprimirWord(Juego $j){
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$text = $section->addText('Juego Nº '.$j->numero.': '.$j->nombre,array('name'=>'Arial','size' => 15,'bold' => true));
$text = $section->addText($j->nombre);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('Prueba.docx');
return response()->download(public_path('Prueba.docx'));
}
And so I get a docx file! But I've run into a crazy rush. I have this view with what you have to print:
@extends('layouts.app')
<html lang="es">
<body>
<font size="15" style="display: inline;">Juego Nº {{$j->numero}}: {{$j->nombre}}</font> <img style="width: 90px; height: 90px;" align="right" src="{{url($j->ruta())}}"/>
<hr>
<div class="row justify-content-center">
<div class="col-md-5 card card-1">
<div class="card-body">
<p><b>Materiales:</b> {{$j->materiales}}</p><br>
<p><b>Agrupación de los jugadores:</b> {{$j->agrupacion->nombre}}</p><br>
<h3>Organización:</h3>
<p class="badge-primary" style="float: left; padding-left: 5px; padding-right: 4px; border-radius: 5px;">{{$j->organizacion}}</p>
<br><br><br>
<h3>Desarrollo del juego</h3>
<p class="badge-primary" style="float: left; padding-left: 5px; padding-right: 4px; border-radius: 5px;">{{$j->desarrollo}}</p>
@if($j->observaciones!="*")
<br><br>
<h3>Reglas y observaciones:</h3>
<p class="badge-primary" style="float: left; padding-left: 5px; padding-right: 4px; border-radius: 5px;">{{$j->observaciones}}</p>
@endif
@if($j->variantes!="*")
<br><br>
<h3>Variantes:</h3>
<p class="badge-primary" style="float: left; padding-left: 5px; padding-right: 4px; border-radius: 5px;">{{$j->variantes}}</p>
@endif
<?php
$contenidos=$j->enlaces;
?>
@if(count($contenidos))
<br><br><br>
<h3>Contenidos:</h3>
@foreach($contenidos as $contenido)
<span class="badge badge-cat badge-info">{{$contenido->contenido->nombre}}</span>
@endforeach
@endif
</div>
</div>
</div>
</body>
</html>
However, in the tutorials I found, the Word file is always generated manually. Never helped by views like this. Is there any way to use this view to create a .docx file?