Aspose Words and Slides having huge Doc/Ppt to Pdf Conversion times

I am trying to convert .docx/.doc/.ppt/.pptx files to .pdf and I am using below code, but it has high benchmarking times.
Is there a way to optimise the code or this conversion operation? I need to convert files up to 100 MB, any suggestion to optimise and minimise the time?

Conversion time statistics I have measured so far on my machine -
Word documents -
1.7 MB - 5.6 sec
4.1 MB - 4.9 sec
33.5 MB - 14.5 sec

Powerpoint Presentations -
1.17 MB - 4.04 sec
3.39 MB - 8.72 sec
33 MB - 8.12 sec

Aspose.Words ----

public byte[] ConvertDocToPdfViaAspose(byte[] docBytes)
{
    using (MemoryStream docStream = new MemoryStream(docBytes))
    {
        // Load the DOC file into an Aspose.Words Document
        Document doc = new Document(docStream);

        // Create a MemoryStream to hold the output PDF
        using (MemoryStream pdfStream = new MemoryStream())
        {
            // Save the document as PDF in the MemoryStream
            doc.Save(pdfStream, Aspose.Words.SaveFormat.Pdf);

            //return pdfStream.ToArray();
            byte[] pdfBytes = pdfStream.ToArray();

            return pdfBytes;
        }
    }
}

Aspose.Slides ----

public byte[] ConvertPptToPdfViaAspose(byte[] pptBytes)
{
    using (MemoryStream pptxStream = new MemoryStream(pptBytes))
    {
        // Load the PPTX presentation from the MemoryStream
        using (Presentation presentation = new Presentation(pptxStream))
        {
            // Create a MemoryStream to hold the output PDF
            using (MemoryStream pdfStream = new MemoryStream())
            {
                // Save the presentation as a PDF in the MemoryStream
                presentation.Save(pdfStream, Aspose.Slides.Export.SaveFormat.Pdf);

                byte[] pdfBytes = pdfStream.ToArray();

                return pdfBytes;
            }
        }
    }
}

@Harshika_Sharma

To optimize the conversion times for .docx and .pptx files to PDF using Aspose, you can consider the following strategies:

  1. Use PdfSaveOptions: When saving documents, you can customize the PdfSaveOptions to optimize the output. For example, enabling options like OptimizeOutput can help reduce the file size and potentially speed up the conversion process.

    PdfSaveOptions saveOptions = new PdfSaveOptions();
    saveOptions.OptimizeOutput = true; // Optimize the output PDF
    doc.Save(pdfStream, saveOptions);
    
  2. Reduce Image Quality: If your documents contain images, consider downsampling or compressing images during the conversion. This can significantly reduce the size of the output PDF and improve conversion speed.

    PdfSaveOptions saveOptions = new PdfSaveOptions();
    saveOptions.ImageCompression = PdfImageCompression.JPEG; // Use JPEG compression
    saveOptions.JpegQuality = 50; // Set JPEG quality to 50%
    doc.Save(pdfStream, saveOptions);
    
  3. Avoid Embedding Fonts: If font embedding is not necessary, you can disable it to speed up the conversion process. This can be done by setting the FontEmbeddingMode to EmbedNone.

    PdfSaveOptions saveOptions = new PdfSaveOptions();
    saveOptions.FontEmbeddingMode = PdfFontEmbeddingMode.EMBED_NONE; // Do not embed fonts
    doc.Save(pdfStream, saveOptions);
    
  4. Profile and Benchmark: Since you have already measured conversion times, continue to profile different document types and sizes. This will help you identify specific bottlenecks in your conversion process.

  5. Use a License: If you are using a trial version of Aspose, consider purchasing a license. Licensed versions often have performance optimizations that can improve conversion times.

  6. Batch Processing: If you are converting multiple documents, consider processing them in batches or using asynchronous methods to improve overall throughput.

By implementing these strategies, you should be able to reduce the conversion times for your documents significantly.

For more detailed examples and options, you can refer to the Aspose documentation on PDF save options and performance optimization techniques.

Sources:
[1]: Base conversions.cs
[2]: WorkingWithPdfSaveOptions.java

@Harshika_Sharma I’m afraid there is no room for optimization in your code. The conversion time depends on various factors, such as document format, size, complexity, and the hardware resources available in the environment where the conversion is performed.

I am also facing below issues with conversion functions in a .NET application which is hoisted in a Linux container.

For Aspose.Slides-

System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
   at System.Drawing.StringFormat.get_GenericTypographic()
   at ..ctor(Bitmap , Boolean )
   at ..ctor(Bitmap )
   at ..ctor(Int32 , Int32 , Single , Single , Boolean ,  ,  , List`1 )
   at Aspose.Slides.Slide.(Boolean ,  ,  , List`1 , InterruptionToken )
   at .(Presentation , Stream , Int32[] , PdfOptions , InterruptionToken )
   at .(Presentation , Stream , PdfOptions , InterruptionToken )
   at Aspose.Slides.Presentation.Save(Stream stream, SaveFormat format, ISaveOptions options) 

For Aspose.Words-

System.TypeInitializationException: The type initializer for 'LY' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
/app/runtimes/linux-x64/native/libSkiaSharp.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.13/libSkiaSharp.so: cannot open shared object file: No such file or directory
/app/libSkiaSharp.so: cannot open shared object file: No such file or directory
/app/runtimes/linux-x64/native/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.13/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/app/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/app/runtimes/linux-x64/native/libSkiaSharp: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.13/libSkiaSharp: cannot open shared object file: No such file or directory
/app/libSkiaSharp: cannot open shared object file: No such file or directory
/app/runtimes/linux-x64/native/liblibSkiaSharp: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.13/liblibSkiaSharp: cannot open shared object file: No such file or directory
/app/liblibSkiaSharp: cannot open shared object file: No such file or directory

