ITeye博客

用JavaScript(JSON)生成pdf、docx、png、svg、flash等,带中文、图形、图片、超链接...

xdoc · 2014-02-12 22:18 · Web前端 · Markdown

运行效果: http://sandbox.runjs.cn/show/rdhbtfbw

规范说明见:http://xdoc.sinaapp.com

<script type="text/javascript" src="http://xdoc.sinaapp.com/xdoc.js"></script>
<script type="text/javascript">
var obj = {
    "version": "9.8.1",
    "meta": {
        "author": "xdoc"
    },
    "paper": {
        "margin": "10"
    },
    "body": {
        "sizeType": "autosize",
        "items": [
            {
                "Class": "para",
                "lineSpacing": "4",
                "align": "center",
                "items": [
                    {
                        "Class": "img",
                        "height": "230",
                        "src": "http://img1.imglafaso.com/images/product/000/000/001/742/463/1742463_0_b.jpg",
                        "width": "230"
                    }
                ]
            },
            {
                "Class": "para",
                "align": "center",
                "items": [
                    {
                        "Class": "text",
                        "fontName": "黑体",
                        "fontColor": "#ffffff",
                        "backColor": "#ff9900",
                        "text": " 包邮 "
                    },
                    {
                        "Class": "text",
                        "fontName": "标宋",
                        "text": " 静佳Jplus全身瘦最强攻略3件套装"
                    }
                ]
            },
            {
                "Class": "para",
                "backColor": "#f0f0f0",
                "align": "center",
                "lineSpacing": "6",
                "items": [
                    {
                        "Class": "text",
                        "valign": "center",
                        "fontName": "标宋",
                        "fontSize": "21",
                        "text": "¥168"
                    },
                    {
                        "Class": "rect",
                        "padding": "0",
                        "height": "37",
                        "width": "107",
                        "color": "",
                        "items": [
                            {
                                "Class": "para",
                                "items": [
                                    {
                                        "Class": "path",
                                        "fillColor": "#800000",
                                        "height": "18",
                                        "width": "40",
                                        "shape": "M 389 190 L 389 1 L 101 1 L 101 131 L 40 189 Z",
                                        "color": "",
                                        "items": [
                                            {
                                                "Class": "para",
                                                "align": "right",
                                                "items": [
                                                    {
                                                        "Class": "text",
                                                        "fontColor": "#ffffff",
                                                        "fontSize": "10",
                                                        "text": "4.4折"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "Class": "para",
                                "items": [
                                    {
                                        "Class": "text",
                                        "fontColor": "#808080",
                                        "fontStyle": "throughline",
                                        "valign": "center",
                                        "text": "¥390.0"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "Class": "rect",
                        "fillColor": "#800000",
                        "gradual": "6",
                        "arc": "8",
                        "fillColor2": "#ff0000",
                        "href": "http://product.lefeng.com/pklist/1742463.html?productId=1742463",
                        "align": "center",
                        "color": "",
                        "valign": "center",
                        "items": [
                            {
                                "Class": "para",
                                "align": "center",
                                "items": [
                                    {
                                        "Class": "text",
                                        "fontColor": "#ffffff",
                                        "fontStyle": "bold",
                                        "valign": "center",
                                        "text": "立即疯抢"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
};
XDoc.to(obj, "pdf");
//XDoc.to(obj, "docx");
//XDoc.to(obj, "png");
//XDoc.to(obj, "svg");
//XDoc.to(obj, "flash");
</script>

评论(2)

  1. #2 楼 · xdoc · 2014-06-22 20:32

    chinesejie writes:

    xdoc后台开源吗?

    XDOC部分开源,XDOC云服务是免费的 http://xdoc.sinaapp.com

  2. #1 楼 · chinesejie · 2014-06-22 20:08

    xdoc后台开源吗?

评论功能维护中,当前仅展示历史评论。