ZulfadlyAshBurn Posted May 5, 2020 Share Posted May 5, 2020 (edited) I have created a PHP page where the contents are pulled from DB. Is there a way that I can save the file with the output and stylesheet to PDF with a click of a button. Edited May 5, 2020 by ZulfadlyAshBurn Grammer Quote Link to comment Share on other sites More sharing options...
requinix Posted May 5, 2020 Share Posted May 5, 2020 Yes. Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted May 5, 2020 Author Share Posted May 5, 2020 I'm unable to include the css in the PDF. I'm using TCPDF. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 5, 2020 Share Posted May 5, 2020 That would be because CSS is for HTML. PDFs do not support CSS. TCPDF does not do CSS as far as I can tell. So either you forget CSS and tell TCPDF explicitly what styling you want to use everywhere, or you pick another HTML-to-PDF library that does support CSS. If I can remember what library I used some time ago and was fairly pleased with then I'll mention it. Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted May 5, 2020 Author Share Posted May 5, 2020 Managed to get CSS to work. Had to do inline CSS for it work tho. Quote Link to comment Share on other sites More sharing options...
kicken Posted May 6, 2020 Share Posted May 6, 2020 It's a little more complicated to setup, but I personally prefer using something like pdf-puppeteer. It essentially spins up a browser to render the page then generate the PDF so you can use most all your modern CSS/HTML (with some limitations) to design the page. I've used it in a few projects and can generally just render the same HTML/CSS as I normally use but without the header/footer and a extra 'pdf' class on the <html> tag. You just have to have node available on the server, create a little javascript program to accept your HTML and generate the PDF then use exec to run it. If you have dedicated hosting or a VPS then it should be relatively simple to setup. If your on shared hosting you'll likely have to ask your host if they support such a thing. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.