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 pdf (converted from svg) always appears on top #147

Open
ohmyarch opened this issue Jan 24, 2024 · 7 comments
Open

Text in pdf (converted from svg) always appears on top #147

ohmyarch opened this issue Jan 24, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@ohmyarch
Copy link

<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<text x="30" y="50" dy="0.76em" text-anchor="start" font-family="Arial" font-size="16.129032258064516" opacity="1" fill="#000000">
Test
</text>
<rect x="0" y="0" width="100" height="100" opacity="1" fill="#FFFFFF" stroke="none"/>
</svg>

svg:
图片

pdf:
图片

@jonmmease jonmmease added the bug Something isn't working label Jan 24, 2024
@jonmmease
Copy link
Collaborator

Thanks for raising the issue @ohmyarch, we should list this as a known limitation in the README.

As context, how are you using vl-convert, and in what kind of situation is this limitation causing issues for you?

@ohmyarch
Copy link
Author

Draw a vector map to svg, and then use vl-convert-pdf to output it to pdf. Some elements in the map, such as titles and legends, need to be overlaid on the base map. But there may be text labels on the base map below them. Therefore, in similar scenarios, this bug or limitation will cause some display confusion.

@ohmyarch
Copy link
Author

By the way, can this problem be avoided by using the original version of svg2pdf? I have a confusion about it. Its documentation tells me that text will be converted into shapes, but the same svg, such as the above example, only retains text elements, and uses svg2pdf to output, there will be nothing on the pdf.

@jonmmease
Copy link
Collaborator

Yeah, svg2pdf by itself will convert text to paths and should preserve proper layering of text under shapes.

vl-convert-pdf first runs svg2pdf without converting text to paths, so that svg2pdf renders everything except text. Then it performs its own logic to embed and overlay the text.

The long term solution here is probably to integrate text embedding logic into svg2pdf, but that will take a bit of effort. See typst/svg2pdf#21 for more background.

@jonmmease
Copy link
Collaborator

Text embedding has been merged into svg2pdf in typst/svg2pdf#64 (thanks @LaurenzV!), so after the next svg2pdf release we should be able to switch to this and drop our vl-convert-pdf crate which always layers text on top.

@LaurenzV
Copy link

Yeah, it should work just like that now! Also feel free to test it, if you want to try it before the release. The only caveat right now is that if a CFF font is selected for some text, it might result in rather large file sizes (see also typst/svg2pdf#66). But it should work pretty well otherwise, all test cases that worked before still work now.

Not sure when the next release will be though, first we need a new resvg release and there are also some other smaller things I need to add before we can make a new release. But hopefully within the next 1-2 months.

@jonmmease
Copy link
Collaborator

Thanks for the context @LaurenzV! No rush from our side, I'll keep an eye out for release notifications. And I'll let you know if I find time to test it out before release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants