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

Improve pdf export with vectorized #1859

Open
Nova38 opened this issue Mar 7, 2024 · 4 comments
Open

Improve pdf export with vectorized #1859

Nova38 opened this issue Mar 7, 2024 · 4 comments

Comments

@Nova38
Copy link

Nova38 commented Mar 7, 2024

Currently the PDF export uses playwrite to grab a PNG, this results in a rasterized image instead of a vector image, which can cause a lower quality output. I have been playing around with typst, a alternative to latex, and they have a nice svg to pdf library that renders the svg's to a pdf. It seems to do a good job with foreign objects, unlike inkscape etc... who have trouble rendering the d2 svg's. It currently doesn't render the text as text, but as paths which is a small downside. But it's output is a vectorized pdf which retains the high quality of d2 diagrams. I mainly was looking into this as I wanted to use d2 to draw diagrams for latex, but found that the pdf output ended up not looking great when imbedded in a pdf.

https://github.com/typst/svg2pdf

@alixander
Copy link
Collaborator

I've seen tools like those. The problem is text. Text in SVG sucks, so we and many others inject a little HTML for text, which is unrenderable in these tools. See typst/svg2pdf#57 .

I suppose we could do it twice. Grab a PNG of just the texts and overlay it on an SVG, but it's hairy. I'll leave it open for a OneDay task

@Nova38
Copy link
Author

Nova38 commented Mar 21, 2024

Hmm when I ran in on my desktop I think that it did render the text fine. It just rendered it as part of the vectorized path and not as text. The text was not selectable/embedded but instead it was still vectorized.

I am away from my computer at the moment so I don't have the d2 -> svg -> pdf that is the direct output of the tool I linked above, however that tool is the library that typst uses to render svg's in their documents. I have included below a link that contains a link to a typst project that contains it rendering a few different svg's from various tools, including d2langs avg output

https://typst.app/project/r_EHGOIHReFhPH4klfSkou

Classic (1).pdf

@alixander
Copy link
Collaborator

Oh interesting. Will have to take another look to verify

@Nova38
Copy link
Author

Nova38 commented Mar 27, 2024

I think it might still need a post prossing step to add back in the hovertext

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants