-1

I have a page and I just want it to save it as pdf.

Like if you click print on the webpage and save as pdf or microsoft print to pdf.

Here is my code

`<?php

    // Include the main TCPDF library (search for installation path).
    require_once('./TCPDF-main/tcpdf.php');

    // create new PDF document        
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->setTitle('Title');
    $pdf->AddPage();

    //To print
    $html = 'https://examplewebsite.com';

    //Write to pdf
    $pdf->writeHTML($html);
    $pdf->Output('Newp file.pdf');

?>`

Currently it is creating a pdf which has https://examplewebsite.com but not the contents. How to print the contents?

1 Answers1

1

The $html variable is a string not a html source, you need to load the url with file_get_contents $html = file_get_contents('https://examplewebsite.com') or a curl method: php: Get html source code with cURL

neurodede
  • 100
  • 6