Some pages are missing when converting from CAD to PDF

I have a DWG document with multiple pages, and when I convert to PDF, some of the pages are missing.

The demo code

void Main()
{
	var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
	{
		DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor
	};
	
	using (var dwgDoc = Load(@"C:\Users\54390\Downloads\demo.dwg"))
	{
		dwgDoc.Save(@"C:\Users\54390\Downloads\demo.pdf", new Aspose.CAD.ImageOptions.PdfOptions() { VectorRasterizationOptions = rasterizationOptions });
	}
}

The demo file

demo.zip (1.4 MB)

The screenshot

20230708101039.png (83.6 KB)

@sullivan,
Hello.

Some default layouts with the same content as Model are ignored by default. If you need to export all existing layouts anyway you can add this option to the rasterizationOptions:

Layouts = new List<string>(cadImage.Layouts.KeysTyped).ToArray()

Sometimes we observe also that the size of the drawing in the file may be not correct. In this case manual update of size may be useful after loading but before export:

cadImage.UpdateSize();

Here is my result with these two options: demo.dwg.pdf (3.3 MB)

@oleksii.gorokhovatskyi

Thank you for your reply, I tried your method and it worked, but I found another problem when processing other files.It has only one Layout , but the exported PDF has two pages with the same content

void Main()
{
	
	using (var dwgDoc = Load(@"C:\Users\54390\Desktop\demo.dwg"))
	{
		var cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)dwgDoc;
		var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
		{
			DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor,
			Layouts = new List<string>(cadImage.Layouts.KeysTyped).ToArray()
		};

		cadImage.UpdateSize();
		dwgDoc.Save(@"C:\Users\54390\Desktop\output.pdf", new Aspose.CAD.ImageOptions.PdfOptions() { VectorRasterizationOptions = rasterizationOptions });
	}
}

The demo file

demo.zip (5.2 MB)

@sullivan,
this is because Model is itself a Layout too, so there are 2 pages - Model and Layout 1. You can remove “Model” from the list that is put to Layout property of the options and will see one page only.

@oleksii.gorokhovatskyi
Is all CAD files contain at least Model and one or more Layouts? Will it cause other problems if I remove Model from the list?

@sullivan,
It depends on the format. DWG/DXF files should contain Model sheet at least (and it is not possible to rename it as far as we know). So there will be no problems if you just ignore Model sheet for export.