在项目中遇到了svg转pdf,此处记录一下,方便以后使用。
此处使用直接下载的方式,存在自己电脑默认下载目录。
1、maven依赖:
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.8</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-pdfa</artifactId>
<version>5.5.8</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-xtra</artifactId>
<version>5.5.8</version>
</dependency>
<dependency>
<groupId>com.itextpdf.tool</groupId>
<artifactId>xmlworker</artifactId>
<version>5.5.8</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.kenai.nbpwr</groupId>
<artifactId>org-apache-batik-all</artifactId>
<version>1.7-201003011305</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.w3c.dom.smil</artifactId>
<version>1.0.1.v200903091627</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt.runtime.3_7_1</groupId>
<artifactId>org.w3c.dom.svg</artifactId>
<version>1.1.0</version>
</dependency>
2、html代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
$("#svgToPDF").click(function(){
var svgHtml = $("#svgDiv").find("svg")[0];
var XMLS = new XMLSerializer();
var svg = XMLS.serializeToString(svgHtml);
$("#svgHtml").val(svg);
$("#svgForm").submit();
});
});
</script>
</head>
<body>
<div id="svgDiv">
<svg version="1.1" style="font-family:"Lucida Grande", "Lucida Sans Unicode", Arial, Helvetica, sans-serif;font-size:12px;" xmlns="http://www.w3.org/2000/svg" width="800" height="920">
<desc>Created with Highcharts 4.2.5</desc>
<defs>
<clipPath id="highcharts-7"><rect x="0" y="0" width="803" height="483"></rect></clipPath>
</defs>
<rect x="0" y="0" width="800" height="920" fill="#FFFFFF" class=" highcharts-background"></rect>
<g class="highcharts-grid"></g>
<g class="highcharts-grid">
<path fill="none" d="M 144.5 53 L 144.5 856" stroke="#D8D8D8" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 265.5 53 L 265.5 856" stroke="#D8D8D8" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 386.5 53 L 386.5 856" stroke="#D8D8D8" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 506.5 53 L 506.5 856" stroke="#D8D8D8" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 628.5 53 L 628.5 856" stroke="#D8D8D8" stroke-width="1" opacity="1"></path>
</g>
<g class="highcharts-axis">
<path fill="none" d="M 145 88.5 L 135 88.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 123.5 L 135 123.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 158.5 L 135 158.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 193.5 L 135 193.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 228.5 L 135 228.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 262.5 L 135 262.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 297.5 L 135 297.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 332.5 L 135 332.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 367.5 L 135 367.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 402.5 L 135 402.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 437.5 L 135 437.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 472.5 L 135 472.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 507.5 L 135 507.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 542.5 L 135 542.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 577.5 L 135 577.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 612.5 L 135 612.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 647.5 L 135 647.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 681.5 L 135 681.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 716.5 L 135 716.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 751.5 L 135 751.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 786.5 L 135 786.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 821.5 L 135 821.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 856.5 L 135 856.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 145 52.5 L 135 52.5" stroke="#C0D0E0" stroke-width="1" opacity="1"></path>
<path fill="none" d="M 144.5 53 L 144.5 856" stroke="#C0D0E0" stroke-width="1"></path>
</g>
<g class="highcharts-axis">
<text x="628" text-anchor="end" transform="translate(0,0)" class=" highcharts-yaxis-title" style="color:#707070;fill:#707070;" y="899">Rating</text>
<path fill="none" d="M 145 856.5 L 628 856.5" stroke="#C0D0E0" stroke-width="1"></path>
</g>
<g class="highcharts-series-group">
<g class="highcharts-series highcharts-series-0 highcharts-tracker" transform="translate(628,856) rotate(90) scale(-1,1) scale(1 1)" style="" width="483" height="803" clip-path="url(#highcharts-7)">
<rect x="777.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="0" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="742.5" y="0" width="15" height="483" stroke="#FFFFFF" stroke-width="0" fill="red" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="707.5" y="0" width="15" height="483" stroke="#FFFFFF" stroke-width="0" fill="red" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="672.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="0" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="637.5" y="362.25" width="15" height="120.75" stroke="#FFFFFF" stroke-width="0" fill="green" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="602.5" y="120.75" width="15" height="362.25" stroke="#FFFFFF" stroke-width="0" fill="orange" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="568.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="0" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="533.5" y="120.75" width="15" height="362.25" stroke="#FFFFFF" stroke-width="0" fill="orange" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="498.5" y="120.75" width="15" height="362.25" stroke="#FFFFFF" stroke-width="0" fill="orange" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="463.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="0" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="428.5" y="0" width="15" height="483" stroke="#FFFFFF" stroke-width="0" fill="red" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="393.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="0" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="358.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="1" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="323.5" y="120.75" width="15" height="362.25" stroke="#FFFFFF" stroke-width="0" fill="orange" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="288.5" y="120.75" width="15" height="362.25" stroke="#FFFFFF" stroke-width="0" fill="orange" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="253.5" y="362.25" width="15" height="120.75" stroke="#FFFFFF" stroke-width="0" fill="green" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="218.5" y="0" width="15" height="483" stroke="#FFFFFF" stroke-width="0" fill="red" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="184.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="0" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="149.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="0" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="114.5" y="120.75" width="15" height="362.25" stroke="#FFFFFF" stroke-width="0" fill="orange" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="79.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="0" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="44.5" y="241.5" width="15" height="241.5" stroke="#FFFFFF" stroke-width="0" fill="yellow" rx="0" ry="0" style="width: 20px;"></rect>
<rect x="9.5" y="362.25" width="15" height="120.75" stroke="#FFFFFF" stroke-width="0" fill="green" rx="0" ry="0" style="width: 20px;"></rect>
</g>
<g class="highcharts-markers highcharts-series-0" transform="translate(628,856) rotate(90) scale(-1,1) scale(1 1)" width="483" height="803" clip-path="none"></g>
</g>
<text x="400" text-anchor="middle" class="highcharts-title" style="color:#333333;font-size:18px;fill:#333333;width:736px;" y="24">
<tspan>Traumatic Experiences</tspan>
</text>
<g class="highcharts-data-labels highcharts-series-0 highcharts-tracker" visibility="visible" transform="translate(145,53) scale(1 1)" opacity="1" style="">
<g style="" transform="translate(242,4)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>1</tspan>
</text>
</g>
<g style="" transform="translate(465,39)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>3</tspan>
</text>
</g>
<g style="" transform="translate(465,74)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>3</tspan>
</text>
</g>
<g style="" transform="translate(242,109)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>1</tspan>
</text>
</g>
<g style="" transform="translate(121,144)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>0</tspan>
</text>
</g>
<g style="" transform="translate(362,179)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>2</tspan>
</text>
</g>
<g style="" transform="translate(242,213)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>1</tspan>
</text>
</g>
<g style="" transform="translate(362,248)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>2</tspan>
</text>
</g>
<g style="" transform="translate(362,283)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>2</tspan>
</text>
</g>
<g style="" transform="translate(242,318)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>1</tspan>
</text>
</g>
<g style="" transform="translate(465,353)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"><tspan>3</tspan></text></g><g style="" transform="translate(242,388)"><text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"><tspan>1</tspan></text></g><g style="" transform="translate(242,423)"><text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>1</tspan>
</text>
</g>
<g style="" transform="translate(362,458)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>2</tspan>
</text>
</g>
<g style="" transform="translate(362,493)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>2</tspan>
</text>
</g>
<g style="" transform="translate(121,528)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>0</tspan>
</text>
</g>
<g style="" transform="translate(465,563)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>3</tspan>
</text>
</g>
<g style="" transform="translate(242,597)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>1</tspan>
</text>
</g>
<g style="" transform="translate(242,632)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>1</tspan>
</text>
</g>
<g style="" transform="translate(362,667)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>2</tspan>
</text>
</g>
<g style="" transform="translate(242,702)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>1</tspan>
</text>
</g>
<g style="" transform="translate(242,737)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>1</tspan>
</text>
</g>
<g style="" transform="translate(121,772)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16">
<tspan>0</tspan>
</text>
</g>
<g style="" transform="translate(0,13)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,48)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,83)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,118)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,153)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,188)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,222)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,257)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,292)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,327)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,362)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,397)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,432)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,467)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,502)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,537)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,572)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,606)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,641)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,676)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,711)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,746)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
<g style="" transform="translate(0,781)">
<text x="5" style="font-size:11px;font-weight:bold;color:#000000;text-shadow:0 0 6px #FFFFFF, 0 0 3px #FFFFFF;fill:#000000;text-rendering:geometricPrecision;" y="16"></text>
</g>
</g>
<g class="highcharts-legend" transform="translate(640,90)">
<rect x="0.5" y="0.5" width="108" height="28" stroke="black" stroke-width="5" fill="none" isShadow="true" stroke-opacity="0.049999999999999996" transform="translate(1, 1)" visibility="visible"></rect>
<rect x="0.5" y="0.5" width="108" height="28" stroke="black" stroke-width="3" fill="none" isShadow="true" stroke-opacity="0.09999999999999999" transform="translate(1, 1)" visibility="visible"></rect>
<rect x="0.5" y="0.5" width="108" height="28" stroke="black" stroke-width="1" fill="none" isShadow="true" stroke-opacity="0.15" transform="translate(1, 1)" visibility="visible"></rect>
<rect x="0.5" y="0.5" width="108" height="28" stroke="#909090" stroke-width="1" fill="#FFFFFF" visibility="visible"></rect>
<g>
<g>
<g class="highcharts-legend-item" transform="translate(8,3)">
<text x="21" style="color:#333333;font-size:12px;font-weight:bold;cursor:pointer;fill:#333333;" text-anchor="start" y="15">
<tspan>gdfsg gfdgs</tspan>
</text>
<rect x="0" y="4" width="16" height="12" fill="#7cb5ec"></rect>
</g>
</g>
</g>
</g>
<g class="highcharts-axis-labels highcharts-xaxis-labels">
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="72" opacity="1">
<tspan style="width:125px; overflow:hidden">Neglect</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="107" opacity="1">
<tspan style="width:125px; overflow:hidden">Sexual Abuse</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="142" opacity="1">
<tspan style="width:125px; overflow:hidden">Physical Abuse</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="177" opacity="1">
<tspan style="width:125px; overflow:hidden">Emotional Abuse</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="212" opacity="1">
<tspan style="width:125px; overflow:hidden">Medical Trauma</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="247" opacity="1">
<tspan style="width:125px; overflow:hidden">Family Violence</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="282" opacity="1">
<tspan style="width:125px; overflow:hidden">Community Violence</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="317" opacity="1">
<tspan style="width:125px; overflow:hidden">School Violence</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="352" opacity="1">
<tspan style="width:125px; overflow:hidden">Disasters</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="387" opacity="1">
<tspan style="width:125px; overflow:hidden">War-Terrorism</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="422" opacity="1">
<tspan style="width:125px; overflow:hidden">Witness Crime</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="457" opacity="1">
<tspan style="width:125px; overflow:hidden">Parental Crime</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="491" opacity="1">
<tspan style="width:125px; overflow:hidden">Disruptions in CG</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="526" opacity="1">
<tspan style="width:125px; overflow:hidden">Exploitation</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="561" opacity="1">
<tspan style="width:125px; overflow:hidden">Accident</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="596" opacity="1">
<tspan style="width:125px; overflow:hidden">Adj to Trauma</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="631" opacity="1">
<tspan style="width:125px; overflow:hidden">*Traumatic Grief</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="666" opacity="1">
<tspan style="width:125px; overflow:hidden">*Re-experiencing</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="701" opacity="1">
<tspan style="width:125px; overflow:hidden">*Hyperarousal</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="736" opacity="1">
<tspan style="width:125px; overflow:hidden">*Avoidance</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="771" opacity="1">
<tspan style="width:125px; overflow:hidden">*Numbing</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="806" opacity="1">
<tspan style="width:125px; overflow:hidden">*Dissociation</tspan>
</text>
<text x="130" style="color:#606060;cursor:default;font-size:11px;width:254px;fill:#606060;text-overflow:clip;" text-anchor="end" transform="translate(0,0)" y="841" opacity="1">
<tspan style="width:125px; overflow:hidden">Emotional Dysreg</tspan>
</text>
</g>
<g class="highcharts-axis-labels highcharts-yaxis-labels">
<text x="145" style="color:#606060;cursor:default;font-size:11px;fill:#606060;width:111px;text-overflow:clip;" text-anchor="middle" transform="translate(0,0)" y="875" opacity="1"></text>
<text x="265.75" style="color:#606060;cursor:default;font-size:11px;fill:#606060;width:111px;text-overflow:clip;" text-anchor="middle" transform="translate(0,0)" y="875" opacity="1">0</text>
<text x="386.5" style="color:#606060;cursor:default;font-size:11px;fill:#606060;width:111px;text-overflow:clip;" text-anchor="middle" transform="translate(0,0)" y="875" opacity="1">1</text>
<text x="507.25" style="color:#606060;cursor:default;font-size:11px;fill:#606060;width:111px;text-overflow:clip;" text-anchor="middle" transform="translate(0,0)" y="875" opacity="1">2</text>
<text x="628" style="color:#606060;cursor:default;font-size:11px;fill:#606060;width:111px;text-overflow:clip;" text-anchor="middle" transform="translate(0,0)" y="875" opacity="1">3</text>
</g>
<g class="highcharts-tooltip" style="cursor:default;padding:0;pointer-events:none;white-space:nowrap;" transform="translate(160,-9999)" opacity="0" visibility="visible">
<path fill="none" d="M 3.5 0.5 L 413.5 0.5 C 416.5 0.5 416.5 0.5 416.5 3.5 L 416.5 85.5 C 416.5 88.5 416.5 88.5 413.5 88.5 L 111.5 88.5 105.5 94.5 99.5 88.5 3.5 88.5 C 0.5 88.5 0.5 88.5 0.5 85.5 L 0.5 3.5 C 0.5 0.5 0.5 0.5 3.5 0.5" isShadow="true" stroke="black" stroke-opacity="0.049999999999999996" stroke-width="5" transform="translate(1, 1)"></path>
<path fill="none" d="M 3.5 0.5 L 413.5 0.5 C 416.5 0.5 416.5 0.5 416.5 3.5 L 416.5 85.5 C 416.5 88.5 416.5 88.5 413.5 88.5 L 111.5 88.5 105.5 94.5 99.5 88.5 3.5 88.5 C 0.5 88.5 0.5 88.5 0.5 85.5 L 0.5 3.5 C 0.5 0.5 0.5 0.5 3.5 0.5" isShadow="true" stroke="black" stroke-opacity="0.09999999999999999" stroke-width="3" transform="translate(1, 1)"></path>
<path fill="none" d="M 3.5 0.5 L 413.5 0.5 C 416.5 0.5 416.5 0.5 416.5 3.5 L 416.5 85.5 C 416.5 88.5 416.5 88.5 413.5 88.5 L 111.5 88.5 105.5 94.5 99.5 88.5 3.5 88.5 C 0.5 88.5 0.5 88.5 0.5 85.5 L 0.5 3.5 C 0.5 0.5 0.5 0.5 3.5 0.5" isShadow="true" stroke="black" stroke-opacity="0.15" stroke-width="1" transform="translate(1, 1)"></path>
<path fill="white" d="M 3.5 0.5 L 413.5 0.5 C 416.5 0.5 416.5 0.5 416.5 3.5 L 416.5 85.5 C 416.5 88.5 416.5 88.5 413.5 88.5 L 111.5 88.5 105.5 94.5 99.5 88.5 3.5 88.5 C 0.5 88.5 0.5 88.5 0.5 85.5 L 0.5 3.5 C 0.5 0.5 0.5 0.5 3.5 0.5" stroke="#7cb5ec" stroke-width="1"></path>
</g>
</svg>
</div>
<div>
<div id="formDiv">
<form action="exportPDF.do" id="svgForm" method="post">
<input type="hidden" name="svg" id="svgHtml">
</form>
</div>
<button id="svgToPDF">SVG TO PDF</button>
</div>
</body>
</html>
3、control层:
@RequestMapping(value="exportPDF")
@ResponseBody
public String exportPdfFile(HttpServletRequest request,HttpServletResponse response,String svg) throws Exception {
Calendar cal = Calendar.getInstance();
String pdfName = String.valueOf(cal.getTimeInMillis());
response.reset();
response.addHeader("Content-Type", "application/pdf");
response.addHeader("Content-Disposition", "attachment; filename="+ pdfName + ".pdf");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PDF.testPDf(baos,svg);
baos.writeTo(response.getOutputStream());
baos.close();
return "success";
}
4、PDF类:
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.StringReader;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.print.PrintTranscoder;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.ImgTemplate;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.ElementList;
import com.itextpdf.tool.xml.XMLWorkerHelper;
public class PDF {
@SuppressWarnings("deprecation")
public static void testPDf() throws Exception{
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream("d:/svg.pdf"));
document.open();
document.setPageSize(PageSize.A4);
StringBuffer html = new StringBuffer();
html.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
html.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">").
append("<head>")
.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />")
.append("<style type=\"text/css\" mce_bogus=\"1\">body {font-family: SimSun;}</style>")
.append("</head>")
.append("<body>");
html.append("<div>");
html.append("<div>TESTTTTT</div>");
html.append("<div>");
html.append("<div>");
html.append("this is test div");
html.append("</div>");
html.append("</div>");
html.append("<table>");
html.append("<tr>");
html.append("<td>");
html.append("this is test table1");
html.append("</td>");
html.append("</tr>");
html.append("</table>");
html.append("<div style=\"border:dotted thin;height: auto; width:400px\" align=\"left\" >");
html.append("<table class=\"split\" style=\"height: 30px;width: 100px\">");
html.append("<tr>");
html.append("<td>");
html.append("this is test table2");
html.append("</td>");
html.append("<td>");
html.append("this is test table2");
html.append("</td>");
html.append("</tr>");
html.append("</table>");
html.append("</div>");
html.append("<div style=\"color: #0000ff;font-size: 12px;\" >UUUGGGHHFF</div>");
html.append("<h1>UUUGGGHHFF</h1>");
html.append("</div>");
html.append("</body></html>");
Paragraph context = new Paragraph();
String htmlString = html.toString();
ElementList elementList =XMLWorkerHelper.parseToElementList(htmlString, null);
for (Element element : elementList) {
context.add(element);
}
document.add(context);
//document.add(new Paragraph(html.toString()));
int width = 500;
int height = 250;
PdfContentByte cb = writer.getDirectContent();
PdfTemplate template = cb.createTemplate(width,height);
Graphics2D g2 = template.createGraphics(width,height);
PrintTranscoder prm = new PrintTranscoder();
TranscoderInput ti = new TranscoderInput("file:///d:/testxml.xml");
prm.transcode(ti, null);
PageFormat pg = new PageFormat();
Paper pp= new Paper();
pp.setSize(width, height);
pp.setImageableArea(0, 0, width, height);
pg.setPaper(pp);
prm.print(g2, pg, 0);
g2.dispose();
ImgTemplate img = new ImgTemplate(template);
document.add(img);
document.close();
System.out.println("转换成功");
}
@SuppressWarnings("deprecation")
public static void testPDf(ByteArrayOutputStream baos,String svg) throws Exception{
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,baos);
document.open();
document.setPageSize(PageSize.A4);
StringBuffer html = new StringBuffer();
html.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
html.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">").
append("<head>")
.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />")
.append("<style type=\"text/css\" mce_bogus=\"1\">body {font-family: SimSun;}</style>")
.append("</head>")
.append("<body>");
html.append("<div>");
html.append("<div>TESTTTTT</div>");
html.append("<div>");
html.append("<div>");
html.append("this is test div");
html.append("</div>");
html.append("</div>");
html.append("<table>");
html.append("<tr>");
html.append("<td>");
html.append("this is test table1");
html.append("</td>");
html.append("</tr>");
html.append("</table>");
html.append("<div style=\"border:dotted thin;height: auto; width:400px\" align=\"left\" >");
html.append("<table class=\"split\" style=\"height: 30px;width: 100px\">");
html.append("<tr>");
html.append("<td>");
html.append("this is test table2");
html.append("</td>");
html.append("<td>");
html.append("this is test table2");
html.append("</td>");
html.append("</tr>");
html.append("</table>");
html.append("</div>");
html.append("<div style=\"color: #0000ff;font-size: 12px;\" >UUUGGGHHFF</div>");
html.append("<h1>UUUGGGHHFF</h1>");
html.append("</div>");
html.append("</body></html>");
Paragraph context = new Paragraph();
String htmlString = html.toString();
ElementList elementList =XMLWorkerHelper.parseToElementList(htmlString, null);
for (Element element : elementList) {
context.add(element);
}
document.add(context);
//document.add(new Paragraph(html.toString()));
int width = 500;
int height = 250;
PdfContentByte cb = writer.getDirectContent();
PdfTemplate template = cb.createTemplate(width,height);
Graphics2D g2 = template.createGraphics(width,height);
PrintTranscoder prm = new PrintTranscoder();
TranscoderInput ti = new TranscoderInput(new StringReader(svg));
prm.transcode(ti, null);
PageFormat pg = new PageFormat();
Paper pp= new Paper();
pp.setSize(width, height);
pp.setImageableArea(0, 0, width, height);
pg.setPaper(pp);
prm.print(g2, pg, 0);
g2.dispose();
ImgTemplate img = new ImgTemplate(template);
document.add(img);
document.close();
System.out.println("转换成功");
}
public static void main(String[] args) throws Exception {
PDF.testPDf();
}
}
注意:因为使用的是下载方式,此方式必须使用form表单提交,若使用ajax方式不会下载成功
相关推荐
5. **命令行使用**:`svg2pdf`通常提供命令行接口,用户可以通过指定SVG文件和输出PDF文件路径来执行转换,如`svg2pdf input.svg output.pdf`。在开发环境中,这可以集成到自动化脚本或构建流程中。 6. **代码示例*...
svg2pdf.pdf,无线网络开发资料,对于无线网络开发具有帮助,linux驱动相关的,有兴趣可以自行下载
SVG2PDF是将SVG图像转换为PDF文档的工具,这种转换在许多场景中非常有用,例如,为了确保在各种设备和打印机上的一致显示。 本项目开源的SVG转PDF源码是基于Cairo库实现的。Cairo是一个跨平台的2D图形渲染库,支持...
svg2pdf.js 仅JavaScript的SVG到PDF转换实用程序,可利用jsPDF在浏览器中运行。 试用一下:。安装您可以通过npm获取svg2pf.js: npm install svg2pdf.js jspdf --save# oryarn add svg2pdf.js jspdf 从版本2.x开始,...
svg2pdf 从一系列 SVG 文件创建分层 PDF 文件 关于 这个应用程序是用 GO 编写的,使用修改过的库 。 svg2pdf 将一系列 SVG 文件转换为分层的 PDF 文件,每个 SVG 文件放在单独的层中。 文件名成为层名。 此应用...
$ pip install sphinxcontrib-svg2pdfconverter 您可以通过添加Inkscape中,和的librsvg之间CairoSVG选择sphinxcontrib.inkscapeconverter , sphinxcontrib.rsvgconverter或sphinxcontrib.cairosvgconverter的...
标题中的“svg2pdf.bat”指的是一个批处理脚本,用于将SVG(可缩放矢量图形)文件转换成PDF(便携式文档格式)文件。这个过程是通过结合使用两个开源软件——Inkscape和pdftk来实现的。在Windows操作系统中,批处理...
"pdf2svg 64位" 是一个专门用于将PDF文件转换为SVG格式的工具,特别适合在64位操作系统上运行。这个工具经过测试,被认为功能有效且输出质量良好。下面我们将详细介绍如何使用这个工具以及相关的技术要点。 **使用...
SVG Animations.pdf SVG Animations.pdf SVG Animations.pdf SVG Animations.pdf SVG Animations.pdf SVG Animations.pdf
PDF2SVG是一款强大的工具,主要用于将PDF文档转换为SVG(Scalable Vector Graphics)格式的文件。SVG是一种基于XML的矢量图像格式,它能够无损地缩放,且文件体积小,适合于网络上使用和进行二次编辑。在标题和描述...
Parser dxfParser = ParserBuilder.createDefaultParser(); dxfParser.parse(in, "UTF-8"); DXFDocument doc = dxfParser.getDocument(); SAXGenerator generator = new SVGGenerator();
"pdf2svg"项目是基于PDF.js的一个扩展,它将PDF文档转换为SVG(可缩放矢量图形)格式,这对于需要进行进一步处理、编辑或在Web上以高质量显示PDF内容的情况非常有用。SVG是一种基于XML的矢量图形格式,能够提供高...
2. SVG转换为PNG/JPEG/JPG: 这些是常见的位图格式,用于网络传输和存储。转换过程与SVG转Image类似,但需要额外保存为特定格式。C#内置的System.Drawing命名空间提供了Graphics和Image对象,可以用来将绘制的图像...
pdf2svg input.pdf output.svg ``` 这个命令将会把`input.pdf`转换为`output.svg`。转换过程中,工具会尽可能保留PDF的原始质量和细节,同时将文本转换为路径,以保持SVG的可缩放性。 然而,需要注意的是,PDF转...
### SVG入门PDF文档知识点梳理 #### 一、SVG简介 - **定义**:SVG(Scalable Vector Graphics)是一种基于XML的语言,用于描述二维矢量图形。它由W3C组织制定并维护,当前版本为1.1。 - **特点**: - 可缩放性:...
在提供的压缩包文件中,有两个名为"Xml2PDF.Server.2009_Evaluation_latest.msi"和"Xml2PDF.SDK.2009(.NET2.0).msi"的文件,它们可能是用于SVG到PDF转换的软件组件。"Server"可能是一个服务端应用程序,允许批量或...
`pdf2svg` 是一个开源工具,专门用于将PDF文件转换为SVG格式。这个32位版本是为32位操作系统设计的,确保在这些系统上也能处理PDF到SVG的转换任务。 使用`pdf2svg`的命令行语法非常简单,如下所示: ``` Usage: ...
2. **图形绘制**:解析后的SVG元素需要被渲染到PDF中。这个过程涉及理解SVG的路径数据、渐变、滤镜等特性,并在PDF上下文中正确绘制。Java中可以使用如iText或PDFBox等库来创建和编辑PDF文档。 3. **转换算法**:从...
PDF转SVG是一个常见的需求,特别是在图形设计和网页开发领域,因为SVG是一种矢量图形格式,可以在任何分辨率下保持清晰,适合于创建可缩放的图形元素。本实用程序专为Windows用户设计,利用了Poppler和cairo这两个...