Multi-page DWG to JPEG conversion

Converting a multi-page DWG file to JPEG does not work.
Result of conversion:

  • Only one jpeg file is generated.
  • The color is not the original color in DWG file.

I have search in documentation and sample codes but I cannot find any information on how to make the correct conversion.

Do you have any reference on how to do the conversion in the correct way?

@franciss

Can you please share the DWG file with us having multiple pages. Secondly, for color related issue, please share the generated output and used sample code.

Hi @mudassir.fayyaz .

Thanks for replying.

  1. Can you please share the DWG file with us having multiple pages.
    Attached is the DWG file with multi-pages.
    colorwh.zip (1.5 MB)

  2. Secondly, for color related issue, please share the generated output and used sample code.

  • regarding color issue, I already solved it using “rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);”

  • about not saving each page, I cannot seem to find documentation how to do it.
    Below is the sample code I tried.

    public void convertToJpeg(File sourceFile, File targetFile, Float width, Float height) {

        CadImage image = (CadImage)Image.load(sourceFile.toString());

        // Create an instance of CadRasterizationOptions and set its various properties
        CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();

        CadLayoutDictionary layouts = image.getLayouts();
        List<String> layoutNames = new ArrayList<>();
        int i = 0;
        for(var layout : layouts.getValues())
        {
            layoutNames.add(layout.getLayoutName());
        }


        // Set Page Width/Height
        float pw = width;
        float ph = height;

        rasterizationOptions.setPageWidth(pw);
        rasterizationOptions.setPageHeight(ph);
        String[] stringArray = layoutNames.toArray(new String[0]);
        rasterizationOptions.setLayouts(layoutNames.toArray(stringArray));

        rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);

        // Create an instance of JpegOptions
        JpegOptions options = new JpegOptions();

        // Set the VectorRasterizationOptions property as CadRasterizationOptions
        options.setVectorRasterizationOptions(rasterizationOptions);

        // Export to JPEG
        image.save(targetFile.toString(), options);
    }

@franciss

Can you please share the generated PDF and highlight what issue you are having. Using online free Aspose.CAD viewer and other tools, I am getting identical PDF files.

@mudassir.fayyaz

Sorry for the confusion.

Its actually a conversion from DWG direct to JPEG.
Not DWG->PDF->JPEG.

@franciss
Please check the PNG generated using Aspose tool. I am more interested in output that you are getting and observing that to be wrong. Please share the generated and desired output with us.

page_1 2.png (174.7 KB)

@mudassir.fayyaz

Thank you for the help.

I was able to solved the problem.

I use CadLayoutDictionary to get the layouts of DWG files.
For each layouts, I convert it to JPEG.

Again, thank you.

@franciss

That’s good to hear that using individual layout and exporting that to JPEG/PNG has worked on your end. Please feel free to share if there is any further requirement in this regard.