Rendering of Multiple CAD Layouts

for IMAGING-34372, we tried last 2.7.0 version but still we cannot see all dwg layouts in exported images or pdf (see examples in attachment, original dwg viewed with a dwg viewer, and aspose images or pdf export)

so, what’s wrong ?


Hi Valerio,


First of all, please note that we have split the existing thread to create a new one on your behalf because the existing thread was getting too long to properly keep track of your requests.

With the release of Aspose.Imaging for .NET 2.7.0, the API has exposed the CadRasterizationOptions.Layouts property of type string array so you may specify more than one layouts at a time for possible conversion to image and PDF formats. While specifying multiple layouts for the CadRasterizationOptions.Layouts property, the resultant TIFF image & PDF would have multiple pages, GIF image would have multiple frames and PSD format would have multiple layers, where each page/frame/layer represents an individual AutoCAD layout. In case any other image format such as PNG, BMP, JPEG is selected to store the result then the API will render only the default layout; that is “Model”.

Here is the complete code for your reference.

C#

using (CadImage image = (CadImage)Image.Load(sourceFilePath))
{
CadLayoutDictionary layouts = image.Layouts;
string[] layoutNames = new string[layouts.Count];
int i = 0;
foreach(CadLayout layout in layouts.Values)
{
layoutNames[i++] = layout.LayoutName;
}

//Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
//Set page width & height
rasterizationOptions.PageWidth = 1200;
rasterizationOptions.PageHeight = 1200;

//Specify a list of layout names
rasterizationOptions.Layouts = layoutNames;

//Create an instance of TiffOptions for the resultant image
ImageOptionsBase options = new TiffOptions();

//Set rasterization options
options.VectorRasterizationOptions = rasterizationOptions;

//Save resultant image
image.Save(myDir + “output.tiff”, options);
}

We have tested both of your provided DWG drawings to test this case. The file 2.dwg renders fine to TIFF format using the above code. However, the other DWG file 1.dwg renders in blank frames of the TIFF file. We are currently looking into it further to guide to in this regard.

Hi again,


As discussed earlier, we are not able to properly render the DWG file 1.dwg to PDF and TIFF image formats therefore we have logged this incident in our bug tracking system under the ticket IMAGING-34576 for further investigation. Please spare us little time to properly analyze the problem cause and to provide the fix at earliest possible. In the meanwhile, we will keep you posted with updates in this regard.

Ok, thank you for splitting threads.

So, omitting 1.dwg you are investingating and focusing on other 2.dwg, we see two problems.

we tried exporting as png (one layout on one png in a loop on layouts.count) and as PDF with this code:

Aspose.Imaging.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = ((Aspose.Imaging.Image)m_oDocument).Width;
rasterizationOptions.PageHeight = ((Aspose.Imaging.Image)m_oDocument).Height;
rasterizationOptions.BackgroundColor = Aspose.Imaging.Color.White;
rasterizationOptions.DrawColor = Aspose.Imaging.Color.Black;
rasterizationOptions.DrawType = Aspose.Imaging.FileFormats.Cad.CadDrawTypeMode.UseDrawColor;
rasterizationOptions.CenterDrawing = true;

Aspose.Imaging.FileFormats.Cad.CadLayoutDictionary layouts = ((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Layouts;
string[] layoutNames = new string[layouts.Count];
int i = 0;
foreach (Aspose.Imaging.FileFormats.Cad.CadObjects.CadLayout layout in layouts.Values)
{
layoutNames[i++] = layout.LayoutName;
}
//commented
// rasterizationOptions.Layouts = layoutNames;

Aspose.Imaging.ImageOptions.PdfOptions OptionsIP = new Aspose.Imaging.ImageOptions.PdfOptions();

Aspose.Imaging.ResolutionSetting oResIP = new Aspose.Imaging.ResolutionSetting(Convert.ToDouble(m_iResolution), Convert.ToDouble(m_iResolution));
OptionsIP.ResolutionSettings = oResIP;
OptionsIP.VectorRasterizationOptions = rasterizationOptions;
((Aspose.Imaging.Image)m_oDocument).Save(_oOutputStream, OptionsIP);


1
as you can see we comment the line rasterizationOptions.Layouts = layoutNames;
'cause there is some difference passing all the layouts or passing noone (see attachments), in one case we obtain a pdf with page 1 = layout 1 and page 2 = model, in the other case we obtain a pdf with page 1 = model and page 2 = blank page

2
in every cases we lack some items (text) we can see in dwg viewer (see in attachment, model and layout1)

thank you

Hi Valerio,


Thank you for writing back.

I am able to confirm the point 2) from your post, as the Layout1 is not rendering completely when the 2.dwg is rendered to the PDF format. It seems like most of the textual contents from the said layout are missing in the resultant PDF. We have logged this incident in our bug tracking system under the ticket IMAGING-34581 for further investigation. We will keep you posted with updates in this regard.

Regarding the point 1), I am afraid, the problem didn’t replicate on my side while using your provided code snippet against the sample 2.dwg. Please note, if CadRasterizationOptions.Layouts property isn’t initialized then the API will render all the layouts to PDF format and only the Model layout to image formats that could not have multiple frames/pages such as PNG format. If you check my attached resultant PDF files that were generated with & without setting the CadRasterizationOptions.Layouts property. You will notice that both PDF files have two pages with drawings on it. Please confirm the environment details so we may re-evaluate this scenario after simulating your environment settings. Moreover, please provide an executable sample application along with referenced assemblies as well as the input DWG file for further investigation.

