HummusRecipe 簡易好用的PDF新工具(兼具修改與生成)
https://github.com/chunyenHuang/hummusRecipe https://www.npmjs.com/package/hummus-recipe
現行有許多生成PDF的工具,但是唯獨欠缺撿單好用的"修改"工具。HummusRecipe
建構在HummusJS
(https://github.com/galkahana/HummusJS)之上,大幅簡化了使用上的難度,也增加了許多親切的API。
安裝
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();