David C
asked on
Save generated output to folder instead of displaying in browser
Hi Experts
My code below takes the current html of a page and creates a PDF. I am struggling to find a way to save the PDF into a folder instead of showing it in the browser
My code below takes the current html of a page and creates a PDF. I am struggling to find a way to save the PDF into a folder instead of showing it in the browser
Dim htmlToPdf = New HtmlToPdfConverter()
Dim pdfData = htmlToPdf.GeneratePdf(html)
Response.ContentType = "application/pdf"
Response.OutputStream.Write(pdfData, 0, pdfData.Length)
Response.[End]()
Save it in a folder where: on the server or on the client?
ASKER
Apologies on the server
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you it tries to do it then says
I tried it with
and without but get the same error
I have placed the line as follows
System.Web.HttpException: A page can have only one server-side Form tag.
I tried it with
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
End Sub
and without but get the same error
I have placed the line as follows
System.IO.File.WriteAllBytes(Server.MapPath("~\PDF\test.pdf"), pdfData)
That sounds like an issue in your markup file, not your code-behind file. Do you have two <form> tags in your HTML somewhere?
ASKER
No I have just 1
Default.aspx
Default.aspx
ASKER
I have noticed that it creates the file which is brilliant news but its just the error that I need to get rid off.
ASKER
I have also noticed that if I remove the only form tag and place the code in the form load, everything works fine however this renders the form useless as none of the controls work without the form tag.
This is how I am generating the html
Maybe if I change that it'll work? Is there any other way to get the HTML of the current page?
This is how I am generating the html
'Generate from current page
Dim renderedOutput As StringBuilder
Dim strWriter As StringWriter
Dim tWriter As HtmlTextWriter
Dim html As String
'create a HtmlTextWriter to use for rendering the page
renderedOutput = New StringBuilder
strWriter = New StringWriter(renderedOutput)
tWriter = New HtmlTextWriter(strWriter)
'render the page output
Page.RenderControl(tWriter)
html = renderedOutput.ToString
Maybe if I change that it'll work? Is there any other way to get the HTML of the current page?
ASKER
Thanks