we cannot say…maybe the difference is in the output on stream?

This is our complete code:
Aspose.Imaging.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.CadRasterizationOptions();
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;
}
}
//imposto i colori per evitare di usare quelli originali (potrei avere linee uguali allo sfondo)
rasterizationOptions.BackgroundColor = Aspose.Imaging.Color.White;
rasterizationOptions.DrawColor = Aspose.Imaging.Color.Black;
rasterizationOptions.DrawType = Aspose.Imaging.FileFormats.Cad.CadDrawTypeMode.UseDrawColor;
rasterizationOptions.CenterDrawing = true;

//nessun layer impostato -> li disegna tutti

// rasterizationOptions.Layers = new List { “layer1” };
// al momento non è possibile sapere in che layout si trovi il disegno intero (assume che sia nel Model)
//foreach (KeyValuePair<string, Aspose.Imaging.FileFormats.Cad.CadObjects.CadLayout> cl in ((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Layouts)
//{
// if (cl.Value.LayoutName.ToLower() != “model”)
// { rasterizationOptions.LayoutName = cl.Value.LayoutName; }
//}
Aspose.Imaging.FileFormats.Cad.CadLayoutDictionary layouts = ((Aspose.Imaging.FileFormats.Cad.CadImage)m_oDocument).Layouts;
string[] layoutNames = new string[layouts.Count];
int i = 0;
foreach (Aspose.Imaging.FileFormats.Cad.CadObjects.CadLayout layout in layouts.Values)
{
layoutNames[i++] = layout.LayoutName;
}
//non specifico nessun layout: li disegna tutti, uno per pagina
// rasterizationOptions.Layouts = layoutNames;

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



with comment on line // rasterizationOptions.Layouts = layoutNames;
it generates a pdf , while uncomment that line the pdf… complete
(in attachment original dwg and the two pdf)

Hi Valerio,


Thank you for the code snippet.

Your code helped me replicate the problem of blank PDF page. Problem seems to be related to the resultant page dimensions. Your code is setting the page width & height to 1024, and these settings cause the blank page. If I set these parameters to the CAD drawing size, the result is different. Moreover, the problem happens when CadRasterizationOptions.Layouts is initialized with all layouts in the drawing.

I have logged an investigative ticket under the Id IMAGING-34582 to probe further into this matter. Please spare us little time to isolate the problem cause. As soon as we get updates in this regard, we will post here for your kind reference.

ok thanks
we use this kind of resize in every cases of exporting images or pdf to obtain smaller files

Hi Valerio,


This is to inform you that among the three tickets attached to this thread, only one ticket (IMAGING-34576) is currently blocked because the sample 1.dwg contains 3D drawings. Aspose.Imaging APIs currently cannot handle 3D drawings/solids therefore the aforesaid ticket has been rescheduled for a later time. Other two tickets (IMAGING-34581 & IMAGING-34582) have been marked resolved, and the fix will be delivered with the upcoming release of Aspose.Imaging for .NET 2.8.0 during the next week.

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


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

hello, any news about 3d graphics?

Hi Valerio,

Please note that the issue under ticket ID IMAGING-34576 is still under process. We will update you once it is fixed via this thread.

Further, you can export 3D AutoCAD images to PDF. For details please visit the link Export 3D AutoCAD Images to PDF and our blog post Export PSD Layer to Raster Image and 3D AutoCAD Images to PDF with Aspose.Imaging for .NET 3.1.0.

concerning your suggestion: it is not our scenario.
Our customers upload some cad files (dwg, dxf…) BUT we cannot say if they are 2d or 3d.
So our use of aspose.imaging has to be intended as reading dwg file and convert it in image(s) and pdf file
So how can we set TypeOfEntities according to the content of file? is it possible to know if a cad file contains or not some 3d layout? is there a possibility to export/print all layouts to a pdf even if the file has 2D and 3D content?

Hi Valerio,

Thank you for your inquiry.

Please note that currently no such mechanism is available. The requirements have been forwarded to our product team for further analysis under ticket ID IMAGING-34576. We will update you about the progress via this thread.

any new about it?
thanks

Hi Valerio,

Thank you for writing us back.

This is to update you that our product team is making progress regarding drawing of 3D-entities but the work is still under progress. As soon as we get any updates in this regard, we will share the details with you via this forum post.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.