jeudi 23 juillet 2020

Adding page number to a PDF file using DOMPDF issue in laravel

When i upload a PDF file to add page number in it the function remove the all data in the file and add the page number.

Controller:

public function numbering(Request $request){
        $data = $request->all();
        if($request->hasFile('file')){
            $pdf = app('dompdf.wrapper');
            $pdf->getDomPDF()->set_option("enable_php", true);
            $pdf->loadView('numbering', $data);
            $name = time() . '.' . '.pdf';
            $destinationPath = public_path('/pdf_file');
            $numberfile = $destinationPath . '/' . $name;
            $pdf->save($numberfile);
            return response()->json(['code' => 200, 'success' => 'Data Updated Succesfully', 'file' => $name]);
        }
        else{
            return response()->json(['code' => 422, 'error' => 'NO File Found. ']);
        }
    }

BLade for Page Numbering

   <body>
<script type="text/php">
    if (isset($pdf)) {
        $x = 250;
        $y = 10;
        $text = "Page {PAGE_NUM} of {PAGE_COUNT}";
        $font = null;
        $size = 14;
        $color = array(255,0,0);
        $word_space = 0.0;  //  default
        $char_space = 0.0;  //  default
        $angle = 0.0;   //  default
        $pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
    }
</script>
</body>


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2WOxUfA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire