DXF to PNG margins issue

We are in the process of testing few scenarios before we proceed with aspose.cad licensing. I’m trying to convert a DXF file to a PNG but i can’t figure out how to get rid of the additional white space that get added around the output image(below)

output_with_margin.png (717.1 KB)

The only way i manage to get rid of the extra space in above image is by adding hardcoded Margins in CadRasteriztionOptions and i dont want to do that, i just want image to be as per specified page width and height(which is happening) but docked to bottom left corner:

my code

class Program
{
    static void Main(string[] args)
    {
        using (var image = Aspose.CAD.Image.Load("C:\\Work\\CBA\\The Foundry_02.dxf"))
        {
            // create an instance of CadRasterizationOptions and set page height & width
            var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
            {
                PageWidth = 11968,
                PageHeight = 4994,
                AutomaticLayoutsScaling = true,
                NoScaling = false,
                //Margins = new Margins
                //{
                //    Top = 0,
                //    Right = -3000,
                //    Bottom = -2570,
                //    Left = -3080
                //},
            };

            var options = new Aspose.CAD.ImageOptions.PngOptions();

            // set the VectorRasterizationOptions property as CadRasterizationOptions
            options.VectorRasterizationOptions = rasterizationOptions;

            // export DXF to PNG
            image.Save("output.png", options);
        }
    }
}

if i uncomment margins in above code then i am able to get desired output
desired_output.png (1.0 MB)

@TJ1981

You can consider selecting the layouts inside DWG/DXF while rendering to PDF or PNG. Secondly, there will be still extra white space

You can also refer to following thread link.

  1. You can update entity properties, and then call UpdateSize() to recalculate page min and max point.

For example:

((DwfWhipPolyline)entities[0]).Points[0].X = 0;
((DwfWhipPolyline)entities[0]).Points[0].Y = 0;
image.UpdateSize();
  1. It is possible to update font name for text entities before export.
    For example:
  ReadOnlyCollection<DwfWhipDrawable> entities = ((DwfImage)image).Pages[0].Entities;

  foreach (DwfWhipDrawable drawable in entities)
    {
     if (drawable is DwfWhipText)
       {
        ((DwfWhipText)drawable).Font.Name.Value.AsciiString = "Arial";
       }
    }

Thanks for your reply @mudassir.fayyaz, are you saying i cannot git rid of the extra white space around the output?

Also, the thread link you posted “Converting dwf to image makes the margins” is marked as Private. Please can you give me access

@TJ1981

There is some improvement you can achieve by selecting layers and entities in exported output and other is by setting margin values in negative as well will serve the purpose as given in thread link that I have shared.