Saving a chart and diagram as images.

Hi, 

I'm looking to create a PDF using Syncfusion PDF that takes a number of Syncfusion Charts and a Syncfusion Diagram as images. Is it possible to save charts and diagrams as images?

Thank you! 



19 Replies

DD Devakumar Dhanapoosanam Syncfusion Team February 2, 2022 01:20 PM UTC

Hi Raymond Dillon, 
 
Chart Query: Saving chart as image 
 
We can save the multiple charts as images in pdf using chart stream and we have prepared a sample based on your requirement.  
 
 
Please refer the below link for more details 
 
Diagram Query: Saving diagram as images 
 
Please find the download link for save the SfDiagram into image sample from below,  
 
 
Kindly try the above sample in your end and let us know if you need any further assistance with this. 
 
Regards, 
Devakumar D 



RD Raymond Dillon February 2, 2022 06:06 PM UTC

Hi - with regards to the diagram sample, how would I output the diagram for saving into a PDF (like was done for the charts?).

The chart sample worked perfect - thank you!



YP Yuvaraj Palanisamy Syncfusion Team February 3, 2022 12:33 PM UTC

Hi Raymond 
  
Currently we do not have support to “Save Diagram as PDF format”. We do not have any immediate plans to implement this feature. We will implement the requested feature in any our upcoming release and let you know when this feature is implemented.   
  
Regards, 
Yuvaraj 



RD Raymond Dillon February 3, 2022 01:53 PM UTC

Hi - Apologies, I should have been clearer. As in a similar fashion to using a chart in a PDF (via saving as a stream) - is this possible to do the same with a diagram, or utilise the diagram.SaveAsImagge() method to save the diagram and place the resulting image i



GR Gayathri Ramalingam Syncfusion Team February 4, 2022 11:23 AM UTC

Hi Raymond, 
 
You can save the SfDiagram as image in given Stream using ‘SaveAsImage’ method and kindly use the below code snippet, 
 
Stream stream = new MemoryStream();             
diagram.SaveAsImage(stream, ImageFormat.Png); 
 
 
We have prepared sample for the same and it can be downloaded from below link, 
 
As we mentioned earlier, currently we do not have direct support to “Save Diagram as PDF format”. 
 
Could you please try the above suggested solution and let us know whether it meets your requirement or not?   
 
With Regards, 
Gayathri R 
 
 



RD Raymond Dillon February 9, 2022 11:06 AM UTC

Hi,

When I apply this to my project I get the error "Object not set to an instance of an object". I can see my diagram has 2 items and 1 connector as expected, so the diagram is not null - however the stream is returning a value of 0.

Is there any particular property of the diagram that needs set in order to allow the export to an image to take place?


Thank you!



GR Gayathri Ramalingam Syncfusion Team February 10, 2022 12:56 PM UTC

Hi Raymond, 
Based on your previous update, we suspect you have tried to get the ‘SaveAsImage’ stream immediately after adding the node into Diagram control. Since we are facing the reported issue “Object not set to an instance of an object" exception only in that particular scenario, could you please confirm us whether you have faced this issue in the same scenario? This issue occur due to that the diagram is not loaded properly while getting the stream. To overcome this issue, we have suggested to get the stream once diagram loaded using ‘Loaded’ event. 
 
Please find the below code snippet, 
public MainPage() 
{ 
     InitializeComponent(); 
 
     Node node = new Node { Width = 200, Height = 200, OffsetX = 100, OffsetY = 100 }; 
     Node node1 = new Node { Width = 200, Height = 200, OffsetX = 350, OffsetY =100 }; 
     diagram.AddNode(node); 
     diagram.AddNode(node1); 
     diagram.Loaded += Diagram_Loaded; 
} 
 
private void Diagram_Loaded(object sender) 
{ 
     Stream stream = new MemoryStream(); 
     diagram.SaveAsImage(stream, ImageFormat.Png); 
} 
 
We have prepared sample for the same and it can be downloaded from below link, 
 
Could you please try the above suggested solution and let us know whether it meets your requirement or not? 
 
With Regards, 
Gayathri R 



RD Raymond Dillon February 10, 2022 01:53 PM UTC

Hi,


My app is reaching the diagram.Loaded += Diagram_Loaded; call but the method itself is never called.  Any ideas why?


Essentialy what I'm loooking to do is take the stream and create a PDF Image for use in a PDF


e.g 


       Stream stream = new MemoryStream();

       diagram.SaveAsImage(stream, ImageFormat.Png);

      PdfBitmap diagramimage = new PdfBitmap(stream);


Is this possible?







GR Gayathri Ramalingam Syncfusion Team February 11, 2022 11:25 AM UTC

Hi Raymond, 
We were able to reproduce the issues with “Diagram loaded event is not triggered in UWP” and “Diagram loaded event triggered twice in iOS” but its working fine in Android. We will analyze and provide you details on 15th February 2022. 
 
Could you please confirm us whether you have facing issue in UWP? 
 
With Regards, 
Gayathri R  



GR Gayathri Ramalingam Syncfusion Team February 15, 2022 04:45 PM UTC

Hi Raymond, 
We have confirmed that the issues “Diagram loaded event is not triggered in UWP” and “Diagram loaded event triggered twice in iOS” are defect and logged defect report for the issues. The patch for this issue will be delivered on 8th March 2022.   
 
 
 
With Regards, 
Gayathri R 



RD Raymond Dillon February 15, 2022 09:49 PM UTC

Hi, 

