Free Support Forum - aspose.com

Dwg converted to PDF, but PDF is only black and white color,how to set to multi color

We currently using aspose.cad for java for coverting dwg file to PDF format, but we met an issue that converted PDF only contains black and white color lines(the colors are lost), could anyone assist on how to setup the tools to generate multicolor PDF?

@husong1,

I have observed your requirements shared and request you to please try using latest Aspose.CAD for Java 20.1 on your end. If there is still an issue then please share the source file and used sample code along with Operating System and Java details with us.

Thanks for the replay, mudassir. I tried the version 20.1 but the issue still exists. Below is our source code.

package com.aspose.cad.examples.DWGDrawings;

import com.aspose.cad.Color;
import com.aspose.cad.examples.Utils.Utils;
import com.aspose.cad.imageoptions.CadRasterizationOptions;
import com.aspose.cad.imageoptions.PdfOptions;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.File;
import java.io.IOException;

public class ConvertDWGFileToPDFFree {

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

    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.setBackgroundColor(Color.getWhite());
    rasterizationOptions.setPageWidth(1600);
    rasterizationOptions.setPageHeight(1600);

    // Create an instance of PdfOptions
    PdfOptions pdfOptions = new PdfOptions();
    // Set the VectorRasterizationOptions property
    pdfOptions.setVectorRasterizationOptions(rasterizationOptions);

    // Export the DWG to PDF

// objImage.save(dataDir + “_out_20200312_free_1.pdf”, pdfOptions);
objImage.save(dataDir + “linux_aspose_Bottom_plate_out_20200312_free_3.pdf”, pdfOptions);
//ExEnd:ConvertDWGFileToPDF
}

}

@husong1,

Thank you for sharing the code sample. As requested earlier, please share the source file and generated PDF with us along with Java details. I also suggest you to please try using following option on your end.

rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);

Thanks for your reply. The statement you provided solved the problem immediately. Appreciate for your help.

@husong1,

It’s good to know things are resolved on your end.