hand-dot / labelmake

labelmake has moved and now available at pdfme / https://github.com/pdfme/pdfme

Home Page:https://labelmake.jp/javascript-pdf-generator-library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

日本語が動きません

muners opened this issue · comments

お世話になります。
日本語フォントですとこの様なエラーが出ますが対処方法ありますでしょうか?

スクリーンショット 2021-07-23 14 15 06

コード上ではこんなエラーが出ます。

const labelmake = require('labelmake');
const fs = require('fs');

(async () => {
  // You can also use Uint8Array or ArrayBuffer as a basePdf
  const basePdf = fs.readFileSync("./template/tmp.pdf")
  // const basePdf = await fetch("path/to/your.pdf").then((res) => res.arrayBuffer());
  const template = {
	"basePdf": basePdf,
	"schemas": [
		{},
		{
			"name": {
				"type": "text",
				"position": {
					"x": 122.24,
					"y": 136.02
				},
				"width": 68.6,
				"height": 7,
				"alignment": "left",
				"fontSize": 12,
				"characterSpacing": 0,
				"lineHeight": 1
			}
		}
	]
};
  const inputs = [{"name":"東京都中野区"}];
  const pdf = await labelmake({ template, inputs });
  // Node
  fs.writeFileSync('./output/new.pdf', pdf);
  // Browser
  // const blob = new Blob([pdf.buffer], { type: "application/pdf" });
  // document.getElementById("iframe").src = URL.createObjectURL(blob);
})();
debug> c
< (node:17516) UnhandledPromiseRejectionWarning: Error: WinAnsi cannot encode "京" (0x4eac)
<     at tr.encodeUnicodeCodePoint (/Users/username/workspace/test/cloudsign/node_modules/labelmake/dist/labelmake.min.js:15:180806)
<     at e.encodeTextAsGlyphs (/Users/username/workspace/test/cloudsign/node_modules/labelmake/dist/labelmake.min.js:15:229123)
<     at e.widthOfTextAtSize (/Users/username/workspace/test/cloudsign/node_modules/labelmake/dist/labelmake.min.js:15:228148)
<     at e.widthOfTextAtSize (/Users/username/workspace/test/cloudsign/node_modules/labelmake/dist/labelmake.min.js:15:353823)
<     at /Users/username/workspace/test/cloudsign/node_modules/labelmake/dist/labelmake.min.js:15:1869920
<     at Array.reduce (<anonymous>)
<     at r (/Users/username/workspace/test/cloudsign/node_modules/labelmake/dist/labelmake.min.js:15:1869880)
<     at /Users/username/workspace/test/cloudsign/node_modules/labelmake/dist/labelmake.min.js:15:1870087
<     at Array.forEach (<anonymous>)
<     at /Users/username/workspace/test/cloudsign/node_modules/labelmake/dist/labelmake.min.js:15:1869795
< (node:17516) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
< (node:17516) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
< Waiting for the debugger to disconnect...

こちらで動きました。

#17