We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Font Size Changes after Saving a Presentation and Opening the Same File

Hi,
We are using Aspose.Slides for generating the powerpoint files. We are having an issue when we save the generated file and if we re-open the saved file then the font size is changed. Before saving the file , font size looks correct.

Please review and let us know why it is changing the font after saving the file.

Regrads,
Prathap

@PrathapSV,
Thank you for contacting support.

Please check the problem with the font size using the latest version of Aspose.Slides if it is possible. If the issue persists, please share the following data and information:

  • input and output files
  • code example that reproduces the problem
  • OS version on which the code was executed
  • .NET target platform in your app
  • Aspose.Slides version you used

Hi,

At this moment, we don’t have enough time to re-produce this issue. But we can provide some information which might give you an idea to guide us.

However, we have attached the screenshots “img5” and “img6” for your reference. (img5.png (105.8 KB)
img6.png (91.5 KB)
)
Here
img5.png => This is the PPTX output from Aspose.Slides, which has proper footer text formatting, aquires the entire slide width.

img6.png => This is the same PPTX file saved and re-opened which has different footer text formatting, creates a gap and doesn’t acquire the entire width of the slide.

Note, that all slides in the PPT will have just an image in “.emf”/“metafile” format, added into a picture control during powerpoint creation using aspose slides. Also, please note, if you compare both these image screenshots side by side, you can find almost all of the fonts looks different.

Below is the code for your reference along with other info you asked earlier.
input and output files => we don’t have this at this point, will get it to you soon, but you can refer screenshots attached(img5 n img6.png)
OS version on which the code was executed: Microsoft windows 10 Enterprise LTSC
.NET target platform in your app: 4.8
Aspose.Slides version you used: 21.11.0.0
code example that reproduces the problem: refer below

