I need a php code for converting from any format to pdf by clicking a button called convert to pdf.
How to do?

I don't know if there is a ready PHP solution for this, but if you can install software in your hosting, then use LibreOffice in command line mode:


    $file = 'something.doc';
    $str  = sprintf("libreoffice --headless --invisible --convert-to pdf %s", $file);
    $cmd  = escapeshellcmd($str);


There are other solutions as unoconv, based on LibreOffice and JodConverter which seems to not be anymore maintained.