CAD dxf to svg conversion - scaling issues and preserving colors

I am trying to convert dxf to svg using the java library. The converted svg is very big. Are there any options to set the scaling parameters, additionally the colors should be retained in the svg.

public static void main(String[] args) throws Exception {
        // Replace these paths with your actual file locations
        String inputDxfFilePath = "dxftoconvert.dxf";
        String outputSvgFilePath = "output.svg";

        // Load the DXF file
        try (CadImage image = (CadImage)Image.load(inputDxfFilePath)) {
            // Create SvgOptions for desired output format (optional)
            SvgOptions svgOptions = new SvgOptions();
            // Set layer to export (optional)
            SvgOptions svgOpts = new SvgOptions();
            CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
            rasterizationOptions.setLayouts(null);
            svgOpts.setUseAbsoluteRescaling(false);
            svgOpts.setTextAsShapes(false);
            svgOpts.setPalette(image.getPalette());
            svgOpts.setVectorRasterizationOptions(rasterizationOptions);
            // Convert to SVG and save
            image.save(outputSvgFilePath, svgOptions);
            System.out.println("DXF file converted to SVG successfully!");
        }
    }

Is there any documentation for advanced conversion.
Rectangle-layers.zip (33.3 KB)

@brahmajipusuluri,
Hello.
Thanks for details provided. Please try is these options are useful:

final CadImage cadImage = (CadImage)Image.load(inputFile);

CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1000);
rasterizationOptions.setPageHeight(1000);
rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);

SvgOptions svgOptions = new SvgOptions();
svgOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save(outputSvgFilePath, svgOptions);

You can find here also API reference and documentation.

1 Like