Part of DWF missing

Hi,

When I convert [this file] using the code below, the output file is missing a sidebar on the right side of the CAD file, is there an option I am setting wrong?

using System.IO;
using Aspose.CAD;
using Aspose.CAD.FileFormats.Cad;
using Aspose.CAD.FileFormats.Dwf;
using Aspose.CAD.FileFormats.Ifc.IFC2X3.Entities;
using Aspose.CAD.ImageOptions;
using static System.Net.Mime.MediaTypeNames;


namespace AsposeCad
{
internal class Program
{
static void Main(string[] args)
{
var inputFilePath = “input.dwfx”;
var outputFilePath = “input.pdf”;


        Console.WriteLine($"Loading file: {inputFilePath}");
        try
        {
            /*using (var cadImage = Image.Load(inputFilePath))
            {
                var rasterizationOptions = new CadRasterizationOptions()
                {
                    PageWidth = 3000,
                    PageHeight = 3000
                };

                var pdfOptions = new PdfOptions
                {
                    VectorRasterizationOptions = rasterizationOptions
                    cadRasterizationOptions.UnitType = Aspose.CAD.ImageOptions.UnitType.Centimenter;
            };

                Console.WriteLine($"Converting {inputFilePath} to {outputFilePath}");
                cadImage.Save(outputFilePath, pdfOptions);
            }*/

            //using (Aspose.CAD image = Aspose.CAD.Image.Load(inputFilePath))

            using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(inputFilePath))
            {

                CadImage cadImage = (CadImage)image;// -> working for DWG
                //DwfImage cadImage = (DwfImage)image; -> working for DWXF
                //DxfImage cadImage = (DxfImage)image;
                    cadImage.UpdateSize(); //--> works for all other filetypes except DXF
                /*foreach (var entity in cadImage.Entities)
                {
                    entity.LineWeight = 0;
                }*/
                /*foreach (Aspose.CAD.FileFormats.Cad.CadTables.CadLayerTable layer in cadImage.Layers)
                {
                    layer.LineWeight = 0;
                }*/

                // Create an instance of CadRasterizationOptions and set its various properties
                Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
                //rasterizationOptions.PageWidth = 1600;
                //rasterizationOptions.PageHeight = 1600;
                 //rasterizationOptions.AutomaticLayoutsScaling = false;
                 //rasterizationOptions.ScaleMethod = ScaleType.GrowToFit;
                 //rasterizationOptions.NoScaling = false;
                rasterizationOptions.DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor;
                //rasterizationOptions.Layers = new string[] { "0" };


         //rasterizationOptions.ContentAsBitmap = true;
                rasterizationOptions.Quality = new RasterizationQuality();
                var quality = new RasterizationQuality();
                quality.Arc = RasterizationQualityValue.High;
                quality.Text = RasterizationQualityValue.High;
                quality.TextThicknessNormalization = true;
                quality.Hatch = RasterizationQualityValue.High;
                quality.ObjectsPrecision = RasterizationQualityValue.High; // -> works for all fileformats

                // Export to specific size
                bool currentUnitIsMetric = false;
                double currentUnitCoefficient = 1.0;
                DefineUnitSystem(image.UnitType, out currentUnitIsMetric, out currentUnitCoefficient);

                Console.WriteLine("Dealing with units");
                Console.WriteLine(currentUnitIsMetric + " unit " + currentUnitCoefficient);

            
                if (currentUnitIsMetric)
                {
                    double metersCoeff = 1 / 1000.0;
                    double scaleFactor = metersCoeff / currentUnitCoefficient;
                    //rasterizationOptions.PageWidth = (float)(210 * scaleFactor);
                    //rasterizationOptions.PageHeight = (float)(297 * scaleFactor);
                    rasterizationOptions.UnitType = UnitType.Millimeter;
                }
                else
                {
                    //rasterizationOptions.PageWidth = (float)(8.27f / currentUnitCoefficient);
                    //rasterizationOptions.PageHeight = (float)(11.69f / currentUnitCoefficient);
                    rasterizationOptions.UnitType = UnitType.Inch;
                } // works for all file types


                // Create an instance of PdfOptions
                Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();

                // Set the VectorRasterizationOptions property
                pdfOptions.VectorRasterizationOptions = rasterizationOptions;

                //Export CAD to PDF
                image.Save(inputFilePath + "_OUTPUT", pdfOptions);

                // Create an instance of TiffOptions
                Aspose.CAD.ImageOptions.TiffOptions tiffOptions = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);

                // Set the VectorRasterizationOptions property
                tiffOptions.VectorRasterizationOptions = rasterizationOptions;

                //Export CAD to TIFF
                //image.Save(inputFilePath + "result_out.tiff", tiffOptions);
            }


