[工具] 創建與編輯PDF (hummus-recipe)

作者: little78926 (果果)   2018-08-18 06:00:50
https://github.com/chunyenHuang/hummusRecipe
https://www.npmjs.com/package/hummus-recipe
現行有許多生成PDF的工具,但是唯獨欠缺簡單好用的"修改"工具。
HummusRecipe建構在HummusJS(https://github.com/galkahana/HummusJS)之上,
大幅簡化了使用上的難度,也增加了許多親切的API。
中文字型需另外下載
https://github.com/chunyenHuang/hummusRecipe/blob/master/tests/font.js
安裝
npm i hummus-recipe
修改PDF
const HummusRecipe = require('hummus-recipe');
const pdfDoc = new HummusRecipe('input.pdf', 'output.pdf');
pdfDoc
.editPage(1)
.text('浮水印', 'center', 250, {
color: '066099',
fontSize: 30,
bold: true,
font: 'Helvatica',
align: 'center center',
opacity: 0.2,
rotation: 180
})
.rectangle(20, 20, 40, 100)
.comment('添加Comment annotation', 200, 300)
.image('/path/to/image.jpg', {width: 300, keepAspectRatio: true})
.endPage()
//
.editPage(2)
.comment('Add 2nd comment annotaion', 200, 100)
.endPage()
.endPDF();
生成PDF
const HummusRecipe = require('hummus-recipe');
const pdfDoc = new HummusRecipe('new', '/output.pdf',{
version: 1.6,
author: 'John Doe',
title: 'Hummus Recipe',
subject: 'A brand new PDF'
});
pdfDoc
.createPage('letter-size')
.text('哈囉~ \n 你好', 'center', 250, {
color: '066099',
fontSize: 30,
bold: true,
font: 'Helvatica',
align: 'center center',
opacity: 0.8,
rotation: 180
})
.endPage()
.endPDF();

Links booklink

Contact Us: admin [ a t ] ucptt.com