douju7245 2014-05-19 19:18
浏览 69

通过php或javascript SVG到Powerpoint

So I have figured out how to create a SVG charts with d3, and I have them neatly displayed on a webpage for all to view. The problem is I need to export these SVG graphs to powerpoint. I have started using PHPPowerpoint and can pull an image from a web directory to a powerpoint slide,

but what I can't figure out is how to now take the SVG charts from the html page they are generated on to powerpoint?

I thought I could save them to the web directory then use PHPPowerPoint....but I can't figure out the first step of saving the generated SVG chart to a PNG or JPG to a web directory?

If I could convert to PNG or JPG then submit those images with POST I can save them to the server maybe?

Sorry, probably an easy question for most. Here is some code I have tried, but the circle is still an SVG when I complete....not an img...

    <!DOCTYPE html>
<html>
<body>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/rgbcolor.js"></script> 
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/StackBlur.js"></script>
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/canvg.js"></script> 


<canvas id="test" width="600" height="400"></canvas>

<svg width="600" height="400"><style type="text/css"><![CDATA[text{font-family:sans-serif;font-size:11px;} path{fill: none;stroke: #000;shape-rendering: crispEdges;} line{fill: none;stroke: #000;shape-rendering: crispEdges;}]]></style>.....</svg>

<script type="text/javascript"> 
    var ctx = document.getElementById('test').getContext('2d');
    ctx.drawSvg('<svg width="600" height="400"><style type="text/css"><![CDATA[text{font-family:sans-serif;font-size:11px;} path{fill: none;stroke: #000;shape-rendering: crispEdges;} line{fill: none;stroke: #000;shape-rendering: crispEdges;}]]></style>......</svg>',
    0 , 0 , 600, 400);
</script>


</body>
</html>

So I have found since I can't install something on the host server I am using canvg. I am having trouble getting the charts to look 100% the same...I think it might be the shape-rendering: crispEdges doesn't go into canvg.

  • 写回答

1条回答 默认 最新

  • doutuan8887 2014-05-21 03:59
    关注

    Here is the code(PHP) to convert SVG file to JPG/PNG.

    $svgFile = "sample.svg";
    $im = new Imagick();
    $im->readImageBlob($svgFile);
    $im->setImageFormat("jpg");
    $im->writeImage('jpg1.jpg');
    
    $im->clear();
    $im->destroy();
    

    For this you need to install ImageMagic on your server (http://www.imagemagick.org).

    You can convert SVG to JPG/PNG using command as well.

    convert sample.svg jpg1.jpg
    
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能