handwritten.js可以将文本转变成真实手写笔迹插件

handwritten.js可以将文本转变成真实手写笔迹插件

handwritten.js可以将文本转变成真实手写笔迹,支持浏览器和nodejs运行。支持设置背景线条、颜色、输出文档类型。

安装:

cdn

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/handwritten.js"></script>

npm

npm install handwritten.js
或者
yarn add handwritten.js

使用方式:

nodejs

const handwritten = require('handwritten.js')
const fs = require('fs')
const rawtext = "Hello, world!"
handwritten(rawtext).then((converted) => {
    converted.pipe(fs.createWriteStream('output.pdf'))
})

浏览器示例代码

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" />
    <title>BFW NEW PAGE</title>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/pdfkit.standalone.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/blob-stream.js"></script>

    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/handwritten.js"></script>
</head>

<body>
    <iframe width="100%" height="800px"></iframe>
    <script>
        handwritten("bfw.wiki is a good it site and loved by many iter",{ ruled: true}).then((doc) => {

            // pipe the document to a blob
            const stream = doc.pipe(blobStream());
    
            stream.on("finish", function () {
              // get a blob you can do whatever you like with
              blob = stream.toBlob("application/pdf");
            
              // or get a blob URL for display in the browser
              const url = stream.toBlobURL("application/pdf");
              const iframe = document.querySelector("iframe");
              iframe.src = url;
            });
    })
    </script>
</body>

</html>

cli命令行

npx handwritten.js -f "path/to/inputfile.txt" -o "path/to/outputfile.pdf"

handwritten.js -f path/to/inputfile.txt -o path/to/outputfile.pdf
handwritten.js -f path/to/inputfile.txt -o path/to/outputfile.pdf --ruled
handwritten.js -f path/to/inputfile.txt -o path/to/outputfolder --images png

github地址:https://github.com/alias-rahil/handwritten.js/


立即下载handwritten.js查看所有js插件

网友评论0

程序员在线工具箱