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. perl学习之:正则表达式

  2. 数据结构( Pyhon 语言描述 ) — — 第7章:栈

    栈概览 栈是线性集合,遵从后进先出原则( Last - in first - out , LIFO )原则 栈常用的操作包括压入( push ) 和弹出( pop ) 栈的应用 将中缀表达式转换为后缀 ...

  3. 关于get_magic_quotes_gpc()函数

    function sqlReplace($str) { $strResult = $str; if(!get_magic_quotes_gpc()) //如果 gpc 没有开的话 { $strResu ...

  4. HDU 4089 && UVa 1498 Activation 带环的概率DP

    要在HDU上交的话,要用滚动数组优化一下空间. 这道题想了很久,也算是想明白了,就好好写一下吧. P1:激活游戏失败,再次尝试. P2:连接失服务器败,从队首排到队尾. P3:激活游戏成功,队首的人出 ...

  5. apk 解包 打包

    APK应用程序的解包.修改.编辑.汉化.打包及应用 前两讲主要讲玩机的最基本的知识,集中在如何刷机.本讲是进级的内容,来谈谈与apk应用程序有关的知识,内容包括akp文件的解包.打包.反编辑.解析.汉 ...

  6. scp命令(基于ssh上传文件等)

    (转:http://www.cnblogs.com/hitwtx/archive/2011/11/16/2251254.html) svn 删除所有的 .svn文件 find . -name .svn ...

  7. app审核相关

    app加急审核通道:https://developer.apple.com/contact/app-store/?topic=expedite

  8. BZOJ1923 [Sdoi2010]外星千足虫 【高斯消元】

    题目 输入格式 第一行是两个正整数 N, M. 接下来 M行,按顺序给出 Charles 这M次使用"点足机"的统计结果.每行 包含一个"01"串和一个数字,用 ...

  9. 【线段树查询区间最值】poj 3264 Balanced Lineup

    #include<cstdio> #include<algorithm> using namespace std; ; struct Seg { int l,r,mi,ma; ...

  10. 【2018.9.26】K-D Tree详解

    网上对K-D-Tree的讲解不尽清晰,我学了很久都不会写,这里新开一文做一些讲解. 1.K-D-Tree是什么? K-DTree 即 K-Dimensional-Tree,常用来作空间划分及近邻搜索, ...