How to Insert 2D Graph in PDF?

How can I generate a 2D graph in PDF? We have a MVC razor view that gets converted to PDF using Aspose.PDF but we need to generate a pie chart from ASP.NET cshtml to pdf. Please advise, thanks!

I’m not sure if this is the right path but I’m not seeing any inclination as to where the dynamic data will be integrated.

Hi Jeff,

Thanks for your inquiry. We have already noticed the Pie Chart related issue in HTML to PDF conversion in your other post and logged PDFNEWNET-38526 in our issue tracking system for further investigation and resolution.

Moreover, please note we have another API Aspose.Cells. It [supports almost all types of charts](http://www.aspose.com/docs/display/cellsnet/Introduction+to+Charts+and+Chart+Types) except 3d bubble chart and surface chart. You may generate pie charts using Aspose.cell, convert those charts to Images and then add those images to PDF document using Aspose.Pdf. Please see the following documentation links for reference. Hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,

Make sense although, is it possible to save the image within a byte as part of our Model then pass it in as part of MemoryStream which is the object that will be converted to PDF?




We currently have our cshtml with static images converted to PDF but I don’t think we can SAVE the image to the disk, it preferably in memory.



Have you encountered this question Tilal? Thanks.

Hi Jeff,

As per my understanding, your requirement is to save graph images to a Stream instance and then convert them to PDF format. If so is the case, I am please to share that Aspose.Pdf for .NET supports the feature to load images from a Stream instance and render the output as PDF format.

In case I have not properly understood your requirement, please share some further details.

C#

Document doc = new Document();
doc.Pages.Add();
Aspose.Pdf.Image image = new Aspose.Pdf.Image();
image.ImageStream = new FileStream("inputfile.jpeg", FileMode.Open);
doc.Pages[1].Paragraphs.Add(image);
doc.Save("ImageFromStream.pdf");

Hi,

From the line 4 where
image.ImageStream = new FileStream(“inputfile.jpeg”, FileMode.Open);

—> Let say the this will be the image that Tilal walked me through - which is the Excel JPG Pie Chart.

The ultimate goal is not to write the “inputfile.jpg” to the disk in the web server but append it to .pdf if can be managed passing it as part of Model as a byte then to the memorystream?
Jeff Par:
Hi,
From the line 4 where
image.ImageStream = new FileStream("inputfile.jpeg", FileMode.Open);

---> Let say the this will be the image that Tilal walked me through - which is the Excel JPG Pie Chart.

The ultimate goal is not to write the "inputfile.jpg" to the disk in the web server but append it to .pdf if can be managed passing it as part of Model as a byte then to the memorystream?
Hi Jeff,

As per my understanding, you need to save the image of Pie Chart generated using Aspose.Cells to Stream instance and then load the image contents into ImageStream property. If so is the case, then this requirement can be accomplished.