DWG to PNG rendering issue

Hi,

Please find below the updates for the tickets attached to this thread.

  • IMAGING-34275 (CAD to Raster Image Conversion): We will try our best to provide the requested feature with the upcoming release of Aspose.Imaging for .NET 2.6.0, that is scheduled for the 1st quarter of September 2014. As soon as the feature is available for public use, you will be automatically notified.
  • IMAGING-34281 (PDF seems to be blank when page dimension is too large): Upon thorough investigation, we have concluded that the presented behavior is actually not a bug of Aspose.Imaging API, rather a limitation of Acrobat Reader. It seems that Acrobat Reader cannot render a PDF page of large dimensions such as 24325 x 24325. However, other PDF viewers such as Foxit Reader, Nitro Reader, Sumatra Reader and PS_view reader which comes with LATEX distribution can render such PDF files just fine. Even the built-in PDF viewer of Opera browser can display the contents correctly. A few snapshots are attached here for your reference.
  • IMAGING-34285 (PDF seems to be blank when large DWG is rendered to smaller canvas with ScaleType.GrowToFit): As you may see that the PdfOptions configurations are wrong for this scenario. The ScaleType.GrowToFit should be used in cases where DWG dimensions are smaller as compared to the rendering canvas in order to to scale the drawing accordingly. If the scenario is opposite the ScaleType.ShrinkToFit should be configured to get desired results. Current implementation of Aspose.Imaging API silently ignores the illegal configurations as discussed above, and produces a blank PDF as a result. We will enhance the module with future releases of Aspose.Imaging API to throw appropriate exception(s) for such scenarios.
  • IMAGING-34286 (Support for textual contents in the DWG drawings for rendering to PDF): As discussed earlier, you can render the textual contents with the help of PdfOptions.LayoutName property. We will close this ticket as it has served its purpose. In case you require enhancements to this feature, we can log separate incident(s).

Regarding your recent concerns, we are not sure of your exact requirement so please elaborate your question for better understanding. If you wish to render the DWG files to raster images till the time IMAGING-34275 is resolved, we suggest you to use the Aspose.Pdf for .NET API in collaboration with Aspose.Imaging for .NET as discussed here. Please check the following links for your reference.

As i can see, only Nitro shows dwg real files without borders!

That said, as we mentioned we need to

go over these problems, converting first DWG/DXF files to PNG images and then from PNG to PDF files.
So please, insert in IMAGING-34275 other options, nowadays lacking (or open another request)
Aspose.Imaging.ImageOptions.PngOptions has no options like Aspose.Imaging.ImageOptions.PdfOptions

We need the same as pdfOption:

PngOption.DrawType = Aspose.Imaging.FileFormats.Cad.CadDrawTypeMode.UseDrawColor
OptionsI.LayoutName = szLayouts[1]; (the text layout from dwg)

Thank’s

Hi Valerio,

Boole Server:
As i can see, only Nitro shows dwg real files without borders

Foxit is also rendering the drawing centered without cutting it off from the right side. Whereas, a few viewers are not showing the right most drawing margin. The problem could be due to the reason that PdfOptions.CenterDrawing property not working as expected at the moment. We have logged an investigative ticket (IMAGING-34293) to look further into this matter, and to provide a fix for it.

Boole Server:
That said, as we mentioned we need to
go over these problems, converting first DWG/DXF files to PNG images and then from PNG to PDF files.
So please, insert in IMAGING-34275 other options, nowadays lacking (or open another request)
Aspose.Imaging.ImageOptions.PngOptions has no options like Aspose.Imaging.ImageOptions.PdfOptions

We need the same as pdfOption:

PngOption.DrawType = Aspose.Imaging.FileFormats.Cad.CadDrawTypeMode.UseDrawColor
OptionsI.LayoutName = szLayouts[1]; (the text layout from dwg)

As the requested feature (CAD to Raster Image Conversion) would be generic for all raster image formats so mostly likely the options/properties would be made available for the base class of PngOptions.

We have recorded your concerns to the related ticket, and we will discuss the matter internally to bring updates in this regard.

Ok thank you
Please let me informet about any news of resolution of IMAGING-34275 and IMAGING-34293

Hi Valerio,


Thank you for your patience with us.

