This is a simple server that converts an SVG image to a PDF using Apache Batik and iText
The main reason I made this was to embed vector images in iText, which only likes PDFs and not SVGs.
You can try it from the svg2pdf page on FileFormat.Info. Note that this is only for light, non-commercial use. For other use, please run your own copy.
The code is deliberately simple to avoid external dependencies. All necessary libraries are included.
The easiest way to run it is with the included super-simple Dockerfile. See the run.sh and docker-run.sh shell scripts to see how I run it in development and production.
The code should work on any recent Java web server. There is nothing to compile: all the code is in the .jsp
files.
Environment variables:
FORM_URL
: the full URL of a form that should be used instead of the form in index.jsp. This will also trigger logging if it doesn't match the referrer. If you are running it locally, don't set it and the home page will display a form instead of the "Try It" link.
There is also a "direct" converter that just returns the PDF (vs an HTML page with a download link). Useful for automated conversions. An example with curl
:
curl \
--form height=512 \
--form width=512 \
--form stdin=@/tmp/1f5bc.svg \
--output 1f5bc.pdf \
--verbose \
http://svg2pdf.fileformat.info/direct.pdf
The same "for light, non-commercial use" rules apply!
GNU Affero General Public License v3.0
-
size methods: from svg
-
maximum upload size
-
remove console warning:
Graphics2D from BufferedImage lacks BUFFERED_IMAGE hint
-
convert.jsp: more verbose logging
-
link rel=canonical
-
make a shared function for code in common between direct and convert
-
ability to set margins