Closed chofstrand closed 3 months ago
Hi!
WeasyPrint doesn’t execute JavaScript at all, so I suppose that you generate your final HTML file with some other tool. Could you please share your real final HTML file that includes img
tags?
Or maybe html_file
is just a number instead of a filename. 😄
WeasyPrint doesn’t execute JavaScript at all, so I suppose that you generate your final HTML file with some other tool. Could you please share your real final HTML file that includes
img
tags?
Yeah... that could be an issue 🥲 lol. The (abbreviated) output from the template looks like this, and this is what Weasyprint is trying to turn into a PDF:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="finalData" finalGraphs="["..\\graphs\\blankvsQCs.png", "..\\graphs\\P_31-02_42_batch1.mzML_whole.png", " [...], "..\\graphs\\P_HMN35-5_19_batch1.mzML_whole.png", "..\\graphs\\P_HMN35-5_19_batch1.mzML_L-Glutamine.png", "..\\graphs\\P_HMN35-5_19_batch1.mzML_L-Glutamic Acid.png"]">
</head>
<body>
<h1>polar_neg</h1>
<h3>A Clarkity Control Report</h3>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>Warnings</th>
<th>L-Glutamine Peak Area</th>
<th>L-Glutamic Acid Peak Area</th>
</tr>
</thead>
<tbody>
<tr>
<th>Blank_3_52_batch1.mzML</th>
<td>-</td>
<td>0.0</td>
<td>0.0</td>
</tr>
<tr>
<th>Avg Blank</th>
<td>-</td>
<td>0.0</td>
<td>0.0</td>
</tr>
<tr>
<th>PQC_1_04_batch1.mzML</th>
<td>-</td>
<td>0.0</td>
<td>0.0</td>
</tr>
[...]
[...]
[...]
<tr>
<th>P_HMN35-5_19_batch1.mzML</th>
<td>[Blank peak larger than sample peak for L-Glutamine, Blank peak larger than sample peak for L-Glutamic Acid]</td>
<td>0.0</td>
<td>0.0</td>
</tr>
</tbody>
</table>
<div id="myImg" Content-type="image/png"></div>
<script>
const finalPaths = JSON.parse(document.getElementsByName('finalData')[0].getAttribute('finalGraphs'));
var allPics = finalPaths.length;
console.log(allPics);
for (var i = 0; i < allPics; i++) {
var img = document.createElement('img');
img.src = finalPaths[i];
document.getElementById('myImg').appendChild(img);
}
</script>
</body>
</html>
Is html_file
really a filename in your script, isn’t it an integer?
Hoo boy: I did some bad variable assignment earlier, and it was html_file
was an integer instead of a string. Fixing that fixed the issue! But yes, the Javascript for the images didn't write into the PDF, so I'll have to find another approach.
Thank you so much!
Hi all,
In Python, I'm creating a PDF from an HTML file made from a Jinja2 template. An abbreviated form of the HTML looks like this:
However, when I run:
HTML(html_file).write_pdf(r'output/final_report.pdf', mime_type='image/png', optimize_images=True)
I get:I believe it has something to do with how I have embedded the images into the html template:
I used this approach because the images need to be shown in an order specified in {{ imagePaths }}.
Any advice or input would be greatly appreciated!