We are glad to inform you that both tickets (IMAGING-34275 & IMAGING-34293) have been marked fixed. The fix will be published with the upcoming release of Aspose.Imaging for .NET 2.6.0, which is scheduled for the next week. As soon as v2.6.0 is available for public use, we will notify you here with the download link to the upgraded API.

Hello, we are trying to use new imaging 2.6.0 but we cannot see any difference!
what’s wrong?

Again exeption “cannot export non raster image” and in Aspose.Imaging.ImageOptions.PngOptions we cannot find “LayoutName” and “DrawType” (as in Aspose.Imaging.ImageOptions.PdfOptions)

We need to export original dwg file in png and then from png to pdf
This is our code:
Aspose.Imaging.ImageOptions.PngOptions OptionsI = new Aspose.Imaging.ImageOptions.PngOptions();
OptionsI.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
OptionsI.TransparentColor = new Aspose.Imaging.TransparentColorSetting(Aspose.Imaging.Color.Transparent);
Aspose.Imaging.ResolutionSetting oResI = new Aspose.Imaging.ResolutionSetting(Convert.ToDouble(m_iResolution), Convert.ToDouble(m_iResolution));
OptionsI.ResolutionSettings = oResI;
((Aspose.Imaging.Image)m_oDocument).Save(_oOutputStream, OptionsI);


again, we need to solve the exeption {“Cannot export non-raster images.”} and we need final png export WITH same options we see in PDFoptions:

string[] szLayouts = new string[((Aspose.Imaging.FileFormats.Cad.CadImage)((Aspose.Imaging.Image)m_oDocument)).Layouts.Keys.Count];
((Aspose.Imaging.FileFormats.Cad.CadImage)((Aspose.Imaging.Image)m_oDocument)).Layouts.Keys.CopyTo(szLayouts, 0);
OptionsIP.LayoutName = szLayouts[1];

OptionsIP.DrawType = Aspose.Imaging.FileFormats.Cad.CadDrawTypeMode.UseDrawColor;


Please give us some solution, now we need to solve in a short time.
Original dwg file again attached - Thank you

ps moreover in imaging 2.6.0 dll seems to be missing some Aspose.Imaging.ImageOptions.PdfOptions
as PageWidth, PageHeight, LayoutName, DrawType…
mayube they moved? where? OptionsIP.CorePdfOptions.PageHeight as example is in a read only “position”

Hi Valerio,

Thank you for testing the new release of Aspose.Imaging for .NET 2.6.0.

Please use the following piece of code to convert the DWG drawings to raster image formats.

C#

string sourceFilePath = myDir + “office.dwg”;
using (Image image = Image.Load(sourceFilePath))
{
    //Create an instance of CadRasterizationOptions
    CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
    //Set page width & height
    rasterizationOptions.PageWidth = 1600;
    rasterizationOptions.PageHeight = 1200;
    //Center the drawing
    rasterizationOptions.CenterDrawing = true;


    //Create an instance of PngOptions for the resultant image
    ImageOptionsBase options = new PngOptions();
    //Set rasterization options
    options.VectorRasterizationOptions = rasterizationOptions;

    //Save resultant image
    image.Save(myDir + "output.png", options);
}

Please note, with latest revision of Aspose.Imaging for .NET API, several of the PdfOptions properties have been moved to the new VectorRasterizationOptions and CadRasterizationOptions classes. Please go through the Public API Changes in Aspose.Imaging 2.6.0 for the future reference.

Hi,

we tried this new code but we experience some problems: basically PNG file result completely white or with some little regions draw.
You can see in the attachments original test file, image printed from a CAD viewer (representing real original image), and the two files exported with Aspose (png and PDF).

The C# code we used is this:

