import { pipe, gotenberg, convert, html, please } from 'gotenberg-js-client'
const toPDF = pipe(
gotenberg('http://localhost:3000'),
convert,
html,
please
)
// 转换HTML字符串为PDF
const pdf = await toPDF('<html>...</html>')
pdf.pipe(fs.createWriteStream('index.pdf'))
复制代码
在这个例子中,我们创建了一个转换函数toPDF,它吸收一个HTML字符串,将其转换为PDF,并生存到文件中。
总结来说,gotenberg-js-client 是一个功能强大、机动且易于集成的JavaScript客户端,为Web文档转换提供了高效的解决方案。无论是静态网站天生照旧动态文档处置惩罚,它都能满足开发者的需求,是现代Web开发的宝贵工具。
gotenberg-js-client A simple JS/TS client for interacting with a Gotenberg API