Generating preview for multipage CDR to webP

We are trying to generate a preview from multipage Corel draw file(cdr) to webp and we encountered this exception.

Aspose.Imaging.CoreExceptions.ImageSaveException: Image saving failed. —> Aspose.Imaging.CoreExceptions.ImageSaveException: Image export failed. —> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at #=zgfEbFttj7OqPctXcl$Uz6ERSXpit_V8jyrfOVKsME_RdA4qFl6BHnYiPvdRs.#=zfeZHrGZtanTdZ$vMqA==(#=zGnTa9FNmw9p8n8NFlHzOprRikcgLVSfsEM3YUnolo4cLLlJ_2xHDMrROuHgzgZMz2w== #=z9gcl3o8=)
at #=zgfEbFttj7OqPctXcl$Uz6ERSXpit_V8jyrfOVKsME_RdA4qFl6BHnYiPvdRs.#=zDtlGNRpBk5_L(#=zArK_ghb4HuszVn6mnasQWC2pt39qOYwQ0Z2YZQ5gZTGNy6AuAtpZ$TG7EpVe36$ooA== #=zOR5H2Hs=)
at #=zd0gllY43NtQOxfCH_s3krRWLCt5yhW9UADBsj$cqoKKM9TCrYNVBaO_38uSZg_XCZXF_h4raTQ4a.#=zxsFSChqjKPn8(#=zhF7X4_8= #=zE10bi84=)
at #=zd0gllY43NtQOxfCH_s3krRWLCt5yhW9UADBsj$cqoKKM9TCrYNVBaO_38uSZg_XCZXF_h4raTQ4a.#=zw20xeM7zONAb(#=zhF7X4_8= #=zE10bi84=, Int32& #=z9c$YoaizJLMX)
at #=zGGsdwz1F4EqmdCeyPHWKQua6cBs1LwvbE9Dc7bf2pcyLvll31l85yNfgJAAvtPKZ3A==.#=zI_dBEA9uuhlE(Int32 #=zEyuV_bI=, Boolean #=zrWA$Q0B4HvELHYDRCQ==, Boolean #=zAdPmR6ECCphl, Int64 #=zqd$_61q3kr4E, Int32& #=z$3O9FZQLrQ0y, Int32& #=zCb9X8eE=)
at #=zGGsdwz1F4EqmdCeyPHWKQua6cBs1LwvbE9Dc7bf2pcyLvll31l85yNfgJAAvtPKZ3A==.#=zpVi9sP1Y9FLT(Boolean #=zAdPmR6ECCphl)
at #=zGGsdwz1F4EqmdCeyPHWKQua6cBs1LwvbE9Dc7bf2pcyLvll31l85yNfgJAAvtPKZ3A==.#=zJDe3MxE=(#=zmgRfwJyUyii3cp1EnXbmYR0_ExTLtx9gaF2vPIhR8TyEtfpaFdayY2o= #=z33QejhY=, Int32 #=zZ8D8D4k=, Int32 #=z3r$rhNs=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zY2OFobISnxbIptE3Xj69LE8i10z7(Object #=z_TROKgI=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zElWDNL0TQLQJ3eEdVxKZohU=(MethodBase #=z_TROKgI=, Boolean #=zyCPY02I=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=z8L9pmROGq$Y2$I9cWZuNUn3ISs7o()
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zTmXfPL9e15OQG364q9JQ9dSutLDR(Boolean #=z_TROKgI=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zY2OFobISnxbIptE3Xj69LE8i10z7(Object #=z_TROKgI=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zoa$kyljH3JONwQNHtwoczy42EdWi()
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=z8L9pmROGq$Y2$I9cWZuNUn3ISs7o()
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zTmXfPL9e15OQG364q9JQ9dSutLDR(Boolean #=z_TROKgI=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zY2OFobISnxbIptE3Xj69LE8i10z7(Object #=z_TROKgI=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zoa$kyljH3JONwQNHtwoczy42EdWi()
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zHPb07SKD$J2Q_COx$5DUwd_QoEJbEB9RzHVJGPw=(Object #=z_TROKgI=, UInt32 #=zyCPY02I=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zTmXfPL9e15OQG364q9JQ9dSutLDR(Boolean #=z_TROKgI=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=zTmXfPL9e15OQG364q9JQ9dSutLDR(Boolean #=z_TROKgI=)
at #=qWvdVq2GG1E$YyHOj9o1aFKXy4pKS1QM11Wp7EspsTTw=.#=z8N1_sXxY2si5CejlW_FP_UXTG$Q2stPhKKEg1TonwS2m(Object[] #=z_TROKgI=, Type[] #=zyCPY02I=, Type[] #=zSH85idM=, Object[] #=zKtmmm4o=)
at #=zdtoPTkXbJFxHW2$_4Gh1SF9bma64tSJz1XFkAr15bBUZXwwwUw==.#=z9YsaCZo=(#=zmgRfwJyUyii3cp1EnXbmYR0_ExTLtx9gaF2vPIhR8TyEtfpaFdayY2o= #=z77PZ5jw=)
at #=znag_Zx$32dEVsKXoGDkySa4eaHEEpMarmJDlKv9gssq4iGYK81AClhU=.#=zKgF96zg=(#=zG$GBq4s= #=zOLm3Kck=, RasterImage #=zF5VoE655OCKOwSdj2w==, Stream #=z7ZmspA4=, ImageOptionsBase #=zOP2zRI8=, Rectangle #=z9ZoJ0wOLVubw)
at #=zmI$CMWYKMneTIZeivNnNDvED0CbHyFXa7ausiw78ffBMYsKih4u9QxK25qsX.#=zKgF96zg=(#=zG$GBq4s= #=zOLm3Kck=, Image #=zjPfc$Ns=, Stream #=z7ZmspA4=, ImageOptionsBase #=zOP2zRI8=, Rectangle #=z9ZoJ0wOLVubw, Rectangle #=zbdQg$a2VvPmwNEsA3w==)
at #=zOX811h2SighiJ$zQn_dT486b6APY$BrR13nqV6nRv2KdqL3TSQ==.Export(Image #=zjPfc$Ns=, Stream #=z7ZmspA4=, ImageOptionsBase #=zOP2zRI8=, Rectangle #=zbdQg$a2VvPmwNEsA3w==)
at Aspose.Imaging.Image.Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
— End of inner exception stack trace —
at Aspose.Imaging.Image.Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
at Aspose.Imaging.Image.Save(String filePath, ImageOptionsBase options, Rectangle boundsRectangle)
— End of inner exception stack trace —
at Aspose.Imaging.Image.Save(String filePath, ImageOptionsBase options, Rectangle boundsRectangle)
at Aspose.Imaging.Image.Save(String filePath, ImageOptionsBase options)

Here is our code on how we use the Aspose.Image to create different file format but concentrate on the webp part

private bool CreatePreviews(CreatePreviewMediaActionBase action)
{
    const int DpiResolution = 72;
    const string CdrFormat = "CDR";

    // Only process CDR files
    if (!action.EngineFormat.Equals(CdrFormat, StringComparison.OrdinalIgnoreCase))
    {
        throw new MediaEngineException("File not supported.", false);
    }

    var stopwatch = Stopwatch.StartNew();

    try
    {
        using var inputStream = File.OpenRead(action.Path);
        long fileSizeBytes = inputStream.Length;

        using var image = Image.Load(inputStream);
        // Cast to CdrImage to access pages
        CdrImage cdrImage = image as CdrImage;
        if (cdrImage == null)
        {
            throw new MediaEngineException("Failed to load CDR image.", false);
        }

        // Get pages array - for single page CDR, Pages will contain one page
        Image[] pages = cdrImage.Pages;
        int pageCount = pages.Length;
        int pageNumber = 1;

        // Generate a preview for each page
        foreach (Image page in pages)
        {
            // Calculate preview size
            int previewWidth;
            int previewHeight;
            action.CalculateImageSize(Convert.ToInt32(page.Width), Convert.ToInt32(page.Height), DpiResolution, out previewWidth, out previewHeight);

            // Get output path based on format
            string previewPath = App.GetTemporaryFile(action.PreviewFormat.ToString());

            // Configure rasterization options with white background
            VectorRasterizationOptions rasterizationOptions = new CdrRasterizationOptions
            {
                PageWidth = previewWidth,
                PageHeight = previewHeight
            };

            // Save based on the requested format
            switch (action.PreviewFormat)
            {
                case ImageFormat.Jpg:
                    var jpegOptions = new JpegOptions
                    {
                        Quality = 75,
                        VectorRasterizationOptions = rasterizationOptions
                    };
                    page.Save(previewPath, jpegOptions);
                    break;

                case ImageFormat.Png:
                    var pngOptions = new PngOptions
                    {
                        ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha,
                        PngCompressionLevel = PngCompressionLevel.ZipLevel9,
                        FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.None,
                        Progressive = true,
                        VectorRasterizationOptions = rasterizationOptions
                    };
                    page.Save(previewPath, pngOptions);
                    break;

                case ImageFormat.WebP:
                    var webpOptions = new WebPOptions
                    {
                        Lossless = true,
                        VectorRasterizationOptions = rasterizationOptions
                    };
                    page.Save(previewPath, webpOptions);
                    break;

                default:
                    throw ErrorHelper.CreateGraphicEngineFileFormatNotSupportedForThumbnailAndPreview(App, EngineId);
            }

            // Add preview with page number (1-based)
            action.Previews.Add(new Preview(previewPath, pageNumber, previewWidth, previewHeight));
            pageNumber++;
        }

        stopwatch.Stop();

        var additionalInfo = new Dictionary<string, string>
            {
                {"Function","AsposeImagingMediaEngine.CreatePreviews" },
                {"Duration", stopwatch.ElapsedMilliseconds.ToString()},
                {"FileSizeBytes", fileSizeBytes.ToString()},
                {"PageCount", pageCount.ToString()},
                {"OutputFormat", action.PreviewFormat.ToString()}
            };

        App.WriteTrace("AsposeImagingMediaEngine", TraceSeverity.Information, additionalInfo);

        return true;
    }
    catch (ImageLoadException ex)
    {
        stopwatch.Stop();
        App.Log(LogSeverity.Error, "AsposeImagingMediaEngine.CreatePreviews: CDR files are not supported or corrupted", ex);
        throw new MediaEngineException("CDR files are not supported or corrupted.", ex, false);
    }
    catch (Exception ex)
    {
        stopwatch.Stop();
        App.Log(LogSeverity.Error, "AsposeImagingMediaEngine.CreatePreviews: An error occurred during the create preview process", ex);
        throw new MediaEngineException("An error occurred during the create preview process.", ex, false);
    }

}

On the foreach, the exception happened during the succeeding page is being save to webp. First page is successfully saved.

I will attached the test file that we’ve used.

Aspose.Imaging version installed: 25.10.0
20 PAGES HOSPITALITY BI-FOLD BROCHURE (3).zip (8.2 MB)

@3stan

Summary

You can generate previews for each page of a multi‑page CorelDRAW (CDR) file and save them as WebP with Aspose.Imaging. The exception you see (ImageSaveExceptionIndexOutOfRangeException) is a known issue in Aspose.Imaging 25.10.0 when saving the second or later page of a CDR document to WebP.

Why it happens

  • Bug in version 25.10.0 – the library had a defect in the WebP encoder that caused an out‑of‑range array access when rasterising pages after the first one.
  • The code you posted is correct for loading the CDR, iterating over cdrImage.Pages, and using VectorRasterizationOptions. The failure is not due to missing options but to the internal WebP implementation of that specific version.

What to do next

  1. Upgrade Aspose.Imaging to the latest available version (e.g., 25.11.x or newer). The bug was fixed in a later release and the same code works without changes.
  2. If you must stay on 25.10.0, apply a workaround:
var webpOptions = new WebPOptions
{
// Use lossy mode – the lossless encoder is the one that triggers the bug
Lossless = false,
// Optional: set quality (0‑100) for lossy compression
Quality = 80,
VectorRasterizationOptions = rasterizationOptions
};
page.Save(previewPath, webpOptions);

Switching to lossy mode avoids the faulty code path.
3. Ensure rasterization options are fully defined (especially PageWidth and PageHeight). You may also set a background colour to avoid transparent artefacts:

var rasterizationOptions = new CdrRasterizationOptions
{
PageWidth = previewWidth,
PageHeight = previewHeight,
BackgroundColor = Color.White
};
  1. Re‑run the preview generation. The first page should still succeed, and the subsequent pages will now be saved to WebP without throwing the exception.
  2. If the problem persists after upgrading, open a support ticket with Aspose and attach the sample CDR file and the stack trace – the support team can confirm that the issue is resolved in the current build.

By updating the library (or using the lossy WebPOptions) the preview generation for all pages of a multi‑page CDR file to WebP works as expected.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

SDK version unclear — refer to the official release notes before applying this guidance.

@3stan We will investigate the issue and inform you of the results as soon as possible.

@3stan
The issue is with the exactly second page of the file. All the others do convert correctly.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGNET-7872

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.