        //Console.WriteLine($"File {inputFilePath} converted to {outputFilePath}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error converting CAD to PDF: {ex}");
        }




    }

    private static void DefineUnitSystem(UnitType unitType, out bool isMetric, out double coefficient)
    {
        isMetric = false;
        coefficient = 1.0;

        switch (unitType)
        {
            case UnitType.Parsec:
                coefficient = 3.0857 * 10000000000000000.0;
                isMetric = true;
                break;
            case UnitType.LightYear:
                coefficient = 9.4607 * 1000000000000000.0;
                isMetric = true;
                break;
            case UnitType.AstronomicalUnit:
                coefficient = 1.4960 * 100000000000.0;
                isMetric = true;
                break;
            case UnitType.Gigameter:
                coefficient = 1000000000.0;
                isMetric = true;
                break;
            case UnitType.Kilometer:
                coefficient = 1000.0;
                isMetric = true;
                break;
            case UnitType.Decameter:
                isMetric = true;
                coefficient = 10.0;
                break;
            case UnitType.Hectometer:
                isMetric = true;
                coefficient = 100.0;
                break;
            case UnitType.Meter:
                isMetric = true;
                coefficient = 1.0;
                break;
            case UnitType.Centimenter:
                isMetric = true;
                coefficient = 0.01;
                break;
            case UnitType.Decimeter:
                isMetric = true;
                coefficient = 0.1;
                break;
            case UnitType.Millimeter:
                isMetric = true;
                coefficient = 0.001;
                break;
            case UnitType.Micrometer:
                isMetric = true;
                coefficient = 0.000001;
                break;
            case UnitType.Nanometer:
                isMetric = true;
                coefficient = 0.000000001;
                break;
            case UnitType.Angstrom:
                isMetric = true;
                coefficient = 0.0000000001;
                break;
            case UnitType.Inch:
                coefficient = 1.0;
                break;
            case UnitType.MicroInch:
                coefficient = 0.000001;
                break;
            case UnitType.Mil:
                coefficient = 0.001;
                break;
            case UnitType.Foot:
                coefficient = 12.0;
                break;
            case UnitType.Yard:
                coefficient = 36.0;
                break;
            case UnitType.Mile:
                coefficient = 63360.0;
                break;
        }
    }

}

}

This does not happen with the online converter tool.

@Pavitter,
I used this code (with Aspose.CAD for .NET 23.5) to get “Output.pdf”:

using (DwfImage cadImage = (DwfImage)Image.Load("file.dwf"))
{
   // cadImage.UpdateSize();

	Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
	rasterizationOptions.DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor;

	rasterizationOptions.Quality = new RasterizationQuality();
	var quality = new RasterizationQuality();
	quality.Arc = RasterizationQualityValue.High;
	quality.Text = RasterizationQualityValue.High;
	quality.TextThicknessNormalization = true;
	quality.Hatch = RasterizationQualityValue.High;
	quality.ObjectsPrecision = RasterizationQualityValue.High; 

	bool currentUnitIsMetric = false;
	double currentUnitCoefficient = 1.0;
	DefineUnitSystem(cadImage.UnitType, out currentUnitIsMetric, out currentUnitCoefficient);

	Console.WriteLine("Dealing with units");
	Console.WriteLine(currentUnitIsMetric + " unit " + currentUnitCoefficient);
	if (currentUnitIsMetric)
	{
		double metersCoeff = 1 / 1000.0;
		double scaleFactor = metersCoeff / currentUnitCoefficient;
		rasterizationOptions.UnitType = UnitType.Millimeter;
	}
	else
	{
		rasterizationOptions.UnitType = UnitType.Inch;
	} 

	Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
	pdfOptions.VectorRasterizationOptions = rasterizationOptions;
	cadImage.Save("OUTPUT.pdf", pdfOptions);
}

OUTPUT.pdf (3.4 MB)

Could you please clarify what is missing? Could you share your PDF result?

this result is perfect! i’ll check what the difference to my code is, thank you very much!

1 Like

@Pavitter,
we were happy to help :slight_smile:

it did convert it using the same code, but maybe my version of the Aspose SDK can’t convert it properly. I am using the nugget package in version 23.3.0.0, is that maybe outdated?

Nevermind, it works with 23.6.0.0!

1 Like

@Pavitter,
thank you :slight_smile: