Solved

Save generated output to folder instead of displaying in browser

Posted on 2014-02-08
9
284 Views
Last Modified: 2014-02-28
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

Dim htmlToPdf = New HtmlToPdfConverter()
        Dim pdfData = htmlToPdf.GeneratePdf(html)
        Response.ContentType = "application/pdf"
        Response.OutputStream.Write(pdfData, 0, pdfData.Length)
        Response.[End]()

Open in new window

0
Comment
Question by:takwirirar
  • 6
  • 3
9 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Save it in a folder where:  on the server or on the client?
0
 
LVL 1

Author Comment

by:takwirirar
Comment Utility
Apologies on the server
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
Replace lines 3 - 5 with:

System.IO.File.WriteAllBytes("path\to\folder", pdfData)  ' First parameter may need to change
                                                         '  to Server.MapPath("path\to\folder")
                                                         '  depending on which folder you are
                                                         '  referencing

Open in new window

0
 
LVL 1

Author Comment

by:takwirirar
Comment Utility
Thank you it tries to do it then says

 System.Web.HttpException: A page can have only one server-side Form tag.

Open in new window


I tried it with

 Public Overrides Sub VerifyRenderingInServerForm(control As Control)
    End Sub

Open in new window


and without but get the same error

I have placed the line as follows

System.IO.File.WriteAllBytes(Server.MapPath("~\PDF\test.pdf"), pdfData) 

Open in new window

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
That sounds like an issue in your markup file, not your code-behind file. Do you have two <form> tags in your HTML somewhere?
0
 
LVL 1

Author Comment

by:takwirirar
Comment Utility
No I have just 1
Default.aspx
0
 
LVL 1

Author Comment

by:takwirirar
Comment Utility
I have noticed that it creates the file which is brilliant news but its just the error that I need to get rid off.
0
 
LVL 1

Author Comment

by:takwirirar
Comment Utility
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

  '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

Open in new window


Maybe if I change that it'll work? Is there any other way to get the HTML of the current page?
0
 
LVL 1

Author Closing Comment

by:takwirirar
Comment Utility
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now