Using Zapfdingbats with jsPDf

梦想与她 提交于 2019-12-11 16:33:20

问题


I'm trying to add a checkmark as text to a pdf document with jsPDf and the built-in Zapfdingbats font, but I'm running into issues. What is the correct way to access the glyphs in this font?

doc.setFont("Zapfdingbats");
doc.setFontStyle("normal");
doc.text("\u2714", 20, 20, null, null, "left");

When I use the above and render the pdf in an iframe, I get an error message via an alert message saying "Error in function Object.F (http://localhost:3000/static/js/1.chunk.js:26266:81): Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."

Note: I'm using this in my react app using create-react-app.

When I try:

doc.text(btoa(unescape(encodeURIComponent("\u2714"))), 20, 20, null, null, "left");

I get the checkmark but also three additional symbols that I don't want.


回答1:


Checkmark glyph is mapped to "4"

doc.text("4", xPosition, yPosition, null, null, "left");



回答2:


Question regarding the answer: how did you know that checkmark is mapped to "4"? I am trying to use the trademark (TM) in Symbol font, but have not figured out how to do it yet. I was able to use your answer above to put a checkmark where I want the TM. If I can find the correct mapping to the Symbol font, it should work. (I have tried "\u2122", but it came out like py!" in the file.)



来源:https://stackoverflow.com/questions/58333857/using-zapfdingbats-with-jspdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!