Devuelve las primeras n paginas del documento pasado

This commit is contained in:
Alejandro Tasistro 2021-11-28 20:13:58 -03:00
parent bbea85bbd4
commit 20c5ac4731
5 changed files with 23 additions and 27 deletions

View File

@ -12,12 +12,13 @@ class FileUploadController extends Controller {
public function fileUploadPost(Request $request)
{
$request->validate([
'file' => 'required|mimes:pdf|max:2048',
'archivo' => 'required|mimes:pdf|max:2048',
'bookletsize' => 'min:1'
]);
$fileName = time().'.'.$request->file->extension();
$request->file->move(public_path('uploads'), $fileName);
$fileName = time().'.'.$request->archivo->extension();
$request->archivo->move(public_path('uploads'), $fileName);
return redirect()->route("process", ['fileName' => $fileName]);
return redirect()->route("process", ['fileName' => $fileName, 'size' => $request->bookletsize]);
}
}

View File

@ -3,13 +3,12 @@
namespace App\Http\Controllers;
use App\Models\Librilladora;
use Illuminate\Http\Request;
class LibrilladoraController extends Controller
{
//
public function process($fileName) {
public function __invoke($fileName, $size) {
$lib = new Librilladora();
$lib->prueba($fileName);
$lib->prueba($fileName, $size);
}
}

View File

@ -10,24 +10,20 @@ class Librilladora extends Model {
use HasFactory;
public function prueba(string $fileName) {
$mpdf = new \Mpdf\Mpdf();
// // Write some HTML code:
// $mpdf->WriteHTML($nombre);
//
// // Output a PDF file directly to the browser
// $mpdf->Output();
//
// // Require composer autoload
// require_once __DIR__ . '/vendor/autoload.php';
public function prueba($fileName, $size) {
$file = 'uploads/'.$fileName;
$mpdf->SetSourceFile($file);
$tplId = $mpdf->importPage(1);
$mpdf->useTemplate($tplId);
File::delete($file);
$mpdf = new \Mpdf\Mpdf();
$pagecount = $mpdf->SetSourceFile($file);
$fin = ($size < $pagecount) ? $size : $pagecount;
for ($i = 1; $i <= $fin; $i++) {
$tplId = $mpdf->importPage($i);
$mpdf->useTemplate($tplId);
if ($i != $fin) $mpdf->AddPage();
}
$mpdf->Output();
File::delete($file);
}
}

View File

@ -47,10 +47,10 @@
<div class="p-6">
<form id="archivo" action="{{ route('file.upload.post') }}" method="POST" enctype="multipart/form-data">
@csrf
<input required name="file" type="file" class="formulario">
<input required name="archivo" type="file" class="formulario">
<div class="labeled-input">
<label for="booklet-size">Tamaño de los librillos</label>
<input name="booklet-size" type="number" min=0 value=20 class="formulario numero-input">
<label for="bookletsize">Tamaño de los librillos</label>
<input name="bookletsize" type="number" min=1 value=20 class="formulario numero-input">
</div>
<input type="submit" value="Cargar archivo">
</form>

View File

@ -19,6 +19,6 @@ Route::get('/', function () {
return view('welcome');
});
Route::get('/processed/{fileName}', [LibrilladoraController::class, 'process'])->name('process');
Route::get('/processed/{fileName}/{size}', LibrilladoraController::class)->name('process');
Route::post('file-upload', [FileUploadController::class, 'fileUploadPost'])->name('file.upload.post');