-
Notifications
You must be signed in to change notification settings - Fork 363
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
Add support for SVG images #23
Comments
I decided to create our own transcoder rather than the transcoder provided by FOP. This gives the benefits that it can output to Java2D as well as pdf and can use our user agent, font resolver, etc. However, it is a bit more work so I'm still debugging it and will commit something tomorrow for testing. |
Should we keep the transcoder to use flexible? Batik is very mature, and will likely be quicker to implement for complex SVGs. |
This is a very early prototype using Batik to draw inline SVG graphics in a PDF document. Still to do are images and text in the SVG. Also to do is support for Java 2D.
…lso uses the first color in a SVG linear gradient rather than ignoring it.
Todo for proper SVG output:
|
With commit bb586a9 you can output custom fonts in SVG like this (text color is still wrong and gradients aren't implemented): <html>
<head>
<meta charset="UTF-8"/>
<style>
@font-face {
font-family: 'handwriting';
src: url(JustAnotherHand.ttf);
}
svg {
display: block;
}
body {
font-size: 50px;
}
</style>
</head>
<body>
<svg height="130" width="500" xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="100" cy="70" rx="85" ry="55" fill="url(#grad1)" />
<text fill="#ffffff" font-size="45" font-family="handwriting" x="50" y="86">SVG</text>
</svg>
</body>
</html> |
- Correctly deal with width and height of SVG elements. - Add svg as block element to the base stylesheet (only block elements can be replaced). - Import fonts once per document rather than for every SVG element.
…bled due to issues with the transform origin.
… origin. At least when it comes to SVG transforms, we are now matching Chrome.
@danfickle I am not sure if the current approach is the right one. Instead of retrofitting a Graphics2D on a OutputDevice it should just be possible to get a Graphics2D to draw on. Like "createGraphics(rectangle)". This was possible with iText, but is currently not possible with PdfBox. After I finish #38 I will implement such a PdfBoxGraphics2D, as I need that for some reports where we have Java2D drawing code for some diagrams. And I need text support including the ability to render text as vector paths. But if you want to build such a PdfBoxGraphics2D feel free to do so. The PdfBox seems not interested in such a graphics 2d... |
@rototor - I think you have a good point. In fact a standalone Graphics2D implementation which output to PDF would be useful for many projects, not just this one. I found an old attempt and found some of our code is identical. I don't know who copied who. The old attempt would be useful for some of the maths, etc. It is also licensed under the LGPL. |
Just curious, is any other image format supported by openhtmltopdf right now? For example, I have a PNG which I need to render. |
Hi @brettclark |
Just for your information: I started a Graphics2D for PDFBox (https://github.com/rototor/pdfbox-graphics2d) but it seems not to be that simple. I choose the Apache 2.0 Licence, cause maybe PDFBox may want to integrate it when its finished. |
…This implements the infrastructure, but does not yet use it to render SVGs.
…oning is not right yet.
FYI: I've just created a pull request #66 which implements the SVG rendering using my Graphics2D adapter. It just does the placement of the final XForm wrong at the moment. |
…oxGraphics2D by @rototor - Converts XForm object from 72dpi to 96dpi using the XForm output matrix. - Fixes y to take into account the difference between bottom left coordinate system and top left coordinate system. - Apache Batik SVG renderer is still rendering in 96dpi on a 72dpi device so this will form work for the next commit.
@rototor - The SVG example is now working perfectly including text, sizing and positioning. Custom fonts via the font-face rule are also working.
…This implements the infrastructure, but does not yet use it to render SVGs.
…oning is not right yet.
…itioning is now right, so it is no longer needed.
…itioning is now right, so it is no longer needed.
Thanks to awesome library and work by @rototor SVG support is largely done.
|
Can this be released to maven repo? |
@pilami |
@danfickle this can be closed now? |
Currently, SVG images are not supported. PDFBox does not "draw" SVGs natively. Best practice is, to use apache batik to transcode SVGs to PDFs and embed these as PDFFormXObject via PDFBox.
_See also _
The text was updated successfully, but these errors were encountered: