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