I am in the process of converting a webpage into a format that is easily printable as a PDF, while ensuring that it maintains the same appearance. Many tools for printing to PDF do not support background images or colors, so I am attempting to overcome this by inserting a solid color image underneath the header elements of a table. Currently, it appears like this:
<img src="/image.png" width="100%" style="margin-bottom:-90px">
<table><th>Header1</th><th>Header2</th>...
Although in a web browser it looks like the header elements have a solid colored background, when trying to print to a PDF, the <th>
elements end up with a blank white background overlaying the image. Is there a way to make these elements transparent with the text against the image? Or perhaps there is an easier solution to address the background issue?
Edit:
My main challenge here was trying to find a workaround to ensure compatibility with various HTML to PDF conversion tools. Ultimately, this proved to be impractical as different browsers render pages differently and printers can impose varying margins. My resolution was to develop a simple PHP application that generates the PDF using wkhtmltopdf, which I had to set up on my server first. With this approach, the PDF consistently displayed correctly regardless of the browser used!