Aspose.Imaging.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.CadRasterizationOptions();
rasterizationOptions.BackgroundColor = Aspose.Imaging.Color.Black;
//rasterizationOptions.PageWidth = ((Aspose.Imaging.Image)m_oDocument).Width;
//rasterizationOptions.PageHeight = ((Aspose.Imaging.Image)m_oDocument).Height;
if (((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Width > ((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Height)
{
    if (((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Width > 1024)
    {
        int iWidth = 1024;
        int iHeight = (int)((1024.0f / (float)((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Width) * (float)((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Height);
        rasterizationOptions.PageWidth = iWidth;
        rasterizationOptions.PageHeight = iHeight;
    }
}
else
{
    if (((Aspose.Imaging.Image)m_oDocument).Height > 1024)
    {
        int iHeight = 1024;
        int iWidth = (int)((1024.0f / (float)((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Height) * (float)((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Width);
        rasterizationOptions.PageWidth = iWidth;
        rasterizationOptions.PageHeight = iHeight;
    }
}
rasterizationOptions.DrawColor = Aspose.Imaging.Color.White;
rasterizationOptions.DrawType = Aspose.Imaging.FileFormats.Cad.CadDrawTypeMode.UseDrawColor;
rasterizationOptions.Layers = new List { "layer1" };
rasterizationOptions.LayoutName = "layout1";

Aspose.Imaging.ImageOptions.PngOptions OptionsI = new Aspose.Imaging.ImageOptions.PngOptions();
OptionsI.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
OptionsI.TransparentColor = new Aspose.Imaging.TransparentColorSetting(Aspose.Imaging.Color.Transparent);
Aspose.Imaging.ResolutionSetting oResI = new Aspose.Imaging.ResolutionSetting(Convert.ToDouble(m_iResolution), Convert.ToDouble(m_iResolution));
OptionsI.ResolutionSettings = oResI;
OptionsI.VectorRasterizationOptions = rasterizationOptions;
((Aspose.Imaging.Image)m_oDocument).Save(_oOutputStream, OptionsI);

as you can see we tried to change background colors or draw colors, excluding text layer and so on but we can obtain only a white image or a black image.
with pdf export, even if is the same code, we obtain a partial file with some drawings (but not all and none of text layer )

The real file contains drawings and text (over draw layer and in the right part box).

This is the first (and the one) problem: a second problem is document resizing lack in Aspose.Imaging.FileFormats.Cad.CadImage class
we use this code for all type of images (works for all images):

m_oDocument = Aspose.Imaging.Image.Load(_oInputStream);
m_iPageCount = 1;
//resize
if (((Aspose.Imaging.Image)m_oDocument).Width > ((Aspose.Imaging.Image)m_oDocument).Height)
{
    if (((Aspose.Imaging.Image)m_oDocument).Width > 1024)
    {
        int iWidth = 1024;
        int iHeight = (int)((1024.0f / (float)((Aspose.Imaging.Image)m_oDocument).Width) * (float)((Aspose.Imaging.Image)m_oDocument).Height);
        ((Aspose.Imaging.Image)m_oDocument).Resize(iWidth, iHeight, Aspose.Imaging.ResizeType.NearestNeighbourResample);
    }
}
else
{
    if (((Aspose.Imaging.Image)m_oDocument).Height > 1024)
    {
        int iHeight = 1024;
        int iWidth = (int)((1024.0f / (float)((Aspose.Imaging.Image)m_oDocument).Height) * (float)((Aspose.Imaging.Image)m_oDocument).Width);
        ((Aspose.Imaging.Image)m_oDocument).Resize(iWidth, iHeight, Aspose.Imaging.ResizeType.NearestNeighbourResample);
    }
}

but if we use for dwg files, like this:

m_oDocument = (Aspose.Imaging.FileFormats.Cad.CadImage)Aspose.Imaging.Image.Load(_oInputStream);
m_iPageCount = 1;
//if (((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Width > ((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Height)
//{
//    if (((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Width > 1024)
//    {
//        int iWidth = 1024;
//        int iHeight = (int)((1024.0f / (float)((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Width) * (float)((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Height);
//        ((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Resize(iWidth, iHeight, Aspose.Imaging.ResizeType.NearestNeighbourResample);
//    }
//}
//else
//{
//    if (((Aspose.Imaging.Image)m_oDocument).Height > 1024)
//    {
//        int iHeight = 1024;
//        int iWidth = (int)((1024.0f / (float)((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Height) * (float)((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Width);
//        ((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Resize(iWidth, iHeight, Aspose.Imaging.ResizeType.NearestNeighbourResample);
//    }
//}

the instruction .Resize throw in an Exeption “method not implemented”
Why and how we can solve? Maybe it is related with first problem?
We solved moving that code in the method (above) that exports DWG to PNG but, as we said, resulting image is completely white (or black or other background color)

Can you try our code and our test Dwg file and give us correct solution to obtain a complete png (and pdf) file like the example file we attached (that represent what we see opening with a DWG viewer)?

Thank you

The issues you have found earlier (filed as IMAGING-34275;IMAGING-34293) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Valerio,


There are few problems in your code that you should consider fixing in order to get the results close to the one as shown by your stated DWG viewer.

  • If you are not sure what layer represents what part of the drawing, you shouldn’t be setting the CadRasterizationOptions.Layer property as doing so may result in unexpected outcome.
  • CadRasterizationOptions.LayoutName property is case sensitive so make sure you are referring to the correct layout name.

Here are the modified CadRasterizationOptions settings that I have used on my end to render the attached PNG and PDF files.

C#

rasterizationOptions.BackgroundColor = Aspose.Imaging.Color.Black;
rasterizationOptions.DrawColor = Aspose.Imaging.Color.White;
rasterizationOptions.DrawType = Aspose.Imaging.FileFormats.Cad.CadDrawTypeMode.UseDrawColor;
rasterizationOptions.CenterDrawing = true;
rasterizationOptions.LayoutName = “Layout1”;

Regarding other part of your inquiry, I am afraid, resize operation is not available for CAD entities. If you can explain the necessity of the said feature, we may consider adding it to the road map of Aspose.Imaging APIs. However, if your requirement is to resize the converted images then there are plenty of methods available for the Image class such as Resize, ResizeWidthProportionally & ResizeHeightProportionally that you can use to accomplish your goals.

Let me see if we got it: in a generally working application we can’t know what kind of cad files we manage, so we don’t use the CadRasterizationOptions.Layer property and use ever rasterizationOptions.LayoutName = "Layout1"

Is it a right approach?
We need to represent all files our customer upload, we need a general solution, so LayoutName will be “Layout1” for every file or there is some method to estabilish correct name when opening original file with Aspose? Same question about vaious layers cad file could have: we need to represent ever all file’s layers, so don’t specify any layer will draw every layers?
In this approach is there a way to know background of the original cad object, so to apply it accordingly?
Is there some way to save in one image every possible layers we found in Layouts original document?

Thank you for clear our doubts

our need to resize cad object is the same need we for all other image types we treat with Aspose: in case images have some big dimension we resize for web use and we obtain smaller object to convert in images and pdf
Cad class is a part of aspose.imaging classes so we think to use the same Resize method we are using for other images

We are trying to export dwg sample files found in this site:
AutoCAD Sample Files

Aspose seems to can’t load Autocad 2010 sample files: it thrown in exeption “object out of range”
and Autocad 2011 sample files seems to be pretty empty: we can see three layouts (model, layout1, layout2) and print separately but they don’t represent the entire file(s) we can see with a dwg viewer

What is the problem with these files and how we can write a code with aspose can render the majority of dwg files completely?




Hi Valerio,

In order to address your concerns properly, here is brief description of the Layers & Layouts in perspective of CAD drawings. Consider CAD layers as transparency sheets, laying over one another like the layers in Photoshop application (if you have worked with it). Each layer could have a partial drawing (an object or several objects) and combination of all layers completes the drawing. On the other hand, Layouts are individual drawings that are complete and independent.

Boole Server:
Let me see if we got it: in a generally working application we can't know what kind of cad files we manage, so we don't use the CadRasterizationOptions.Layer property and use ever rasterizationOptions.LayoutName = "Layout1"

Is it a right approach?

This is the correct approach for CadRasterizationOptions.Layer property because if you do not set this property, the Aspose.Imaging API will render all layers by default. However, if you set this property, you have to be sure that the layers with specified names exist otherwise an empty or incomplete page will be rendered.

Like layers, there could be several layouts in a particular CAD file. If you do not specify the CadRasterizationOptions.LayoutName property, the Aspose.Imaging API will render the Model layout as its default behavior. In case of office.dwg sample, the Layout1 happens to have the complete drawing as it is in the Model layout with addition of textual contents. Therefore when you set the CadRasterizationOptions.LayoutName property to Layout1, you get the results close to the one as shown in the DWG viewer with Layout1 tab selected.

Boole Server:
We need to represent all files our customer upload, we need a general solution, so LayoutName will be "Layout1" for every file or there is some method to estabilish correct name when opening original file with Aspose?

As discussed above, there could be several layouts in a particular drawing and their names could be any. You can get all layouts in a drawing using the following instruction and customize your code to render all layouts one by one to individual PDF files or images.

C#
CadLayoutDictionary layouts = cadImage.Layouts;

Boole Server:
Same question about vaious layers cad file could have: we need to represent ever all file's layers, so don't specify any layer will draw every layers?

It is best to leave the CadRasterizationOptions.Layer untouched. This way you will be able to render all the layers in one resultant PDF or image. If you wish to get all the layers in a drawing, please use the following piece of code.

C#
CadLayersDictionary layers = cadImage.Layers;

Boole Server:
In this approach is there a way to know background of the original cad object, so to apply it accordingly?

As per my understanding, CAD files do not have background color therefore this information isn't stored in CAD files. It is the viewer settings that you can change in the viewer's preferences. If you wish to render the CAD objects in their original color, please set the CadRasterizationOptions.DrawType property to CadDrawTypeMode.UseObjectColor. Doing so will render all objects in their original colors by overriding the CadRasterizationOptions.DrawColor setting.

Boole Server:
Is there some way to save in one image every possible layers we found in Layouts original document?

Yes this is possible, by not setting the CadRasterizationOptions.Layer property. However, it is not possible to render all layouts on a single image or a PDF file at the moment. We are currently analyzing the feasibility of rendering the selected or all layouts as separate pages of a PDF file. When we will make some progress with this feature, we will update you.

Boole Server:
our need to resize cad object is the same need we for all other image types we treat with Aspose: in case images have some big dimension we resize for web use and we obtain smaller object to convert in images and pdf
Cad class is a part of aspose.imaging classes so we think to use the same Resize method we are using for other images

You are seeing CadImage.Resize method because this method has been implemented for the base class Image that corresponds to all image objects. We haven't yet provided the implementation specifically for CadImage class because it is complex feature, and we may take some time to provide it.

I have tried to address all your concerns. In case I have missed anything or you have further questions for us, please feel free to write back.
Boole Server:
We are trying to export dwg sample files found in this site:
http://knowledge.autodesk.com/support/autocad/downloads/caas/downloads/content/autocad-sample-files.html

Aspose seems to can't load Autocad 2010 sample files: it thrown in exeption "object out of range"
and Autocad 2011 sample files seems to be pretty empty: we can see three layouts (model, layout1, layout2) and print separately but they don't represent the entire file(s) we can see with a dwg viewer

What is the problem with these files and how we can write a code with aspose can render the majority of dwg files completely?

Hi Valerio,

Thank you for sharing the link. The samples available at the provided link have DWG 2014 & 2010 format, whereas, the current implementation of Aspose.Imaging API supports loading & converting AutoCAD 2004 DWG (version 16.0 Release 18) format only. We are currently working to provide support for other more recent data formats as well. Top on our priority is supporting the DWG 2010 data format, which we hope to publish in December 2014.

On another note, we understand that all the questions posted in this thread are related to DWG file format and their conversion. However, it is suggested that you should create a new thread (in a relevant forum) for every distinct inquiry/problem. This will help us keep track of all your requests in an appropriate manner.

Thank you for your understanding and cooperation.

Hi, basically our request is to have a conversion from DWG to images (png) stream, having in one resulting image all the layers and layouts of original cad file
I think it can work as photoshop file’s layers: now when you convert a psd multi-layer in png you obtain all layers in one png file.
So we hope to do the same with DWG files, 2004 to 2014 format possibly.
For now there is too much limitations in dwg conversion: we risk to have many reports of bad issue by our customers, so we hide conversion for cad files.

Hi Valerio,


You can render all layers of a CAD drawing to a single PDF page or raster image using the current implementation of Aspose.Imaging API so the functionally is already present. Regarding the layouts, we are currently investigating the possibility of rendering all layouts or selected layouts (more than one) to PDF & raster image formats. We have now attached the appropriate ticket (IMAGING-34372) from our database to this thread so that we can keep you posted with updates in this regard.

Moreover, with the next release of Aspose.Imaging for .NET 2.7.0, we are planning to provide the support for DWG 2010 as well as 2005 data formats. If everything goes as planned, the said release will be available for public use in the mid of November 2014.

The issues you have found earlier (filed as IMAGING-34372;IMAGING-34285) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

20 posts were split to a new topic: Background Image layer and Alpha Channel creation for PSD (C#)

Hi,
when we psd image first open it, the Layer that is selected/highlighted is the one called “Top layer”. Is it possible to select/highlight “particular layer” instead?

@veerakarthik,

I have observed that you have made similar inquiry in another forum thread as well. I have shared my feedback for your kind reference over following thread link.