DWG was not published to PDF

This particular DWG was failing publishing to a PDF.

Test was done in,
Aspose version: aspose-cad 23.8
Java version 11

@Test
public void test() throws FileNotFoundException {
java.util.Locale.setDefault(Locale.US);
File dwgFile = Paths.get(TEST_RESOURCE_PATH, “notWorking.dwg”).toFile();
CadImage cadImage = (CadImage) CadImage.load(new FileInputStream(dwgFile));
saveCadImageAsPdf(cadImage, Paths.get(TEST_RESOURCE_PATH, “notWorking.pdf”).toFile());
}

private void saveCadImageAsPdf(CadImage cadImage, File pdfFile) {
final PdfOptions pdfOptions = new PdfOptions();
cadImage.save(pdfFile.getAbsolutePath(), pdfOptions);
}

@TLiljedahl

It seems that you are experiencing issues with exporting a DWG file to PDF using Aspose.CAD for Java. Here are some steps and considerations that might help you resolve the problem:

  1. Check the DWG File: Ensure that the DWG file you are trying to convert is not corrupted and is compatible with Aspose.CAD. Sometimes, specific DWG files may have elements that are not supported for conversion.

  2. Set Rasterization Options: When exporting DWG files, it is essential to configure the rasterization options properly. You can create an instance of CadRasterizationOptions and set properties such as PageWidth and PageHeight to define the output PDF dimensions.

  3. Configure PDF Options: You should also set up the PdfOptions correctly. Make sure to assign the rasterization options to the VectorRasterizationOptions property of the PdfOptions instance.

  4. Example Code: Here’s a modified version of your code that includes rasterization options:

    import com.aspose.cad.*;
    import com.aspose.cad.imageoptions.*;
    
    public class DwgToPdfConverter {
        public static void main(String[] args) throws FileNotFoundException {
            java.util.Locale.setDefault(Locale.US);
            File dwgFile = Paths.get(TEST_RESOURCE_PATH, "notWorking.dwg").toFile();
            CadImage cadImage = (CadImage) CadImage.load(new FileInputStream(dwgFile));
            saveCadImageAsPdf(cadImage, Paths.get(TEST_RESOURCE_PATH, "notWorking.pdf").toFile());
        }
    
        private static void saveCadImageAsPdf(CadImage cadImage, File pdfFile) {
            CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
            rasterizationOptions.setPageWidth(1600);
            rasterizationOptions.setPageHeight(1600);
    
            PdfOptions pdfOptions = new PdfOptions();
            pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
    
            cadImage.save(pdfFile.getAbsolutePath(), pdfOptions);
        }
    }
    
  5. Check for Exceptions: If the conversion fails, ensure to catch exceptions and log the error messages. This can provide insights into what might be going wrong during the export process.

  6. Consult Documentation: For more detailed guidance, you can refer to the official Aspose documentation on exporting DWG files to PDF, which provides step-by-step instructions and additional options you can configure.

If you continue to face issues, consider checking the Aspose.CAD forum for similar cases or posting your specific error messages for further assistance.

Sources:
[1]: Export DWG to PDF or Raster Using Aspose.CAD for Java
[2]: Export Specific DWG Layout to PDF Using Aspose.CAD for Java

Hello,

I’ve already tested with setting the rastrerzationOptions as shown in your example and it throws the same exception.
The exception:

class com.aspose.cad.internal.Exceptions.Exception: Error during PDF export: index ---> class com.aspose.cad.internal.Exceptions.ArgumentException: index
com.aspose.cad.internal.gm.e.<init>(Unknown Source)
com.aspose.cad.internal.fp.d.a(Unknown Source)
com.aspose.cad.internal.fp.d.a(Unknown Source)
com.aspose.cad.internal.fm.k.a(Unknown Source)
com.aspose.cad.internal.fm.k.b(Unknown Source)
com.aspose.cad.internal.ga.b.a(Unknown Source)
com.aspose.cad.internal.ga.c.a(Unknown Source)
com.aspose.cad.s.a(Unknown Source)
com.aspose.cad.internal.b.e.invoke(Unknown Source)
com.aspose.cad.system.Threading.j.invoke(Unknown Source)
com.aspose.cad.system.Threading.n.run(Unknown Source)
java.base/java.lang.Thread.run(Thread.java:840)

Also tried with

        CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
        rasterizationOptions.setPageWidth(cadImage.getWidth());
        rasterizationOptions.setPageHeight(cadImage.getHeight());

Which gives the same exception. If we should go through with aspose as solution it needs to be able to handle all our DWG files with the same code. Currently 1 out of 15 fail.

To me the exception is really cryptic and I can’t really figure out whats going wrong.

I’m not an expert of the DWG format, so it is hard for me to tell if the file is corrupted, maybe @TLiljedahl can fill in information about this.

Hi, the DWG file is not corrupted it can be opened and possible to save out a manual PDF from AutoCAD

@TLiljedahl,
Hello,
please share the initial DWG file so we can reproduce the issue, and please specify what is the error on your side?

notWorking.zip (248.8 KB)

Here is the file

@TLiljedahl,
we can confirm the issue, and created CADJAVA-11758 task to solve it.

Hi, have you any estimate of the timeline of the task and if it is complex?

@TLiljedahl,
Hi.
The issue appears with ACAD_PROXY entities and seems not very complex to fix. It is planned for the next 24.11 release in November, but the corresponding Java version will appear later, probably, till the end of the year, but we can not guarantee this. As a temporarily workaround you can try to explode these entities in the drawing.