Jump to content

Recommended Posts

Posted (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 by ZulfadlyAshBurn
Grammer

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.