简体   繁体   中英

i want to give custom name to a pdf file download from website using mpdf library

i am create a website in which I can download the user information in pdf but the file name I want to give like filename=username ok the file that is download is detail.pdf but i want it like username.pdf

here is the code

            if (isset($_POST['pdf'])) {
                $mpdf = new \Mpdf\Mpdf();
                $body = "<h1>your details</h1>
                        <strong>first name:</strong>$fname <br>
                        <strong>last name:</strong>$lname <br>
                        <strong>username:</strong>$username <br>
                        <strong>email:</strong>$email <br>
                        <strong>contact-no:</strong>$contact <br>
                        <strong>date of birth:</strong>$dob <br>
                        <strong>course </strong>$course <br>
                        <h2>your subjects</h2> <br>
                        <strong>subject 1:</strong>$sub1 <br>
                        <strong>subject 2:</strong>$sub2 <br>
                        <strong>subject 3:</strong>$sub3 <br>
                        <strong>subject 4:</strong>$sub4 <br>
                        <strong>subject 5:</strong>$sub5 <br>
                        <strong>subject 6:</strong>$sub6 <br>
                        <strong>subject 7:</strong>$sub7 <br>
                        ";
                $filename = md5($fname);
                $mpdf->WriteHTML($body);
                $mpdf->Output(`$filename.pdf`, 'D');
            }
        }
    } else {
        header('location:logout.php');
    }

You can decide whatever the name of the file should be. Even a variable or a static name Try this please and see if it works.

// INVOICE name generated.
1° Option
$fileName = 'Invoicename'.'_'.date('D-d-m-Y-H-i-s').'.pdf';

2° Option
$fileName = '$fname'.'_'.date('D-d-m-Y-H-i-s').'.pdf';

$mpdf->Output($fileName,"D");

$mpdf->cleanup();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM