问题
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