Skip to content

Instantly share code, notes, and snippets.

@snehalbaghel
Created May 21, 2022 07:56
Show Gist options
  • Save snehalbaghel/26f76d3ba12e897250d372bd1ff27c5e to your computer and use it in GitHub Desktop.
Save snehalbaghel/26f76d3ba12e897250d372bd1ff27c5e to your computer and use it in GitHub Desktop.
List al available fonts in a document
// Credits: https://stackoverflow.com/a/62399430/4988995
function listFonts() {
let { fonts } = document;
const it = fonts.entries();
let arr = [];
let done = false;
while (!done) {
const font = it.next();
if (!font.done) {
arr.push(font.value[0]);
} else {
done = font.done;
}
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment