Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text in SVG with alpha <1 gets cut off when converting HTML to PDF #2332

Open
victorhartman opened this issue Dec 19, 2024 · 1 comment
Open
Labels
bug Existing features not working as expected

Comments

@victorhartman
Copy link

victorhartman commented Dec 19, 2024

This is a regression. This showed up when we performed an upgrade, used to work fine with an older version of the package. Unfortunately I don't know which version.

I have create a reproduction of the bug here:

import matplotlib.pyplot as plt
import numpy as np
from weasyprint import HTML

# plotting code
x = np.linspace(0, 10, 100)
y = np.sin(x)
fig, ax = plt.subplots(figsize=(10, 6))
ax.plot(x, y)

# Add annotation
ax.annotate('gyj', 
            xy=(4.7, 1),      
            xytext=(5.5, 0.5),
            alpha=0.999999 # This is the issue
            )

# Save to SVG
plt.savefig('test.svg', transparent=True, dpi=300, bbox_inches='tight', format='svg')

# Read the SVG file
with open('test.svg', 'r') as f:
    svg_content = f.read()

# Create HTML with embedded SVG
html_content = f"""
<!DOCTYPE html>
<html>
<head>
    <title>Plot Export</title>
    <style>
        body {{
            margin: 0;
            padding: 20px;
        }}
    </style>
</head>
<body>
    {svg_content}
</body>
</html>
"""

# Convert HTML string directly to PDF
HTML(string=html_content).write_pdf('plot.pdf')

Output is this
plot.pdf

While the svg looks fine:
Image

System info:
System: Windows
Machine: AMD64
Version: 10.0.22631
Release: 11

WeasyPrint version: 62.3
Python version: 3.12.2
Pydyf version: 0.10.0
Pango version: 15003

@liZe
Copy link
Member

liZe commented Dec 20, 2024

Hi!

Thanks for the report. The bug has been introduced in WeasyPrint 60.2 by 4dfe607.

@liZe liZe added the bug Existing features not working as expected label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants