Free Support Forum - groupdocs.com

Docx => TIFF LZW GDI+ error


#1

I’m getting a GDI+ error using the code below with the attached document. Stack following.

The document is intended to stress memory usage. It appears to me that Aspose is failing to save my LZW TIFF. Looking at the stack, it’s clear you’re writing pages to the output TIFF using .NET GDI using a stream as output. What I’m not sure of is if it’s a memory stream or a disk stream and how/if I can control that. If it’s a memory stream, I’m worried I’m running out of memory and would prefer to output directly to disk as that is my final medium.

I haven’t found an incarnation of ConversionHandler.Convert that takes a destination stream. Can it be set in the save options and I’m just not seeing it?

Code:
` var config = new ConversionConfig();

 var conversionHandler = new ConversionHandler(config);
 var imageSaveOptions = new ImageSaveOptions
 {
    ConvertFileType = ImageSaveOptions.ImageFileType.Tiff,
    Grayscale = true,
    TiffOptions =
    {
       Compression = TiffOptions.TiffCompression.Lzw
    },
    HorizontalResolution = 203,
    VerticalResolution = 192,
 }; 

    using (var source = File.OpenRead(parameters.Source.File)) 
    {
       using (var destination = File.OpenWrite(parameters.Target.File))
       {
          using (var result = conversionHandler.Convert(source, imageSaveOptions))
          {
             result.Save(destination);
          }
       }
    }`

Stack:
at System.Drawing.Image.SaveAdd(Image image, EncoderParameters encoderParams) at .( ) at .(Int32 , Stream ) at . ( ) at . ( ) at Aspose.Words.Document.( , SaveOptions ) at Aspose.Words.Document.(Stream , String , SaveOptions ) at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions) at . (Stream ) at . (Stream , SaveOptions ) at .( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at . ( , SaveOptions ) at GroupDocs.Conversion.Handler.ConversionHandler.( , SaveOptions ) at GroupDocs.Conversion.Handler.ConversionHandler.Convert(Stream fileStream, SaveOptions saveOptions)

Source document:
LargeDocx.zip (366.8 KB)

Thanks
-Jonathan


#2

@jisabell,

Thanks you for taking interest in GroupDocs.Conversion for .NET and posting your concerns.

This issue is reproduce at our end as well. Hence, it has been logged in our internal issue tracking system with ID:CONVERSIONNET-2528.

We are further investigating it. Once we have an update, we shall notify you.


#3

@atirtahir3,

Thanks for the prompt response. I look forward to the update on the investigation.

-Jonathan


#4

@jisabell,

You are welcome. Sure, we shall inform you as we have any update.


#5

@jisabell,

Can you please share your system requirements:

  • OS
  • Memory (RAM)

If system memory is occupied with a lot of other resources, then you get this error/exception. We investigated this scenario on a 12GB memory and noticed, if there is only little memory available, this exception is generated. Otherwise, we can easily get converted document.
We used following code snippets in our investigation:

Rendering image as stream

ConversionHandler conversionHandler = Common.getConversionHandler(); ;
             
            var saveOptions = new ImageSaveOptions
            {
                ConvertFileType = outputFileType,
                Grayscale = true,
                TiffOptions = { Compression = TiffOptions.TiffCompression.Lzw },
                HorizontalResolution = 203,
                VerticalResolution = 192,
            };

            // Convert and save converted image file. 
            

            ConvertedDocument convertedDocumentPath;
            using (var inputstream = File.Open(Path.Combine(Common.storagePath + "/"+ Common.inputGUIDFile), FileMode.Open))
            {
                convertedDocumentPath = conversionHandler.Convert(inputstream, saveOptions);
            }

            for (int pagenum = 1; pagenum <= convertedDocumentPath.PageCount; pagenum++)
            {
                convertedDocumentPath.Save("result-" + pagenum.ToString() + "." + outputFileType, pagenum);

            }

Rendering image as path

ConversionHandler conversionHandler = Common.getConversionHandler(); ;

            // Convert and save converted image file.
            // Returns paths to the converted image file.
            var saveOptions = new ImageSaveOptions
            {
                ConvertFileType = outputFileType,
                TiffOptions = { Compression = TiffOptions.TiffCompression.Lzw},
                HorizontalResolution = 203,
                VerticalResolution = 192,
            };
            

            var convertedDocumentPath = conversionHandler.Convert(Common.inputGUIDFile, saveOptions);

            for (int pagenum = 1; pagenum <= convertedDocumentPath.PageCount; pagenum++)
            {
                convertedDocumentPath.Save("result-" + Path.GetFileNameWithoutExtension(Common.inputGUIDFile) + pagenum.ToString() + "." + outputFileType, pagenum);

            }