Save aspx output to a file on the server

W

Will Rickards

In my web application there is an interactive report. Then there need
to be a printable version a pdf. So I found this java tool csstoxslfo
and the java fop tool from apache that will take my xhtml and css and
convert it to pdf.

Problem 1)
I designed the aspx page to produce the xhtml as output. So how do I
save that rendered page to a file on the server? I think it involves
overriding the Render method. I wrote some code which appears below
that I don't know if it will work. Anybody done this before and have
code examples?

Problem 2)
Assuming I can render to a file, I now have to invoke java. I tested
from the command line and this works fine. So now I have to do it from
the asp.net page, wait for it to finish, and then render the resulting
pdf file to the user. I assume all this code will be in the render
override?
Anybody called java before like this?
I'm thinking using a process object and something like the following
for the command. I've been researching and just doing java -jar as the
command doesn't work? Again anybody done this before and have code
examples?
start command /c java -jar thejar.jar options

Will Rickards


Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)

' create stream to store output
Dim objRendered As System.web.UI.HtmlTextWriter
Dim objFileWriter As System.IO.StreamWriter

' get file writer
objFileWriter = System.IO.File.CreateText(Server.MapPath(".") &
"\\PDF\\" & CStr(m_intReportNumber) & ".xhtml")

objRendered = New System.Web.UI.HtmlTextWriter(objFileWriter)

MyBase.Render(objRendered)

objFileWriter.Flush()
objFileWriter.Close()
objRendered.Flush()
objRendered.Close()

writer.Write("Done")

End Sub
 
K

Ken Cox [Microsoft MVP]

Hi Will,

I think this will help with Problem #1.

Ken
Microsoft MVP [ASP.NET]

' Render() sends server control content to a provided HtmlTextWriter
object
' We overrides the Render method
' Output is the HtmlTextWriter object.
Protected Overrides Sub Render _
(ByVal Output As HtmlTextWriter)
' Create a StringBuilder to hold the HTML
Dim sb As New StringBuilder
' Create an HtmlTextWriter
Dim tw As New HtmlTextWriter(New System.IO.StringWriter(sb))
MyBase.Render(tw)
' The following will fail if the ASPNET or impersonated account
' doesn't have write privileges in the root
Dim txtw As System.IO.StreamWriter = _
System.IO.File.CreateText("c:\htmltxt.txt")
' Write the page contents to the file just created
txtw.Write(sb.ToString())
txtw.Flush()
txtw.Close()
' Write the text to the HTML page
Output.Write(sb.ToString())
End Sub
 
W

Will Rickards

Thanks, that worked. Unfotunately, once I got the output the java tool
didn't like it as input so I have to track down those bugs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top