Stirling-PDF
Stirling-PDF copied to clipboard
[Bug]: HTML to PDF not applying CSS
Installation Method
Docker
The Problem
While converting an HTML file with embedded CSS, the CSS is not processed by WeasyPrint.
Sample HTML file:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Test</title>
<style>
@media print {
@page {
size: A4;
margin: 10mm;
}
}
table {
width: 100%;
border: 1px solid black;
border-collapse: collapse;
}
td, th {
border: 1px solid black;
padding: 4px 8px;
}
h1 {
color: #ff6d5a;
font-size: 24px;
font-weight: bold;
}
h2 {
color: #909399;
font-size: 18px;
font-weight: bold;
}
.date {
text-align: center;
}
th {
background-color: #ccc;
}
</style>
</head>
<body>
<div class="container">
<h1>Sample file with CSS</h1>
<h2>Stirling PDF releases by date</h2>
<table>
<thead>
<tr>
<th scope="col">Version</th>
<th scope="col">Release date</th>
</tr>
</thead>
<tbody>
<tr>
<td>0.42.0</td>
<td class="date">2025-02-18</td>
</tr>
<tr>
<td>0.41.0</td>
<td class="date">2025-02-07</td>
</tr>
<tr>
<td>0.40.2</td>
<td class="date">2025-02-04</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Result (from stirlingpdf.io but same result with a local one): test-0.42.0.pdf
If I run weasyprint inside the docker container with weasyprint -e utf-8 -v ./test.html ./test-weasyprint.pdf
I get the following result:
test-weasyprint.pdf
Version of Stirling-PDF
0.42.0
Last Working Version of Stirling-PDF
No response
Page Where the Problem Occurred
https://stirlingpdf.io/html-to-pdf
Docker Configuration
Relevant Log Output
Stirling logs (on a 0.41.0 version):
2025-02-25 10:35:48,475 INFO s.s.S.u.ProcessExecutor [qtp1649096004-74] Running command: weasyprint -e utf-8 -v /tmp/input_5172116263121672320.html /tmp/output_12477067076192693365.pdf
2025-02-25 10:35:49,022 INFO s.s.S.u.ProcessExecutor [Thread-42] INFO: Step 1 - Fetching and parsing HTML - /tmp/input_5172116263121672320.html
2025-02-25 10:35:49,045 INFO s.s.S.u.ProcessExecutor [Thread-42] INFO: Step 3 - Applying CSS
2025-02-25 10:35:49,047 INFO s.s.S.u.ProcessExecutor [Thread-42] INFO: Step 4 - Creating formatting structure
2025-02-25 10:35:49,049 INFO s.s.S.u.ProcessExecutor [Thread-42] INFO: Step 5 - Creating layout - Page 1
2025-02-25 10:35:49,086 INFO s.s.S.u.ProcessExecutor [Thread-42] INFO: Step 6 - Creating PDF
2025-02-25 10:35:49,115 INFO s.s.S.u.ProcessExecutor [Thread-42] INFO: Step 7 - Adding PDF metadata
Manual weasyprint logs:
INFO: Step 1 - Fetching and parsing HTML - ./test.html
INFO: Step 2 - Fetching and parsing CSS - CSS string
INFO: Step 3 - Applying CSS
INFO: Step 4 - Creating formatting structure
INFO: Step 5 - Creating layout - Page 1
INFO: Step 6 - Creating PDF
INFO: Step 7 - Adding PDF metadata
As you can see Step 2 is missing inside StirlingPDF run
Additional Information
No response
Browsers Affected
No response
No Duplicate of the Issue
- [x] I have verified that there are no existing issues raised related to my problem.