With the following code on Android the loaded event isn't triggering



            //Initializes the DataSourceSettings

            diagram.DataSourceSettings = new DataSourceSettings() { DataSource = Data, Id = "ID", ParentId = parentid };

            //Initializes the Layout

            DirectedTreeLayout treeLayout = new DirectedTreeLayout() { HorizontalSpacing = 80, VerticalSpacing = 50, TreeOrientation = TreeOrientation.TopToBottom };

            diagram.LayoutManager = new LayoutManager() { Layout = treeLayout };

            diagram.EnableZoomAndPan = true;

            diagram.MinimumZoomFactor = 100;

            diagram.EnableTextEditing = false;



            diagram.BeginNodeRender += Diagram_BeginNodeRender;






            diagram.Loaded += Diagram_Loaded1;



I reach the "diagram.Loaded += Diagram_Loaded1" event via a breakpoint but the event itself doesn't trigger. 




GR Gayathri Ramalingam Syncfusion Team February 16, 2022 03:33 PM UTC

Hi Raymond 
 
We tried to reproduce the issue “Diagram loaded event is not triggered in Android with v19.4.0.52, but it is working fine. 
  
We have created a simple sample based on the provided information and the sample can be downloaded from the below link, 
 
  
We created a video for illustrating the same and it can be downloaded from the below links, 
 
  
Kindly provide the following details to investigate further on this issue.   
1.      Modify / Simple sample with which the issue could be reproduced. 
2.      Replication procedure to reproduce the issue or screen shot illustrating the issue. 
3.      Android device specification with the OS version. 
4.      SfDiagram version 
5.      Xamarin Forms version 
The above details will be more helpful for us to reproduce the issue in our side and assist you with the better solution at the earliest.  
 
Note: As we mentioned earlier, we will provide patch for the issues “Diagram loaded event is not triggered in UWP” and “Diagram loaded event triggered twice in iOS” on 08th March 2022. 
 
 
With Regards, 
Gayathri R 
 



RD Raymond Dillon February 23, 2022 09:00 PM UTC

Hi, it's happening on any Android device.

SFDiagram Version is 18.3.0.35 & Xamarin Forms 4.8

I added a try catch and I'm getting the exception "

{System.NullReferenceException: Object reference not set to an instance of an object.

  at Syncfusion.SfDiagram.XForms.Android.DiagramDependencyService.SaveAsImage (System.Object nativeObject, System.IO.Stream stream, Syncfusion.SfDiagram.XForms.ImageFormat imageformat, System.Int32 left, System.Int32 top, System.Int32 right, System.Int32 bottom) [0x00000] in <03ac3d78000e468ba66537df0ac0060b>:0"



GR Gayathri Ramalingam Syncfusion Team February 24, 2022 01:19 PM UTC

Hi Raymond,   
We tried to reproduce the issue “System.NullReferenceException occur when use ‘SaveAsImage’ in Android with v18.3.0.35 and Xamarin Forms v4.8”, but it is working fine.  
     
We have created a simple sample based on the provided information and the sample can be downloaded from the below link,  
   
We created a video for illustrating the same and it can be downloaded from the below links,  

We have tried to reproduce the issue from Android version 7.0 to latest Android version, but it’s working fine as we expected. So, we request you to the exact Android version in which issue could be reproduced in your end. And also we would like to setup a web meeting to directly reproduce the issue in your machine with your sample and provide the solution. Please let us know your availability. We will make every effort to have this scheduled on a date and time of your convenience.   

With Regards, 
Gayathri R 





RD Raymond Dillon March 1, 2022 05:20 PM UTC

Hi, 

I've the diagram saving now to the PDF, however I have a custom template applied to the diagram (image & text below). This renders fine in the app, but when I save it to the PDF the image disappears.

Any advice would be appreciated! Thank you!



GR Gayathri Ramalingam Syncfusion Team March 2, 2022 04:10 PM UTC

Hi Raymond 
 
We were able to reproduce the reported issue in our side and we suspect this to be a defect. We have forwarded this issue to our development team for further analysis and we will update further details by 04th March 2022. 
 
With Regards, 
Gayathri R 



GR Gayathri Ramalingam Syncfusion Team March 4, 2022 02:53 PM UTC

Hi Raymond, 
 
On further analyzation we found that currently we do not have support for “Layout with node template (i.e. Image Template) while saving Diagram as image”. We don't have immediate plan for this feature implementation. We usually have an interval of at least three months between the releases. At the planning stage for every release cycle, we review all open features once again and finalize features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented. We appreciate your patience.  The status of implementation can be tracked through our Features Management System:   
 
 
 
With Regards, 
Gayathri R 



RD Raymond Dillon March 7, 2022 03:28 PM UTC

Hi, 

When is the next release cycle due?

At the minute when I have a node template in place (with an image) and save, the diagram saves but with a large gap where the image should be (I understand this hasn't been implemented yet). However, is there a way to remove this gap / space on diagram save as a workaround?


Thank you!



GR Gayathri Ramalingam Syncfusion Team March 8, 2022 02:34 PM UTC

Hi Raymond 
 
The next release for 2022 Volume 1 Main release is rolled out in the end of March 2022. As we mentioned earlier, we don't have immediate plan for the feature “Layout with node template (i.e. Image Template) while saving Diagram as image. We usually have an interval of at least three months between the releases. At the planning stage for every release cycle, we review all open features once again and finalize features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented. We appreciate your patience. 
 
We can achieve your requirement by workaround to add the label first before adding the image in the custom template of node. We have modified the sample for the same and it can be downloaded from below, 
 
Please find the output screen shot from below, 
 
 
Please find the saved PDF document screen shot from below, 
 
 
Could you please try the above suggested solution and let us know whether it meets your requirement or not?  
 
With Regards, 
Gayathri R 


Loader.
Up arrow icon