DWF to PDF conversion performance (C# .NET)

Hi there,

We are using Aspose.CAD for .NET version 20.3 and use the following code to convert the attached (Corridor-6a.zip (1.0 MB)) DWF input file to PDF:

        using (var image = Image.Load(input))
        {
            var cadPageSizes = CadPageSizesForA4(image.UnitType);
            var rasterizationOptions = new CadRasterizationOptions
            {
                PageWidth = cadPageSizes.PageWidth,
                PageHeight = cadPageSizes.PageHeight,
                UnitType = cadPageSizes.UnitType,
                DrawType = CadDrawTypeMode.UseObjectColor
            };
            image.Save(output, new PdfOptions
            {
                VectorRasterizationOptions = rasterizationOptions
            });
        }

The process takes ~45 seconds and consumes around 2Gb of memory.

Now we understand that this is a CAD file with a lot of items in it but we wanted to know if:

  1. you could look into it and see if there is a problem with the conversion
  2. is there another way to make this conversion process easier (e.g. with some loss on quality for instance).

Best regards.

@gwert,

I have observed the issue shared by you and request you to please share the working VS Solution reproducing the issue on your end along with machine specification and memory profile snapshot. We will be able to investigate the issue further on our end on provision of requested information.

Hi there,

Can you please give this a try and let us know what you see?
We will follow with more data, sure, but this pretty obvious on our side and most likely it will be on your side as well.
The DWF file contains a lot of small items.

Thank you!

@gwert,

I requested you to please share the following information.

I have tried to create a sample project by my self and found following custom call in your code that I am unable to resolve.

        var cadPageSizes = CadPageSizesForA4(image.UnitType);

Hi there,

Here is a full working solution CadToPdf-20-3.zip (1.0 MB) that includes the input file as well.
The CadPageSizesForA4 is just a function based on code that you guys suggested in your free forum or in documentation.

We just want to understand if there is a faster/less consuming way to convert CAD files to PDF. It could involve flattening for what is worth.

Thank you.

@gwert,

Thank you for sharing the information with us. An issue with ID CADNET-1102 has been created in our issue tracking system to further investigate and resolve the issue w.r.t performance aspects. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

@gwert,

After analysis of the shared DWF file it has been observed that the sample file contains many entities (91195956 items). By default, PDF rasterization is a vector, and every entity written into a result file. So, the resultant PDF size is too large, also it consumes more time to render it.

In order to improve the speed at the cost of losing the quality, it’s possible to set ContentAsBitmap = true option in CadRasterizationOptions. As a result, the rendered PDF will contain an image inside except each separate entity, also for an attached sample it will be more than 2 times faster.

I hope the shared elaboration will be helpful.

Hi there,

Here is the output I get using the working solution that I sent you DwfAsBitmap.zip (833 Bytes).

Can you please share the output that you got and how you got it?

Thank you!

@gwert,

I have checked the output, its extremely tiny. Can you please provide the sample project used on your end to obtain this so that we proceed further from there.

Hi there,

The project is the one I shared before. See https://forum.aspose.com/uploads/default/38341

Thank you!

@gwert,

I have tested the sample project on my end as it is and it took 77 seconds to render the PDF.

However, when I added following modification in your project, the rendering time reduced to 40 seconds. The following is what we have suggested to you and it shows notable improvement.

using (var image = Image.Load(inputFileName))
            {
                var cadPageSizes = CadPageSizesForA4(image.UnitType);
                var rasterizationOptions = new CadRasterizationOptions
                {
                    PageWidth = cadPageSizes.PageWidth,
                    PageHeight = cadPageSizes.PageHeight,
                    UnitType = cadPageSizes.UnitType,
                    DrawType = CadDrawTypeMode.UseObjectColor
                    ,ContentAsBitmap = true
                };
                image.Save(outputFileName, new PdfOptions
                {
                    VectorRasterizationOptions = rasterizationOptions
                });
            }

Hi there,

The performance is there, I confirm that. :slight_smile:

BUT the output is garbage. Please see the one that I get on my Win 10 machine and that I attached to this thread yesterday https://forum.aspose.com/uploads/default/39534.

Let me know what am I missing.

Best regards.

@gwert,

I tested the same sample project and used the same DWF file that you have shared with me without any other change then suggested modification and it produced a 22 MB PDF file. Can you please confirm that the garbage PDF that you are referring has been generated from same source file for which a 22 MB PDF has been generated on my end using same code or is there a different file or code used.

If that is a different file and producing garbage result using same sample project, then please share that file with us.

Hi there,

Here is the what I use on a Win 10 machine: CadToPdf-tiny-output.zip (1.0 MB)

It references version 20.3 of both Aspose.CAD and Aspose.PDF.

Thank you!

@gwert,

Using latest sample project, I am able to reproduce issue of 2 KB generated PDF. I have associated the information in our issue tracking system so that we my share feedback with you as soon as the issue will be fixed.

The issues you have found earlier (filed as CADNET-1102) have been fixed in this update.