locked
export a page in PDF format RRS feed

  • Question

  • User-1338060929 posted

    Hi

     

    How to export asp.net page to pdf format in vb.net

     

    Saturday, June 15, 2013 2:56 AM

Answers

  • User-46749029 posted

    Wow! It seems that the need regarding converting aspx page to other file formats is hot now.  I am testing with Spire.Doc for .NET component the conversion at present.  I have done it. Share my code with other guys here. Good luck! Laughing

    Dim document As New Document()
    Using buffer As New MemoryStream()
    	Using writer As TextWriter = New StreamWriter(buffer, Encoding.UTF8)
    		Using htmlWriter As New HtmlTextWriter(writer)
    			Me.RenderControl(htmlWriter)
    			htmlWriter.Flush()
    			writer.Flush()
    			buffer.Position = 0
    
    			Using reader As StreamReader = New System.IO.StreamReader(buffer, Encoding.UTF8)
    		        Dim baseHref As String = Request.Url.AbsoluteUri
    			document.LoadHTML(reader, baseHref, Spire.Doc.Documents.XHTMLValidationType.None)
    			document.SaveToFile("Sample.pdf", FileFormat.PDF, Response,HttpContentType.Attachment)
    			End Using
    		End Using
    	End Using
    End Using

    When you have a need to convert aspx page to Word(doc, docx), you could refer some solutions from other post as below.

    http://forums.asp.net/p/1776279/5428150.aspx/1?Re+convert+aspx+page+to+word+document

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 20, 2013 4:05 AM

All replies