Hi ,
I am trying to render a view in my backend and save its html source to a pdf file. For that purpose, I have a pdf function
Function PDF()
Dim opportunities As IEnumerable(Of OpportunityViewModels)
opportunities = TempData(“snapshot”)
If (IsNothing(opportunities)) Then
Return “No Opportunities”
End If
Dim op = opportunities.ToList
Dim s = RenderView(Me, “_LoadTable_Opportunity2”, op)
Dim pdf1 As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
Dim sec1 As Aspose.Pdf.Generator.Section = pdf1.Sections.Add()
Dim text1 As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(s.ToString)
sec1.Paragraphs.Add(text1)
text1.IsHtmlTagSupported = True
pdf1.Save(“C:Somepath\Test.pdf”)
Return True
End Function
and here is the render view function
Function RenderView(controller As OpportunityController, viewName As String, model As Object) As String
ViewData.Model = model
Using sw As New StringWriter()
Dim viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName)
Dim viewContext = New ViewContext(controller.ControllerContext, viewResult.View, ViewData, TempData, sw)
viewResult.View.Render(viewContext, sw)
viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View)
Return sw.GetStringBuilder().ToString()
End Using
End Function
The following code works, however, for some reasons its doesn’t load the proper CSS with the view. In the view page, I called all the necessary CSS files but Aspose doesn’t seem to take them into account.
Please Help,
Thank you