Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support embed fonts #1302

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

Maxpsc
Copy link

@Maxpsc Maxpsc commented Nov 2, 2023

Through the new API addFonts, support embedding fonts into .ppt file.

@ChillyBots
Copy link

ChillyBots commented Jan 3, 2024

excited

@Rigorich
Copy link

Rigorich commented Mar 1, 2024

As it pointed out in #176, PowerPoint convert TTF/OTF font to it's own format FntData. So, as I tested, this PR doesn't work with TTF/OTF directly (there's error when opening presentation), but works with .fntdata files extracted from created manually PPTX with embedded fonts. Sadly, it's impossible to "embed only used symbols" in advance. And also embedded fonts work only in PowerPoint (and Aspose.Slides)

But if you still want to embed full font using this PR, here's instruction:

  1. Locally install font you want to embed
  2. Create new PowerPoint Presentation
  3. View - Slide Master - Fonts
  4. Replace Heading/Body fonts with your font name
  5. File - Options - Save - Embed fonts in the file - Embed all characters
  6. Save presentation
  7. Change file extension from .pptx to .zip
  8. Open .zip - ppt - fonts
  9. Copy this single .fntdata file outside of zip
  10. Convert this file to base64 string using any online converter
  11. Embed font using code below
const fontBase64 = '...';
fetch(`data:application/octet-stream;base64,${fontBase64}`)
	.then(res => res.blob())
	.then(blob =>
		this.presentation.addFont({
			typeface: 'My Font Name',
			fontBlob: blob,
		})
	);
  1. Save your presentation using base64 after any timeout
setTimeout(() =>
	this.presentation.write('base64')
		.then((data) => {
			// open index.html to get presentation
			const downloadLink = document.createElement('a');
			downloadLink.href = `data:application/octet-stream;base64,${data}`;
			downloadLink.download = `TEST - ${new Date().toISOString()}.pptx`;
			downloadLink.click();
		})
		.catch((err) => {
			console.error(err);
		})
, 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants