微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法使用 Itext 7.1.14 在 iPhone 上的 SVG 中定位文本

如何解决无法使用 Itext 7.1.14 在 iPhone 上的 SVG 中定位文本

我使用 Itext 7.1.14 在 PDF 中添加一个 SVG 图表。 在 Windows 和 Android 上,它正常工作。 但是,在 iPhone 或 Macbook 上,文本是颠倒的,所有内容都在顶部,在左侧。 我该怎么做才能解决这个问题?

比较:

图 1 - 在 Windows 和 Android 上

On Windows and Android

图片 2 - 在 iPhone 上

On iPhone

使用 Google Charts 生成图表的代码

google.charts.load('current',{ 'packages': ['corechart'] });
    google.charts.setonLoadCallback(drawChart);
    function drawChart() {
        var data = google.visualization.arrayToDataTable(participantesGrafico);

        var view = new google.visualization.DataView(data);
        view.setColumns([0,1,{
                calc: "stringify",sourceColumn: 1,type: "string",role: "annotation"
            },2]);

        //let fonte = 'bebas';
        let fonte = 'Arial';

        var options = {
            title: "MÉDIAS",width: 700,height: 50 * participantes.length,bar: { groupWidth: "80%" },legend: { position: "none" },chartArea: {
                top: 20,bottom: 20,left: 100,right: 20
            },hAxis: { textStyle: { fontName: fonte },titleTextStyle: { fontName: fonte } },vAxis: { textStyle: { fontName: fonte },titleTextStyle: { fontName: fonte },tooltip: { textStyle: { fontName: fonte } },fontName: fonte,};

        var chart = new google.visualization.BarChart(document.getElementById("graficoMedias"));
        chart.draw(view,options);
    }

进入 SVG。从 SVG 到字符串:

var grafico1 = document.getElementById('graficoMedias').getElementsByTagName('svg')[0].outerHTML;

由 Google 图表生成的 SVG:

<svg width="700" height="200" aria-label="A chart." style="overflow: hidden;"><defs id="_ABSTRACT_RENDERER_ID_0"><clipPath id="_ABSTRACT_RENDERER_ID_1"><rect x="100" y="20" width="580" height="160"></rect></clipPath><filter id="_ABSTRACT_RENDERER_ID_2"><feGaussianBlur in="SourceAlpha" stdDeviation="2"></feGaussianBlur><feOffset dx="1" dy="1"></feOffset><feComponentTransfer><feFuncA type="linear" slope="0.1"></feFuncA></feComponentTransfer><feMerge><feMergeNode></feMergeNode><feMergeNode in="SourceGraphic"></feMergeNode></feMerge></filter></defs><rect x="0" y="0" width="700" height="200" stroke="none" stroke-width="0" fill="#ffffff"></rect><g><text text-anchor="start" x="100" y="14.2" font-family="Arial" font-size="12" font-weight="bold" stroke="none" stroke-width="0" fill="#000000">MÉDIAS</text><rect x="100" y="4" width="580" height="12" stroke="none" stroke-width="0" fill-opacity="0" fill="#ffffff"></rect></g><g><rect x="100" y="20" width="580" height="160" stroke="none" stroke-width="0" fill-opacity="0" fill="#ffffff"></rect><g clip-path="url(https://localhost:44322/Evento/Evento/976#_ABSTRACT_RENDERER_ID_1)"><g><rect x="100" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#cccccc"></rect><rect x="216" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#cccccc"></rect><rect x="332" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#cccccc"></rect><rect x="447" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#cccccc"></rect><rect x="563" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#cccccc"></rect><rect x="679" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#cccccc"></rect><rect x="158" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#ebebeb"></rect><rect x="274" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#ebebeb"></rect><rect x="390" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#ebebeb"></rect><rect x="505" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#ebebeb"></rect><rect x="621" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#ebebeb"></rect></g><g><rect x="101" y="24" width="216" height="32" stroke="#3f51b5" stroke-width="1" fill="#3f51b5"></rect><rect x="101" y="64" width="303" height="32" stroke="#3f51b5" stroke-width="1" fill="#3f51b5"></rect><rect x="101" y="104" width="506" height="32" stroke="#3f51b5" stroke-width="1" fill="#3f51b5"></rect><rect x="101" y="144" width="419" height="32" stroke="#3f51b5" stroke-width="1" fill="#3f51b5"></rect></g><g><rect x="100" y="20" width="1" height="160" stroke="none" stroke-width="0" fill="#333333"></rect></g><g><rect x="317" y="40" width="0" height="1" stroke="none" stroke-width="0" fill="#999999"></rect><rect x="404" y="80" width="0" height="1" stroke="none" stroke-width="0" fill="#999999"></rect><rect x="607" y="120" width="0" height="1" stroke="none" stroke-width="0" fill="#999999"></rect><rect x="520" y="160" width="0" height="1" stroke="none" stroke-width="0" fill="#999999"></rect></g></g><g></g><g><g><text text-anchor="middle" x="100.5" y="194.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#444444">0</text></g><g><text text-anchor="middle" x="216.3" y="194.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#444444">2</text></g><g><text text-anchor="middle" x="332.1" y="194.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#444444">4</text></g><g><text text-anchor="middle" x="447.9" y="194.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#444444">6</text></g><g><text text-anchor="middle" x="563.7" y="194.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#444444">8</text></g><g><text text-anchor="middle" x="679.5" y="194.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#444444">10</text></g><g><text text-anchor="end" x="88" y="44.575" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#222222">Chromium</text></g><g><text text-anchor="end" x="88" y="84.325" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#222222">Edge</text></g><g><text text-anchor="end" x="88" y="124.075" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#222222">Firefox</text></g><g><text text-anchor="end" x="88" y="163.825" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#222222">Opera</text></g></g><g><g><g><text text-anchor="end" x="313" y="44.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#ffffff">3.74</text><rect x="290" y="34" width="23" height="12" stroke="none" stroke-width="0" fill-opacity="0" fill="#ffffff"></rect></g></g><g><g><text text-anchor="end" x="400" y="84.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#ffffff">5.25</text><rect x="377" y="74" width="23" height="12" stroke="none" stroke-width="0" fill-opacity="0" fill="#ffffff"></rect></g></g><g><g><text text-anchor="end" x="603" y="124.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#ffffff">8.75</text><rect x="580" y="114" width="23" height="12" stroke="none" stroke-width="0" fill-opacity="0" fill="#ffffff"></rect></g></g><g><g><text text-anchor="end" x="516" y="164.2" font-family="Arial" font-size="12" stroke="none" stroke-width="0" fill="#ffffff">7.25</text><rect x="493" y="154" width="23" height="12" stroke="none" stroke-width="0" fill-opacity="0" fill="#ffffff"></rect></g></g></g></g><g></g></svg>

C# 代码

byte[] b = Encoding.UTF8.GetBytes(grafico1);
MemoryStream ms2 = new MemoryStream(b);
Image i = SvgConverter.ConvertToImage(ms2,document.GetPdfDocument());
document.Add(i);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。