Print a pdf file directly from Laravel

935 1 0 0

Last Updated : 2024-04-27 07:10:30

In case you want to directly print a pdf file from the browser in Laravel, here is a snippet of code that might help you do it.


  • Using a dynamically created iframe ,Here is the JS code
    let print = (doc) => {
    let objFra = document.createElement('iframe'); // Create an IFrame.
    objFra.style.visibility = 'hidden'; // Hide the frame.
    objFra.src = doc; // Set source.

    document.body.appendChild(objFra); // Add the frame to the web page.

    objFra.contentWindow.focus(); // Set focus.
    objFra.contentWindow.print(); // Print it.
    }

    print("{{url('openBillEventDocumentsFederal')}}"+"/"+dbId+"/"+fileField);?

    Mohammed Anwar

    Mohammed Anwar

    Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .