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

[Content_Types].xml not getting updated on PresentationDocument.Save with all FontParts removed #1551

Open
JessehMSFT opened this issue Nov 6, 2023 · 1 comment
Assignees
Milestone

Comments

@JessehMSFT
Copy link

JessehMSFT commented Nov 6, 2023

Describe the bug
I'm using OpenXML SDK to disable font embedding and remove all FontParts in a presentation. Saving the document isn't resulting in [Content_Types].xml getting updated even though no more fntdata parts exist in the file.

To Reproduce
Steps to reproduce the behavior:

  1. Download ClearEmbedFontsFlag.zip
  2. Run the below code using the included pptx as input
        internal static void RemoveEmbeddedFontsMin(string file)
        {
            using PresentationDocument doc = PresentationDocument.Open(file, isEditable: true);
            PresentationPart? presentationPart = doc.PresentationPart;
            if (presentationPart is null)
                return;

            BooleanValue? embedFonts = presentationPart.Presentation.EmbedTrueTypeFonts;
            if (embedFonts is null || !embedFonts.HasValue || !embedFonts.Value)
                return;

            presentationPart.Presentation.EmbedTrueTypeFonts = false;

            EmbeddedFontList? fontList = presentationPart.Presentation.EmbeddedFontList;
            if (fontList is not null)
            {
                presentationPart.Presentation.EmbeddedFontList = null;
                presentationPart.DeleteParts(presentationPart.FontParts);
            }

            doc.Save();
        }

Observed behavior
See EmbeddedFont - Copy.pptx for result.

When you inspect [Content_Types].xml, it still contains this entry:
<Default Extension="fntdata" ContentType="application/x-fontdata" />

Expected behavior
All fntdata parts have been removed. This entry is not nececssary.

If I switch to a SaveAs to a new file instead of a Save, the fntdata entry is removed from the resulting file.

If I open the file inside PowerPoint and let the app save, it also removes the unnecessary entry.

Desktop (please complete the following information):

  • OS: Windows
  • Office version: N/A
  • .NET Target: .Net 6.0
    • DocumentFormat.OpenXml Version: 2.20.0

Additional context
Add any other context about the problem here.

@tomjebo
Copy link
Collaborator

tomjebo commented Dec 8, 2023

@JessehMSFT after a little investigation, it seems that we don't actually have cleanup code to remove content type entries when removing parts. The SaveAs (or Clone in the current version - 3.0) appear to remove the content type entry but it's only because the content type doesn't exist in the newly created package before adding the remaining parts from the depleted original package. This is a design change request in the packaging or parts code to clean up content types entries after deleting the last part that uses a particular content type entry. I'm marking this as feature request enhancement and will investigate possible use of our features infrastructure to do the cleanup.

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

No branches or pull requests

3 participants