Skip to content
This repository

SVG based background #116

Closed
coolwanglu opened this Issue April 07, 2013 · 6 comments

2 participants

Lu Wang Clément Wehrung
Lu Wang
Owner

Actually I've attempted to do this for a while, but it's too complicated.

Pros

  • Both #39 and #64 may be solved with a SVG background
  • The size of background images could be significantly reduced
  • Type 3 fonts can be handled

Cons

  • in poppler, svg is handled by CairoOutputDev, which is not exposed
  • CairoOutputDev does not take adavantage of web fonts,
  • Text in SVG are not selectable in Firefox (crocdoc uses a hidden text layer)
Clément Wehrung
iclems commented May 16, 2013

That sounds nice. What I meant was: why not use the current tech which is able to display properly the text in HTML, and just render everything that is not text in SVG (as currently done for the background, nop?) ?

Sorry for the duplicate. So if I understand well, the issue is that you can easily output a page to SVG based on Cairo , but you can't easily remove part of the page (like text, for instance) and hence change what's rendered to SVG right ?

Lu Wang
Owner

I've taken a look at the code of pdftocairo, the output is a multi-page SVG, which is not quite suitable for HTML. I have to make it an svg image per page. I even failed to that since pdftocairo supports a number of formats, and the code was kind of a mess.

I will give it another try will I have time again, but now I know that it is not trivial.

Clément Wehrung
iclems commented May 17, 2013

You can have a look at pdf2svg which does the same job as pdf2cairo but enables the creation of 1 SVG per page. I can try to work on this if you want. There's this very simple convertPage(PopplerPage page, const char svgFilename) which seems especially interesting to me. The only question is if it is possible to pass our context currently used for the background (ie the page without most of the text?) :

poppler_page_get_size (page, &width, &height);

// Open the SVG file
surface = cairo_svg_surface_create(svgFilename, width, height);
drawcontext = cairo_create(surface);

// Render the PDF file into the SVG file
poppler_page_render_for_printing(page, drawcontext);
cairo_show_page(drawcontext);

// Close the SVG file
cairo_destroy(drawcontext);
cairo_surface_destroy(surface);
Lu Wang
Owner

@iclems poppler_page_for_printing is just a simple wrapper of the CairoOutputDev interfaces. In order to remove the text, I guess we still need to work on CairoOutputDev, like what I did with SplashOutputDev.

But a problem is that this interface use its won Font embedding and text placement systems, but ideally we want it the same way as in HTML, more precisely, use @font-face and CSS to specify fonts. And I don't know how to do that.

There is a pretty old branch called bg_integrate, which saves my early attempt, you may want to take a quick glance, but the code was a mess.

You are very welcome to do it now, as I've marked this issue as future, which means I don't expect enough time working on this in a near future.

Thanks.

Lu Wang
Owner

A (very) experimental implementation of SVG support is in the svg branch, which can be turned on with -DENABLE_SVG=ON cmake option. It disables the old png backend automatically.

Lu Wang
Owner

Now the format can be specified at run time.
I guess this issue can be closed now.

Lu Wang coolwanglu closed this September 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.