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

Render PDF to SVG #149

Open
ZZYSonny opened this issue Aug 21, 2022 · 8 comments
Open

Render PDF to SVG #149

ZZYSonny opened this issue Aug 21, 2022 · 8 comments

Comments

@ZZYSonny
Copy link

Hello, recently I was writing a PDF viewer that would work exactly as a normal web page, and you can enjoy all the feature of a browser (such as awesome touchpad scrolling/zooming). Try it out here https://zzysonny.github.io/StarShooter/

The way I am rendering a page is to generate a SVG picture for each page, using mupdf. Then Chrome can directly and efficiently (when generated in a proper way) render a complex SVG file. When you zoom in using touchpad, Chrome can rerender at a higher resolution instantly.

Currently I am modifying mupdf to achieve an efficiently-renderable pdf, but that is painful and I am considering a rust pdf library. Will you be interested in implementing a PDF -> SVG renderer?

@ZZYSonny
Copy link
Author

It seems like pdf_render is not far away from generating a svg. I will see if I can do it.

@s3bk
Copy link
Contributor

s3bk commented Aug 22, 2022

It can totally generate a SVG and you can load the SVG to render it..
But why take the extra step?

@ZZYSonny
Copy link
Author

Really? I've only seen pdf2img converting pdf to a rasterized picture.

@s3bk
Copy link
Contributor

s3bk commented Aug 23, 2022

The debug print for Scene is SVG. Not optimized at all, but it does work.

@ZZYSonny
Copy link
Author

OK I will try.

@ZZYSonny
Copy link
Author

ZZYSonny commented Aug 28, 2022

I've got text rendering (mostly) correct. The way I render text is

  • For each embedded font, extract SVG path of unicode encodable glyph. Compose to SVG font and use svg2ttf to convert SVG font to TTF font.
  • Use TextSpan whenever possible. (All texts in the screenshot below)
  • For characters that cannot be encoded as unicodes, fallback to SVG path. (The Big Sigma in the screenshot below)

I am working on other elements of PDFs.

image

@s3bk
Copy link
Contributor

s3bk commented Aug 28, 2022

You can actually link most fonts directly in SVG.
CID fonts are a bit more difficult.

@ZZYSonny
Copy link
Author

ZZYSonny commented Sep 6, 2022

You can actually link most fonts directly in SVG. CID fonts are a bit more difficult.

Not really. One can embed pfa fonts into a pdf, which is not supported by a modern browser. pfa (or any other) font -> svg font -> ttf font seems to be a shortcut, when there is no good tool to convert a pfa font on the web.

I am working on other drawing, and I got some transparency issue. I will open another issue in pdf-render.

You can find my code here https://github.com/ZZYSonny/pdf_render

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

No branches or pull requests

2 participants