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

[Tools] Convert SVG to a PDF in Node with PDFKit and SVG.js的更多相关文章

  1. convert:图片转pdf失败

     造冰箱的大熊猫@cnblogs 2019/1/21 1.环境 操作系统/Ubuntu 16.04.5 LTS,内核/4.15.0-43-generic,convert/ImageMagick 6.8 ...

  2. [javascript svg fill stroke stroke-width rx ry ellipse 属性讲解] svg fill stroke stroke-width ellipse 绘制椭圆属性讲解

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

  3. [Tools] Create a Simple CLI Tool in Node.js with CAC

    Command-line tools can help you with all sorts of tasks. This lesson covers the very basics of setti ...

  4. Java 将PDF 转为Word、图片、SVG、XPS、Html、PDF/A

    本文将介绍通过Java编程来实现PDF文档转换的方法.包括: 1. PDF转为Word 2. PDF转为图片 3. PDF转为Html 4. PDF转为SVG 4.1 将PDF每一页转为单个的SVG ...

  5. 【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF

    SVG是一种图形文件格式,它的英文全称为Scalable Vector Graphics,意思为可缩放的矢量图形.它在放大或者改变尺寸的情况下其图形质量不会有所损失,且与 JPG 和 GIF 图像比起 ...

  6. 非node环境下的vue.js 实现简单的购物车计算功能 样式请无视

    都说vue的双向数据绑定好用,自己用了下,感觉做购物车没想象中好用.自己的实现如下: <!DOCTYPE html> <html lang="en"> &l ...

  7. node 模块化思想中index.js的重要性

    目录结构如上图 module1和modlue2.main在同一级 module1下文件: index.js var test2=require('./test2'); var sayHi=functi ...

  8. 启动node程序报错:event.js:183 throw er; // unhandled 'error' event

    启动node程序时,报如下错误:

  9. svg web拓扑更新了,支持动态添加svg组件

    版本1.0请点此 预览地址 https://svg.yaolunmao.top 如何使用 # 克隆项目 git clone https://github.com/yaolunmao/vue-webto ...

随机推荐

  1. History Api以及hash操作

    https://segmentfault.com/a/1190000002447556#articleHeader12 https://developer.mozilla.org/zh-CN/docs ...

  2. vue中 表头th 合并单元格,且表格列数不定的动态渲染方法

    吐槽 今天,在vue中遇到 复杂表格的渲染 ,需要合并表头的单元格,且合并单元格的那列还是动态数据,也就是说你不知道会有多少组要合并起来,哎,我也有点说不清楚,废话不多说了,看代码把: 代码示例 da ...

  3. mysql函数总结

    MySQL函数 MySQL数据库提供了很多函数包括: 数学函数:字符串函数:日期和时间函数:条件判断函数:系统信息函数:加密函数:格式化函数: 一.数学函数 数学函数主要用于处理数字,包括整型.浮点数 ...

  4. lombok安装、配置、使用

    eclipse安装Lombok 运行安装: java -jar ${path}\lombok.jar 选择IDE所在路径点击Install/Update即可使用. 手动安装1. 将lombok.jar ...

  5. 安卓启动图去除顶部title和状态栏

    1.在启动页的xml配置中,设置layout的id, <?xml version="1.0" encoding="utf-8"?> <Line ...

  6. Hive 启动报错

    java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected at jl ...

  7. [转]构建Python+Selenium2自动化测试环境(一)

    很久没有了解自动化了,最近发现项目中沉淀了很多东西,回归测试效 率很低,所以必须要考虑构建自动化来提供各个环节的小效率.由于忙于需求以及产品的流程规范,现在对于测试技术方面的研究也相对少了很多.不过不 ...

  8. LongListSelector 控件 在 wp7 和wp8中的不同之处

    众所周知,wp8中的LongListSelector集成到了Rom中. 性能得到了提升,一些api也发生了变化. 在这里总结一下,作为分享,也作为备忘. 参考文献 Windows Phone 8 XA ...

  9. POJ3630/HDU-1671 Phone List,字典树静态建树!

    Phone List POJ动态建树TLE了~~~ 题意:拨打某个电话时可能会因为和其他电话号码的前几位重复而导致错误,现在给出一张电话单,求是否有某个电话是其他电话的前缀.是则输出NO,否则输出YE ...

  10. HDU 3949 XOR ——线形基 高斯消元

    [题目分析] 异或空间的K小值. 高斯消元和动态维护线形基两种方法都试了试. 动态维护更好些,也更快(QAQ,我要高斯消元有何用) 高斯消元可以用来开拓视野. 注意0和-1的情况 [代码] 高斯消元 ...