How to create an PDF file from aspx page

I want to create PDF file from my .aspx page which contains 6 chart, called from 6 diffrent .aspx locations on page to be converted in PDF.

All these cart are genrated runtime and are not saved on any physical location as we are using MemoryStream (used Aspose Chart).

we are using ASP.Net with VB.Net for coding. Kindly help us ASAP.


This message was posted using Page2Forum from Aspose.Pdf for .NET

Hello Manish,

Thanks for using our products.

As far as I can understand from your post, you are generating Charts using Aspose.Cells (as Aspose.Charts has been merged into Aspose.Cells) and the resultant charts are being displayed over .aspx page. Now the requirement is to convert the contents of this .aspx page into PDF format.

Before I have shared some information on how to accomplish your requirements, please confirm that I have properly understood the query.

Hi Codewarior,

I am putting below the code for genrating the chart in aspx page name opt_1 and also code through which we are calling these cart. this will give clear picture what acctualy we are doing & how we are doing it.

Imports Aspose.Chart
Imports System.IO
Imports System.Drawing.Imaging

Partial Class opt1_a
Inherits System.Web.UI.Page

Private Sub Createchart()
Dim c As Chart = New Chart()
Dim s As Series = New Series()

c.Height = 350
c.Width = 450
s.ChartType = ChartType.Pie
s.DefaultDataPoint.LabelFormat = "P0"
s.DefaultDataPoint.IsLabelVisible = True
s.DefaultDataPoint.LabelValue = DataLabelValueType.YValue
s.DataPoints.Add(New DataPoint("Equity", 0, Convert.ToDouble(Session("Equity1")) / 100))
s.DataPoints.Add(New DataPoint("FixedIncome", 1, Convert.ToDouble(Session("FixedIncome1")) / 100))
s.DataPoints(0).Color = Drawing.Color.FromArgb(121, 195, 27)
s.DataPoints(1).Color = Drawing.Color.FromArgb(255, 204, 0)
c.SeriesCollection.Add(s)

'Save the chart image into a memory stream.
Dim ms As MemoryStream = New MemoryStream()
c.Save(ms, ImageFormat.Png)

'Save the chart image from the memory stream to the response.
Response.Clear()
Response.ContentType = "image/png"
Response.OutputStream.Write(ms.ToArray(), 0, ms.Length)

End Sub

Code for calling aspx pages in other page to get all six chart on a page. (Page to be converted into PDF as a part)

Partial Class displaychart
Inherits System.Web.UI.Page

Private Sub DisplayChart()

'image control calling chart
ChartImage.ImageUrl = "opt1_a.aspx"
ChartImage_.ImageUrl = "opt1_b.aspx"
ChartImage1.ImageUrl = "opt2_a.aspx"
ChartImage1_.ImageUrl = "opt2_b.aspx"
ChartImage2.ImageUrl = "opt3_a.aspx"
ChartImage2_.ImageUrl = "opt3_b.aspx"

End Sub

still wating for reply on above. spcl. if i could get some code help.

Hello Manish,

Sorry for replying you late.

As far as I can understand from your code, you are generating charts on runtime and then saving the chart into MemoryStream object in PNG format.

'Save the chart image into a memory stream.
Dim ms As MemoryStream = New MemoryStream()
c.Save(ms, ImageFormat.Png)

As per your requirements, once the charts is converted into PNG image format and is inside MemoryStream object, you can use Aspose.Pdf for .NET to convert this image to PDF format. For more related information, please visit How to convert MemoryStream Image to PDF.

In case you still face any problem or you have any further query, please feel free to contact. We apologize for the delay and inconvenience.