public bool ConvertToPowerPoint(GrapeCity.ActiveReports.SectionReport sectionReport, string fileName, bool isRootOrSectionHeaderOrDisclaimerBookNode)
    {
        bool success = false;
        try
        {
            this.isRootOrSectionHeaderOrDisclaimerNode = isRootOrSectionHeaderOrDisclaimerBookNode;
            ExportToPowerPointUsingAsposeSlides(sectionReport, fileName);
            success = true;
        }
        catch (Exception ex)
        {
            if (ex is FileNotFoundException)
                ExceptionLog.LogException(ex, "Failed to create PPTX file!");
            else
                throw ex;
        }

        return success;
    }

    private bool ExportToPowerPointUsingAsposeSlides(GrapeCity.ActiveReports.SectionReport activeReportToExport, string fileName)
    {
        bool success = false;
        try
        {
            Presentation pres = GetPresentationObjectFromActiveReport(activeReportToExport);
            if (pres != null)
            {
                pres.Save(fileName, SaveFormat.Pptx);
                success = true;
            }
        }
        catch (Exception ex)
        {
            ExceptionLog.LogException(ex, "Failed to create presentation from active report instance!");
            throw ex;
        }

        return success;
    }

    private Presentation GetPresentationObjectFromActiveReport(GrapeCity.ActiveReports.SectionReport activeReport)
    {
        try
        {
            if (activeReport != null)
            {
                // Never use using() blocks while creating the Presentation object when keeping alive in memory to manipulate later, as it will be disposed.
                Presentation pres = new Presentation();
                SetPresentationSlideSizeAndOrientation(pres, true);

                ISlide firstDefaultSlide = pres.Slides[0];

                for (int i = 0; i < activeReport.Document.Pages.Count; i++)
                {
                    GrapeCity.ActiveReports.Document.Section.Page page = activeReport.Document.Pages[i];
                    string imagePath = GetPageImage(page, i);

                    if (File.Exists(imagePath))
                    {
                        ISlide newSlide = AddSlideAsposeSlides(pres, firstDefaultSlide, imagePath, i + 1);
                        File.Delete(imagePath);
                    }
                }

                pres.Slides.RemoveAt(0);// remove first default slide
                return pres;
            }
        }
        catch (Exception ex)
        {
            ExceptionLog.LogException(ex, "Failed to create Presentation Object From Active Report Instance!");
            throw ex;
        }

        return null;
    }

    private void SetPresentationSlideSizeAndOrientation(Presentation pres, bool isPPTXAttributesDerivedFromActiveReport)
    {
        // VVIMP: Only one size/orientation can be set per presenation, multiple slide sizes across different slides WITHIN a single Presentation is not allowed from Microsoft by design.
        // VVIMP: While setting the Orientation for pptx slide, slide size width and height vaues will be swapped if the Orientation is LandScape, which should happen. 
        // If the Orientation is Portrait then values shouldn't swap. Setting the slide size as per the active report document, instead of default 10" * 7.5" (inches)

        if (PowerPointAttributesObj != null)
        {
            if (isPPTXAttributesDerivedFromActiveReport)
            {
                pres.SlideSize.SetSize(GlobalFunction.ConvertFromInchesToPoints(PowerPointAttributesObj.Size.Width),
                    GlobalFunction.ConvertFromInchesToPoints(PowerPointAttributesObj.Size.Height), SlideSizeScaleType.Maximize);

                pres.SlideSize.Orientation = PowerPointAttributesObj.ActiveReportPageOrientation == GrapeCity.ActiveReports.Document.Section.PageOrientation.Landscape
                                        ? SlideOrientation.Landscape : SlideOrientation.Portrait;
            }
            else
            {
                // Sets SlideSize derived from a presentation document itself.
                pres.SlideSize.SetSize(PowerPointAttributesObj.Size.Width, PowerPointAttributesObj.Size.Height, SlideSizeScaleType.Maximize);
                pres.SlideSize.Orientation = PowerPointAttributesObj.AsposeSlidesPageOrientation;
            }
        }
    }

    private string GetPageImage(GrapeCity.ActiveReports.Document.Section.Page page, int pageIndex)
    {
        string imagePath = string.Concat(Context.Settings.TempFileDir, "pptExport", Context.User.UserId, DateTime.Now.ToString().Replace("/", string.Empty).Replace(":", string.Empty), pageIndex, isRootOrSectionHeaderOrDisclaimerNode ? ".jpeg" : ".emf");
        ExportPageToImage(page, imagePath);
        return imagePath;
    }

    public void ExportPageToImage(GrapeCity.ActiveReports.Document.Section.Page page, string imagePath)
    {
        if (!isRootOrSectionHeaderOrDisclaimerNode)
        {
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
            RectangleF bounds = new RectangleF(0, 0, page.Width * graphics.DpiX, page.Height * graphics.DpiY);
            IntPtr hdc = graphics.GetHdc();

            Metafile metaFile = new Metafile(imagePath, hdc, Rectangle.Round(bounds), MetafileFrameUnit.Pixel);
            Graphics metaFileGraphics = Graphics.FromImage(metaFile);
            RectangleF metaFileBounds = new RectangleF(0, 0, page.Width * metaFileGraphics.DpiX, page.Height * metaFileGraphics.DpiY);

            metaFileGraphics.FillRectangle(Brushes.White, metaFileBounds);
            page.Draw(metaFileGraphics, new RectangleF(PointF.Empty, page.Size));
            metaFileGraphics.Dispose();
            metaFile.Dispose();

            graphics.ReleaseHdc(hdc);
            graphics.Dispose();
        }
        else
        {
            page.Units = GrapeCity.ActiveReports.Document.Section.Units.Pixels;
            Bitmap bmp = new Bitmap((int)page.Width, (int)page.Height);
            Graphics graphics = Graphics.FromImage(bmp);
            graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, bmp.Width, bmp.Height);
            page.Draw(graphics, new RectangleF(0, 0, page.Width, page.Height));
            bmp.Save(imagePath, ImageFormat.Jpeg);
            graphics.Dispose();
            bmp.Dispose();
        }
    }

    private ISlide AddSlideAsposeSlides(Presentation presentation, ISlide asposeFirstDefaultSlide, string imagePath, int slideIndex)
    {
        ISlide asposeSlide = presentation.Slides.InsertClone(slideIndex, asposeFirstDefaultSlide);

        float slideWidth = presentation.SlideSize.Size.Width;
        float slideHeight = presentation.SlideSize.Size.Height;
        byte[] bufferData = File.ReadAllBytes(imagePath);
        IPPImage imgx = presentation.Images.AddImage(bufferData);

        if (this.ImgeSizingType == ImgeSizingMethod.DefaultSlideSize)
        {
            float left = 0;
            float top = 0;
            asposeSlide.Shapes.AddPictureFrame(ShapeType.Rectangle, left, top, slideWidth, slideHeight, imgx);
            //asposeSlide.Shapes[1].LockAspectRatio = MsoTriState.msoTrue;
        }
        else if (this.ImgeSizingType == ImgeSizingMethod.CustomImageSize)
        {
            SizeF finalSize = GetMaxProportionalImageSize(slideWidth, slideHeight, imgx.Width, imgx.Height);
            PointF finalPosition = GetImageCenterPosition(slideWidth, slideHeight, finalSize);
            asposeSlide.Shapes.AddPictureFrame(ShapeType.Rectangle, finalPosition.X, finalPosition.Y, finalSize.Width, finalSize.Height, imgx);
        }

        return asposeSlide;
    }

Note: In the above code sample you can replace GetPageImage() function with any of the metafile image that you have in your machine. In our project, it will be provided by ActiveReports.

This issue is in production and it is very time sensitive as we need to fix as soon as we can, please let us know, how we can resolve this issue.

Also,

  1. if it’s an issue with font, is there a way to embed fonts into PPTX file?
  2. We were using metafile format as it gives better picture quality, is there any other format that we can use which can match this without creating these font issues?

Please review and let us know as soon as you can.

Thanks,
Prathap

@PrathapSV

Thanks for the images and sample code.

It seems that the problem is with the fonts used in the metafiles. But we can say exactly if we get an example of a presentation.

Answers to your questions:

  1. Information on how to embed fonts in a presentation can be found in our documentation
  2. You can try to use SVG images as an alternative to metafiles.