We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Error while converting color DWG to PDF (UseObjectColor mode)

I modified code of demo ConvertDWGFileToPDF to convert my color image from DWG to PDF

package com.aspose.cad.examples.DWGDrawings;

import com.aspose.cad.*;
import com.aspose.cad.examples.Utils.Utils;
import com.aspose.cad.imageoptions.CadRasterizationOptions;
import com.aspose.cad.imageoptions.PdfOptions;
import com.aspose.cad.fileformats.cad.CadDrawTypeMode;

import java.awt.Image;

public class ConvertDWGFileToPDF {

public static void main(String[] args) {
	// The path to the resource directory.
    String dwgFile = "ColorDemo.dwg";
	String dataDir = Utils.getDataDir(ConvertDWGFileToPDF.class) + "DWGDrawings/";

	//ExStart:ConvertDWGFileToPDF
    String srcFile = dataDir + dwgFile;
	
	 com.aspose.cad.Image objImage = com.aspose.cad.Image.load(srcFile);

	 // Create an instance of CadRasterizationOptions and set its various properties
	CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
            rasterizationOptions.setAutomaticLayoutsScaling(true);
            rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);
            //rasterizationOptions.setBackgroundColor(Color.getWhite());
            rasterizationOptions.setPageWidth(1600);
            rasterizationOptions.setPageHeight(1600);
            // Create an instance of PdfOptions
            PdfOptions pdfOptions = new PdfOptions();
            pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
            // Export the DWG to PDF
            objImage.save(dataDir + dwgFile + ".pdf", pdfOptions);
            //ExEnd:ConvertDWGFileToPDF
}

}

While executing code i’ve got error:

Exception in thread “main” class com.aspose.cad.cadexceptions.ImageSaveException: Image saving failed. —> class com.aspose.cad.cadexceptions.ImageSaveException: Image export failed. Error during PDF export: index —> java.lang.RuntimeException: Error during PDF export: index

When I replace UseObjectColor to UseDrawColor the code above works fine

@agryzunov

In order to proceed further with investigation on our end, I request you to please share the source DWG file reproducing the issue on your end.

@agryzunov

I have observed the issue shared and a ticket with ID CADJAVA-10195 has been created to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be addressed.