我使用batik-rasterizer-1.8.jar生成png文件。我使用以下svg文件获得了完全空白的png输出。我已经尝试过不同的服务器,但结果相同。
<svg xmlns:xlink="http://www.w3.org/1999/xlink" 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="600" height="380"><desc>Created with Highstock 2.1.5</desc><defs><linearGradient x1="0" y1="0" x2="0" y2="1" id="highcharts-31"><stop offset="0" stop-color="white" stop-opacity="1"></stop><stop offset="1" stop-color="#EEE" stop-opacity="1"></stop></linearGradient><linearGradient x1="0" y1="0" x2="0" y2="1" id="highcharts-32"><stop offset="0" stop-color="#8EB4E3" stop-opacity="1"></stop><stop offset="1" stop-color="#FFF" stop-opacity="1"></stop></linearGradient><clipPath id="highcharts-33"><rect x="0" y="0" width="496" height="300"></rect></clipPath><clipPath id="highcharts-35"><rect x="0" y="0" width="496" height="300"></rect></clipPath></defs><rect x="1" y="1" width="598" height="378" strokeWidth="2" fill="#FFF" stroke="#FFC000" stroke-width="2" class=" highcharts-background"></rect><rect x="20" y="20" width="496" height="300" fill="url(#highcharts-32)"></rect><image preserveAspectRatio="none" x="470" y="340" width="123" height="38" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://static.gurufocus.com/images/chart-exporting-logo.png"></image><text x="160" y="365"><tspan style="font-size:12px;fill:#000;font-weight:normal;">Interactive Charts. Apr. 21 2015, 14:25 UTC. Powered by </tspan></text><g class="highcharts-grid" ></g><g class="highcharts-grid" ><path fill="none" d="M 20 320.5 L 516 320.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 20 245.5 L 516 245.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 20 170.5 L 516 170.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 20 95.5 L 516 95.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 20 19.5 L 516 19.5" stroke="#558ED5" stroke-width="1" opacity="1"></path></g><g class="highcharts-grid" ><path fill="none" d="M 20 320.5 L 516 320.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 20 245.5 L 516 245.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 20 170.5 L 516 170.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 20 95.5 L 516 95.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 20 19.5 L 516 19.5" stroke="#558ED5" stroke-width="1" opacity="1"></path></g><rect x="19.5" y="19.5" width="497" height="301" strokeWidth="-1" stroke="#558ED5" stroke-width="1" fill="none" ></rect><g class="highcharts-axis" ><path fill="none" d="M -42854399732.5 320 L -42854399732.5 330" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 20 320.5 L 516 320.5" stroke="#558ED5" stroke-width="1" visibility="visible"></path></g><g class="highcharts-axis" ></g><g class="highcharts-axis" ><path fill="none" d="M 556 320.5 L 566 320.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 556 245.5 L 566 245.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 556 170.5 L 566 170.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 556 95.5 L 566 95.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 556 19.5 L 566 19.5" stroke="#558ED5" stroke-width="1" opacity="1"></path><path fill="none" d="M 556.5 20 L 556.5 320" stroke="#558ED5" stroke-width="1" visibility="visible"></path></g><g class="highcharts-series-group" ><g class="highcharts-series highcharts-tracker" visibility="visible" transform="translate(20,20) scale(1 1)" style="" clip-path="url(#highcharts-33)"><rect x="129" y="132" width="239" height="169" fill="#0EB45A" rx="0" ry="0"></rect></g><g class="highcharts-markers" visibility="visible" transform="translate(20,20) scale(1 1)" clip-path="none"></g><g class="highcharts-series" visibility="visible" transform="translate(20,20) scale(1 1)" clip-path="url(#highcharts-35)"><path fill="none" d="M 238 300 L 258 300" stroke-linejoin="round" visibility="visible" stroke="#558ED5" stroke-width="23" class=" highcharts-tracker" style=""></path></g><g class="highcharts-markers highcharts-tracker" visibility="visible" transform="translate(20,20) scale(1 1)" style="" clip-path="none"><path fill="#708943" d="M 248 296 C 253.328 296 253.328 304 248 304 C 242.672 304 242.672 296 248 296 Z"></path></g></g><g class="highcharts-legend" transform="translate(15,35)"><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>No. of Shares at Quarter Ends</tspan></text><rect x="0" y="4" width="16" height="12" fill="#0EB45A"></rect></g><g class="highcharts-legend-item" transform="translate(8,21)"><path fill="none" d="M 0 11 L 16 11" stroke="#708943" stroke-width="3"></path><path fill="#708943" d="M 8 7 C 13.328 7 13.328 15 8 15 C 2.6719999999999997 15 2.6719999999999997 7 8 7 Z"></path><text x="21" y="15" style="color:#333333;font-size:12px;font-weight:bold;cursor:pointer;fill:#333333;" text-anchor="start" ><tspan>LVS Quarterly Average Price ($)</tspan></text></g></g></g></g><g class="highcharts-axis-labels highcharts-xaxis-labels" ><text x="-42854399730.745926" style="color:#000;cursor:default;font-size:11px;fill:#000;width:380px;text-overflow:ellipsis;" text-anchor="end" transform="translate(0,0) rotate(-20 -42854399730.745926 338)" y="338" opacity="1"><tspan>2015Q1</tspan></text></g><g class="highcharts-axis-labels highcharts-yaxis-labels" ><text x="519" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="324" opacity="1">55.74</text><text x="519" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="249" opacity="1">56.74</text><text x="519" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="174" opacity="1">57.74</text><text x="519" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="99" opacity="1">58.74</text><text x="0" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="-9999">59.74</text></g><g class="highcharts-axis-labels highcharts-yaxis-labels" ><text x="559" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="324" opacity="1">0M</text><text x="559" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="249" opacity="1">1M</text><text x="559" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="174" opacity="1">2M</text><text x="559" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="99" opacity="1">3M</text><text x="0" style="color:#000;cursor:default;font-size:11px;fill:#000;width:1px;text-overflow:clip;" text-anchor="start" transform="translate(0,0)" y="-9999">4M</text></g><g class="highcharts-tooltip" style="cursor:default;padding:0;white-space:nowrap;" transform="translate(0,-9999)"><path fill="none" d="M 3 0 L 13 0 C 16 0 16 0 16 3 L 16 13 C 16 16 16 16 13 16 L 3 16 C 0 16 0 16 0 13 L 0 3 C 0 0 0 0 3 0" stroke="black" stroke-opacity="0.049999999999999996" stroke-width="5" transform="translate(1, 1)"></path><path fill="none" d="M 3 0 L 13 0 C 16 0 16 0 16 3 L 16 13 C 16 16 16 16 13 16 L 3 16 C 0 16 0 16 0 13 L 0 3 C 0 0 0 0 3 0" stroke="black" stroke-opacity="0.09999999999999999" stroke-width="3" transform="translate(1, 1)"></path><path fill="none" d="M 3 0 L 13 0 C 16 0 16 0 16 3 L 16 13 C 16 16 16 16 13 16 L 3 16 C 0 16 0 16 0 13 L 0 3 C 0 0 0 0 3 0" stroke="black" stroke-opacity="0.15" stroke-width="1" transform="translate(1, 1)"></path><path fill="url(#highcharts-31)" d="M 3 0 L 13 0 C 16 0 16 0 16 3 L 16 13 C 16 16 16 16 13 16 L 3 16 C 0 16 0 16 0 13 L 0 3 C 0 0 0 0 3 0"></path><text x="8" style="font-size:12px;color:#333333;fill:#333333;" transform="translate(0,20)"></text></g><image preserveAspectRatio="none" x="556" y="134.25000000000003" width="48" height="32" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://static.gurufocus.com/images/arrow_chart_1.png" id="undefined_img" ></image><image preserveAspectRatio="none" x="516" y="303" width="38" height="32" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://static.gurufocus.com/images/arrow_chart_1.png" id="undefined_img" ></image><text x="561" y="154" id="undefined_text" ><tspan style="font-size:10px;font-weight:bold;fill:#0eb45a;">2250.0K</tspan></text><text x="521" y="323" id="undefined_text" ><tspan style="font-size:10px;font-weight:bold;fill:#708943;">55.7</tspan></text></svg>
我使用以下命令生成png
C:\batik-1.8>java -Djava.awt.headless=true -jar batik-rasterizer-1.8.jar -m imag
e/png -d test.png -w 600 chart.svg
输出中有一个异常(无效的css值),但我确定它不是空白png文件的原因。我可以用其他svg生成png文件,但只能生成这个文件。
我已经尝试过的java版本:
1
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
2
java version "1.7.0_79"
OpenJDK Runtime Environment (rhel-2.5.5.1.el6_6-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
答案 0 :(得分:1)
问题在于SVG文件中的这个元素:
<path fill="none" d="M -42854399732.5 320 L -42854399732.5 330"
stroke="#558ED5" stroke-width="1" opacity="1"></path>
如果删除它,文件呈现正常。
我猜测奇怪的大坐标值正在破坏Batik的数字解析器。