代码之家  ›  专栏  ›  技术社区  ›  ofey

将带有样式的SVG转换为PDF

  •  0
  • ofey  · 技术社区  · 5 年前

    在将SVG转换为PDF时难以保留样式。 我正在使用csstopdf cloudFormatter.com .

    但是我需要使用样式混合混合混合模式:乘法;但是当我创建PDF时它不会被保留。

    我尝试在svg元素上使用内联样式,也尝试将样式放入HTML头部,并使用外部style.css文件。但在每种情况下,我都得不到“相互影响”。

    如何获取PDF生成以识别SVG元素的样式?

    <!DOCTYPE html>
    <html lang="en" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title>csstopdf</title>
        <link rel="stylesheet" href="style.css">
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"
      integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
        <!-- <style>
          circle {
            mix-blend-mode: multiply;
          }
        </style> -->
      </head>
      <body>
        <div>
          <svg id="svgCircles" version="1.1" xmlns="http://www.w3.org/2000/svg" width="300" height="300" x="0" y="0" viewBox="0 0 150 150">
            <!-- <circle cx="50" cy="50" r="40" stroke-width="4" fill="green" style="mix-blend-mode: multiply;"/>
            <circle cx="75" cy="75" r="40" stroke-width="4" fill="red" style="mix-blend-mode: multiply;"/>
            <circle cx="100" cy="50" r="40" stroke-width="4" fill="blue" style="mix-blend-mode: multiply;"/> -->
            <circle cx="50" cy="50" r="40" stroke-width="4" fill="green" />
            <circle cx="75" cy="75" r="40" stroke-width="4" fill="red" />
            <circle cx="100" cy="50" r="40" stroke-width="4" fill="blue" />
          </svg>
        </div>
        <div class="btn-group" onclick="xepOnline.Formatter.Format('svgCircles');" role="group" aria-label="...">
          <button type="button" class="btn btn-warning">Generate svgCircles!</button>
        </div>
         <script src="xepOnline.jqPlugin.js"></script>
      </body>
    </html>
    

    xeponline.jqplugin.js文件太大,无法包含在此处。但可以在 http://www.cloudformatter.com/Resources/Pages/CSS2Pdf/Script/xepOnline.jqPlugin.js 或从下载 cloudformatter.com

    style.css文件,

    circle {
      mix-blend-mode: multiply;
    }
    

    这方面有一个很好的例子 gh-pages

    回购是在 https://github.com/shanegibney/csstopdf

    如果能为您提供帮助,我们将不胜感激。

    谢谢,

    1 回复  |  直到 5 年前
        1
  •  1
  •   Kevin Brown    5 年前

    我将添加此作为答案,因为我是此应用程序的作者之一。

    @cloudformatter css2pdf应用程序基于renderx的XEP引擎。他们对SVG转换的支持如下:

    RenderX's SVG Support

    如果您想要的不在该列表中,则当前不支持它。

    本质上,@cloudformatter使用包含SVG的HTML+CSS(如果有)发送到远程服务器。该服务器进行一些清理,并将内容转换为用于格式化引擎的XSL FO。使用的格式化引擎是renderx xep。因此,它执行从内容到输出的所有格式设置(PDF、PostScript、AFP、XPS等)。基础引擎支持的是所支持的。

    在您的情况下,似乎不支持混合混合混合模式。