How to convert pptx to tiff using C#

Hi,

When I convert the attached Basic.pptx to a multipage TIFF file with GroupDocs.Conversion v19.9.0, I get an OutOfMemoryException. I’ve attached a simple function to repro the issue.

I am running as x86 on a VM with 10GB showing 3GB available. Please also see the attached OutOfMemory.zip containing a screenshot from the debugger, text file with the stack trace, and packages.config indicating what version of the specific product is being used.

 var convertOptions = new ImageConvertOptions
 {
    Format = ImageFileType.Tiff, 
    Grayscale = false,
    TiffOptions = { Compression = TiffCompressionMethods.Lzw },
    HorizontalResolution = 400,
    VerticalResolution = 400,
 };

 using (var converter = new GroupDocs.Conversion.Converter(() => File.OpenRead(sourceFile))) 
 {
    converter.Convert(() => new FileStream(destFile, FileMode.OpenOrCreate), convertOptions);
 }

Thanks in advance for any guidance you can provide on avoiding or working around this issue.
-Jonathan

OutOfMemory.png (111.0 KB)
OutOfMemory.zip (331.3 KB)

@jisabell,

Can you please try this code (set source and output files path as per your requirements):

string outputFileTemplate = Path.Combine(@"D:\Data", "converted-page-{0}.tiff");
SavePageStream getPageStream = page => new FileStream(string.Format(outputFileTemplate, page), FileMode.Create);
string sourceFile = @"C:\Users\ABC\Downloads\OutOfMemory\OutOfMemory\";
using (Converter converter = new Converter(sourceFile + "Basic.pptx"))
{
    ImageConvertOptions options = new ImageConvertOptions
    {
        Format = ImageFileType.Tiff,
        Grayscale = false,
        TiffOptions = { Compression = TiffCompressionMethods.Lzw },
        HorizontalResolution = 400,
        VerticalResolution = 400,
    };
    converter.Convert(getPageStream, options);
} 

And let us know if this resolves your issue.

@atirtahir3,

No. It still gets the OutOfMemoryException even with saving to separate files.

I also wanted to mention that we would like to save the resulting pages to a multipage TIFF rather than separate TIFFs that have to be re-read and saved into a multipage TIFF.

Finally, I did find a work around that does work. If I set UsePdf=true in ImageConvertOptions with the original code, I do not get the error.

That is, this works:

 var convertOptions = new ImageConvertOptions
 {
    Format = ImageFileType.Tiff,
    Grayscale = false,
    TiffOptions = { Compression = TiffCompressionMethods.Lzw },
    HorizontalResolution = 400,
    VerticalResolution = 400,
    UsePdf = true // ADDING THIS SEEMS TO ELIMINATE The OutOfMemoryException
 };

 using (var converter = new Converter(() => File.OpenRead(sourceFile))) 
 {
    converter.Convert(() => new FileStream(destFile, FileMode.OpenOrCreate), convertOptions);
 }

What is the impact of using the UsePdf option?

Thanks
-Jonathan

1 Like

@jisabell,

Good to know that your issue is resolved.

We are investigating this. Your investigation ticket ID is CONVERSIONNET-3322. As there is any further update, you’ll be notified.

1 Like