Any help on the same please ?

@Harshika_Sharma Aspose.Words for .NET Standard and .NET Core uses SkiaSharp to deal with graphics, to make it work on Linux you have to add reference either to SkiaSharp.NativeAssets.Linux or to SkiaSharp.NativeAssets.Linux.NoDependencies

If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:

apt-get update && apt-get install -y libfontconfig1

If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies , which does not require installation of libfontconfig1.

I will move your topic into Aspose.Total category. My colleagues from Aspose.Slides team will help you shortly . @andrey.potapov Could you please take a look.

Just FYI, ours is a .NET 8 application.

@Harshika_Sharma,

The conversion time you specified seems acceptable. If you think any file is processed too slowly, please share it and indicate the conversion time. We will then investigate the case.

Please note that Aspose.Slides for .NET 6+ requires GLIBC 2.23 and higher installed on Linux systems.

System Requirements|Aspose.Slides Documentation

Thanks @alexey.noskov , the issue for Aspose.Words is fixed.

For Aspose.Slides, I am still facing issues.
For .NET 8 application, to install Aspose.Slides, I have followed these steps (Aspose.Slides for .NET 6 Cross Platform|Aspose.Slides Documentation)

But I am facing below error -

Aspose.Slides.PptxReadException: The type initializer for ‘’ threw an exception.
—> System.TypeInitializationException: The type initializer for ‘’ threw an exception.
—> System.DllNotFoundException: Unable to load shared library ‘libaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23’ or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you’re using glibc, consider setting the LD_DEBUG environment variable:
/app/runtimes/linux-x64/native/libaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.13/libaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23.so: cannot open shared object file: No such file or directory
/app/libaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23.so: cannot open shared object file: No such file or directory
/app/runtimes/linux-x64/native/liblibaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.13/liblibaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23.so: cannot open shared object file: No such file or directory
/app/liblibaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23.so: cannot open shared object file: No such file or directory
/app/runtimes/linux-x64/native/libaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.13/libaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23: cannot open shared object file: No such file or directory
/app/libaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23: cannot open shared object file: No such file or directory
/app/runtimes/linux-x64/native/liblibaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.13/liblibaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23: cannot open shared object file: No such file or directory
/app/liblibaspose.slides.drawing.capi_x86_64_libstdcpp_libc2.23: cannot open shared object file: No such file or directory

at System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(String libraryName, Assembly assembly, Nullable1 searchPath, Boolean throwOnError) at .(String , Assembly , Nullable1 )
at System.Runtime.InteropServices.NativeLibrary.LoadLibraryCallbackStub(String libraryName, Assembly assembly, Boolean hasDllImportSearchPathFlags, UInt32 dllImportSearchPathFlags)
at .d(Int32 d, Int32 v, Int32 c, IntPtr& t)
at System.Drawing.Bitmap…ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap…ctor(Int32 width, Int32 height)
at …cctor()
— End of inner exception stack trace —
at …ctor(Presentation )
at e…ctor(TextFrame )
at Aspose.Slides.TextFrame…ctor(e )
at Aspose.Slides.AutoShape.()
at .(IAutoShape ,  ,  )
at .(e , IGroupShape ,  )
at .(IGroupShape ,  ,  )
at .(IBaseSlide , e ,  )
at .(IMasterSlide )
at .(IPresentation )
at .(e , IPresentation )
at .(Presentation , Stream , InterruptionToken )
— End of inner exception stack trace —
at .(Presentation , Stream , InterruptionToken )
at Aspose.Slides.Presentation.(Stream , Boolean )
at Aspose.Slides.Presentation.(Stream , Boolean )
at Aspose.Slides.Presentation…ctor(Stream stream, LoadOptions loadOptions)
at Aspose.Slides.Presentation…ctor(Stream stream)

@Harshika_Sharma,
We are sorry that you encountered this problem. Could you please specify the OS version on which the error occurs?

That would be AmazonLinux2 (x86x64).

@Harshika_Sharma,
Thank you for the additional information. I need some time to check the issue. I will get back to you soon.

Sure, no problem.
@andrey.potapov , I had one more question, would I need Aspose.Drawing alongwith Aspose.Slides to do the ppt/pptx to pdf conversion? Or Aspose.Slides shall be sufficient alone?

@Harshika_Sharma,

No, you don’t need Aspose.Drawing to use Aspose.Slides for .NET.

Unfortunately, I was unable to reproduce the error you described on Amazon Linux 2. Please try using the sample project: CrossPlatformApp.zip (1.5 MB).
Please note that you need to copy files from
Aspose.Slides_25.2.zip\Aspose.Slides\net6.0\crossplatform
to
CrossPlatformApp\NetcoreApp\Assemblies\Aspose.Slides\net6.0\crossplatform
to work.
I hope this will help you.

Is there a way to not add hardcoded dependencies in the project ?
We want to restore the libraries by dotnet restore only.

@Harshika_Sharma,
Alternatively, you can use Aspose.Slides.NET6.CrossPlatform instead of Aspose.Slides for .NET.

For the trial version, when I am trying to get a license, should the Product - “Aspose.Slides for .NET” suffice for Aspose.Slides.NET6.CrossPlatform package ?

@Harshika_Sharma,
Yes, of course, that will be enough for using Aspose.Slides for .NET and Aspose.Slides.NET6.CrossPlatform.