Given a epxress application and an svg template, we want to draw some text, date onto it and convert it to pdf as output.

const fs = require("fs")
const PDFDocument = require("pdfkit")
const SVGtoPDF = require("svg-to-pdfkit") const window = require("svgdom")
const document = window.document
const SVG = require("svg.js")(window) const express = require("express")
const app = express() const background = fs
.readFileSync("./background.svg")
.toString() app.get("/", (req, res) => {
const { name, date } = req.query const doc = new PDFDocument({
layout: "landscape",
size: "A4"
}) const draw = SVG(document.documentElement) const nameSVG = draw
.text(name)
.size()
.attr("x", "50%")
.attr("y", "45%")
.attr("text-anchor", "middle") const dateSVG = draw
.text(date)
.size()
.attr("x", "13.9%")
.attr("y", "87.7%") SVGtoPDF(doc, background)
SVGtoPDF(doc, nameSVG.svg())
SVGtoPDF(doc, dateSVG.svg()) doc.pipe(res)
doc.end()
}) app.listen()

Code: Github

最新文章

  1. jquery:validate的例子
  2. Python实现各种排序算法的代码示例总结
  3. <转>.php导出excel(多种方法)
  4. Xamarin Anroid开发教程之验证环境配置是否正确
  5. android AsyncHttpClient 开源框架的使用
  6. 一些CSS技巧
  7. 一个loader加载多个swf
  8. 【C疯狂的教材】(四)C语言分支语句
  9. @dynamic、@synthesize
  10. Java并发Fork-Join框架原理解析
  11. Source Insight4
  12. mac中:不能完成此操作,因为找不到一个或多个需要的项目。(错误代码 -43)
  13. iview render bug & vue namespace bug
  14. github & markdown & collapse & table
  15. 将GETDATE()转换为指定日期格式的varchar类型
  16. #ifdef __cplusplus extern "C" { #endif 含义
  17. Android 加载大图
  18. 【Spring学习笔记-MVC-9】SpringMVC数据格式化之日期转换@DateTimeFormat
  19. [Jobdu] 题目1370:数组中出现次数超过一半的数字
  20. 201621123006 《Java程序设计》第5周学习总结

热门文章

  1. NGINX宏观手记
  2. Django ORM操作及进阶
  3. 总线(bus);设备(devices);驱动(drivers)
  4. UVa 11987 并查集 Almost Union-Find
  5. 【0门槛】PR稿的自我修养
  6. wp8 longlistselector 动态加载datatemplate
  7. 【LeetCode】Maximum Depth of Binary Tree(二叉树的最大深度)
  8. 2.ruby基本语法,类的定义
  9. Python GUI 之 Treeview 学习
  10. BZOJ 2438 [中山市选2011]杀人游戏 ——期望DP