【问题标题】:IText c# SVG to PDF not fully displayedIText c# SVG to PDF未完全显示
【发布时间】:2021-07-06 01:53:00
【问题描述】:

我想使用 iText 将 SVG 文件转换为 PDF 文件。但是,Pdf 文件创建不正确。它以错误的格式显示。我该怎么做才能解决这个问题?

这里是 C# 代码:

using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Drawing.Imaging;
using iText;
using iText.Svg.Converter;
using iText.Kernel.Pdf;
using iText.Kernel.Utils;




namespace SvgToPdf
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FileStream svgPath = File.Open("1/1.svg", FileMode.Open);
            FileStream pdfPath = File.Create("autput.pdf");
            SvgConverter.CreatePdf(svgPath, pdfPath);
        }
    
    }
}

这是 svg 文件的样子:

http://jakob-ofner.myds.me/svg/1.svg

结果如下:

http://jakob-ofner.myds.me/svg/1.pdf

【问题讨论】:

  • 请尝试将 viewBox 添加到 svg 元素中,例如 viewBox="-283 0 1195 1289" 您也可以尝试添加宽度和高度属性。你得到的图像是 300/150 : svg default size

标签: c# svg itext itext7


【解决方案1】:

@enxaneta 我在 SVG 文件中添加了 viewBox="-283 0 1195 1289"。现在它起作用了。非常感谢!

【讨论】:

    猜你喜欢
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多