Free Support Forum - aspose.com

Unable to convert DWF to PNG file using .Net

Hi,

We are getting below exception when trying to convert dwf to png file.

Exception thrown: ‘Aspose.CAD.CadExceptions.ImageLoadException’ in Aspose.CAD.dll

Here is the program I am using

using Aspose.CAD;
using Aspose.CAD.FileFormats.Dwf;
using Aspose.CAD.ImageOptions;
using System;
using System.IO;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Hello World!”);
string imgFileName = null;
int pageCount = 0;

        try
        {
            using (Aspose.CAD.Image image = Aspose.CAD.Image.Load("dwftest.dwf"))
            {
                ImageOptionsBase imgOption = new PngOptions();
                pageCount = 1;
                FileStream fileStream = null;
                DwfImage dwfImage = (DwfImage)image;                  
                foreach (var page in dwfImage.Pages)
                {
                    imgFileName = "TestDwf"  + "_" + pageCount + ".png";
                    Console.WriteLine("Convert>>page>>"+page);
                    fileStream = new FileStream(imgFileName, FileMode.Create);
                    using (MemoryStream imageStream = new MemoryStream())
                    {
                        CadRasterizationOptions options = new CadRasterizationOptions
                        {
                            Layouts = new string[] { page.Name }
                        };

                        options.PageHeight = image.Height * 300;
                        options.PageWidth = image.Width * 300;
                        imgOption.VectorRasterizationOptions = options;

                        image.Save(imageStream, imgOption);
                        Console.WriteLine("Convert>>result file>>" + imgFileName);
                        imageStream.WriteTo(fileStream);

                        // Close stream
                        fileStream.Close();
                        imageStream.Close();
                    }

                    pageCount++;
                }
            }


        }
        catch (Exception e)
        {

        }
    }
}

}

Attached is the dwftest.dwf file we are using.dwftest.zip (58.8 KB)

Thanks&regards,
Gangadhar

@kutti184,

I have worked with the DWF file shared and have been able to observe the issue. An issue with ID CADNET-977 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be fixed.