ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Convert Web Page to PDF and download as Zip file using C# in ASP.Net<p>Hi <a class="username" rel="KatieNgoc">KatieNgoc</a>,</p> <p>Refer below sample code.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <p><strong>CS.aspx</strong></p> <pre class="brush: html">&lt;div&gt; &lt;h50 style=&#34;float: left&#34;&gt;&lt;font color=&#34;black&#34; size=&#34;5&#34;&gt;&lt;b&gt;DASHBOARD&lt;/b&gt;&lt;/font&gt;&lt;/h50&gt; &lt;br /&gt; &lt;br /&gt; &lt;table id=&#34;Table1&#34; runat=&#34;server&#34; style=&#34;float: left&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;img src=&#34;Images/FeedBack.jpg&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;a href=&#34;LiveChat.aspx&#34;&gt; &lt;h51 style=&#34;float: left&#34;&gt;&lt;font color=&#34;green&#34; size=&#34;4&#34;&gt;&lt;b&gt;Live Chat&lt;/b&gt;&lt;/font&gt;&lt;/h51&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;img src=&#34;Images/icon2.jpg&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;a href=&#34;Disagree.aspx&#34;&gt; &lt;h51 style=&#34;float: left&#34;&gt;&lt;font color=&#34;blue&#34; size=&#34;4&#34;&gt;&lt;b&gt;Feed Back&lt;/b&gt;&lt;/font&gt;&lt;/h51&gt; &lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;img src=&#34;Images/logout.jpg&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;a href=&#34;Default.aspx&#34;&gt; &lt;h51 style=&#34;float: left&#34;&gt;&lt;font color=&#34;navy&#34; size=&#34;4&#34;&gt;&lt;b&gt;LogOut&lt;/b&gt;&lt;/font&gt;&lt;/h51&gt; &lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;center&gt; &lt;asp:Label ID=&#34;Label1&#34; runat=&#34;server&#34; Font-Bold=&#34;True&#34; ForeColor=&#34;Blue&#34; Font-Size=&#34;Medium&#34;&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;h1&gt; &lt;font color=&#34;black&#34;&gt;&lt;b&gt;FORMS&lt;/b&gt;&lt;/font&gt;&lt;/h1&gt; &lt;hr /&gt; &lt;br /&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;img src=&#34;/Images/icon.jpg&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;h5&gt; You have completed 75% the progress of the online employment application systems. &lt;/h5&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/center&gt; &lt;br /&gt; &lt;br /&gt; &lt;div class=&#34;container&#34;&gt; &lt;div class=&#34;progress&#34;&gt; &lt;div class=&#34;progress-bar progress-bar-striped progress-bar-animated&#34; style=&#34;width: 75%;&#34;&gt; 75%&lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;br /&gt; &lt;center&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;img src=&#34;/Images/icon.jpg&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;h4&gt; &lt;font color=&#34;white&#34;&gt;Note:&amp;nbsp; At the bottom of each form, it will be displayed your digital signature image came from your job application form.&lt;/font&gt;&lt;/h4&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br /&gt; &lt;br /&gt; &lt;h4&gt; &lt;font color=&#34;black&#34;&gt;Select a form, read and click on [I agree] check box (if you agree so) for all required employment forms as below:&lt;/font&gt;&lt;/h4&gt; &lt;p&gt; &amp;nbsp;&lt;/p&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:DropDownList ID=&#34;FormList&#34; runat=&#34;server&#34; Font-Bold=&#34;True&#34; Font-Names=&#34;Arial Black&#34; Font-Size=&#34;Medium&#34; ForeColor=&#34;Maroon&#34;&gt; &lt;/asp:DropDownList&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Button ID=&#34;HRForm&#34; runat=&#34;server&#34; CssClass=&#34;Button&#34; Font-Size=&#34;Medium&#34; ForeColor=&#34;Blue&#34; Text=&#34;Load A Form&#34; OnClick=&#34;Button4_Click&#34; Font-Bold=&#34;True&#34; /&gt; &lt;br /&gt; &lt;hr /&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;img src=&#34;/Images/icon.jpg&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;h4&gt; &lt;font color=&#34;#542906&#34;&gt;After finished to read all required forms as the list as the above, please click on [Watch Video] button to complete the last step of the online employment application systems.&lt;/font&gt;&lt;/h4&gt; &lt;/p&gt; &lt;/td&gt; &lt;br /&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Button ID=&#34;Add&#34; CssClass=&#34;Button&#34; Font-Size=&#34;Medium&#34; runat=&#34;server&#34; ForeColor=&#34;Blue&#34; Text=&#34;Add To Templus&#34; OnClick=&#34;Button1_Click&#34; Font-Bold=&#34;True&#34; /&gt; &lt;asp:Button ID=&#34;WatchVideo&#34; CssClass=&#34;Button&#34; Font-Size=&#34;Medium&#34; runat=&#34;server&#34; ForeColor=&#34;Blue&#34; Text=&#34;Watch Video&#34; OnClick=&#34;Next_Click&#34; Font-Bold=&#34;True&#34; /&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;/center&gt; &lt;/div&gt; &lt;/div&gt;</pre> <p><strong>CreateW4Form.aspx</strong></p> <pre class="brush: html">&lt;asp:Button Text=&#34;Download&#34; runat=&#34;server&#34; OnClick=&#34;Download&#34;/&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; using System.Text; using System.IO; using iTextSharp.text.pdf; using iTextSharp.text; using iTextSharp.text.html.simpleparser; using Ionic.Zip;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <p><strong>CS.aspx.cs</strong></p> <pre class="brush: csharp">public string sqlConfigConnString1; public string sqlStatement1; protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { if (Session[&#34;userEmail&#34;] != null) { Label1.Text = &#34;Hello, &#34; + Session[&#34;userEmail&#34;].ToString().Trim(); } if (Session[&#34;ListItems&#34;] == null) { DataTable dt = DropDownItems(); FormList.DataSource = dt; FormList.DataTextField = &#34;Text&#34;; FormList.DataValueField = &#34;Value&#34;; FormList.DataBind(); Session[&#34;ListItems&#34;] = dt; } else { DataTable dt = (DataTable)Session[&#34;ListItems&#34;]; FormList.DataSource = dt; FormList.DataTextField = &#34;Text&#34;; FormList.DataValueField = &#34;Value&#34;; FormList.DataBind(); } FormList.Attributes.Add(&#34;size&#34;, &#34;18&#34;); FormList.Attributes.Add(&#34;Style&#34;, &#34;color:blue&#34;); } } private DataTable DropDownItems() { DataTable dt = new DataTable(); dt.Columns.Add(&#34;Text&#34;); dt.Columns.Add(&#34;Value&#34;); dt.Rows.Add(&#34;Select one item, click on [Load a Form] button&#34;, &#34;0&#34;); dt.Rows.Add(&#34;1. W-4 IRS Form&#34;, &#34;1&#34;); dt.Rows.Add(&#34;2. Sexual Harassment Policy&#34;, &#34;2&#34;); dt.Rows.Add(&#34;3. Arbitration Agreement&#34;, &#34;3&#34;); dt.Rows.Add(&#34;4. Disciplinary &amp; Attendance Policy&#34;, &#34;4&#34;); dt.Rows.Add(&#34;5. Paid Sick Leave&#34;, &#34;5&#34;); dt.Rows.Add(&#34;6. Authorization for Release of Information&#34;, &#34;6&#34;); dt.Rows.Add(&#34;7. General Code of Safe Practices&#34;, &#34;7&#34;); dt.Rows.Add(&#34;8. A Summary of Your Rights Under the Fair Credit Reporting Act&#34;, &#34;8&#34;); dt.Rows.Add(&#34;9. Meal Period Policy&#34;, &#34;9&#34;); dt.Rows.Add(&#34;10. Meal Break Waiver Agreement&#34;, &#34;10&#34;); dt.Rows.Add(&#34;11. Rest Period Policy&#34;, &#34;11&#34;); dt.Rows.Add(&#34;12. Employee Safety Orientation Sign-Off Sheet&#34;, &#34;12&#34;); dt.Rows.Add(&#34;13. Policy Statement Firearms, Weapons-Free Workplace&#34;, &#34;13&#34;); dt.Rows.Add(&#34;14. Assignment Abandonment&#34;, &#34;14&#34;); dt.Rows.Add(&#34;15. Remedying the Effects of Identity Theft&#34;, &#34;15&#34;); dt.Rows.Add(&#34;16. Drug and Alcohol Policy&#34;, &#34;16&#34;); dt.Rows.Add(&#34;17. General Safety Video&#34;, &#34;17&#34;); return dt; } protected void Button1_Click(object sender, EventArgs e) { sqlConfigConnString1 = ConfigurationManager.ConnectionStrings[&#34;Citistaff&#34;].ConnectionString; SqlConnection appConnect = new SqlConnection(sqlConfigConnString1); appConnect.ConnectionString = appConnect.ConnectionString; try { sqlStatement1 = &#34;INSERT INTO ApplicantJobApplication (OnboardingUniqueId, TempsPlusID, ApplicantLName, ApplicantMName, ApplicantFName) SELECT A.TempPlusKey, A.TempPlusID, A.ApplicantLastName, A.ApplicantMName, A.ApplicantFirstName FROM ApllicantInfoK A WHERE A.Emailsession = &#39;&#34; + Session[&#34;userEmail&#34;].ToString().Trim() + &#34;&#39;&#34;; sqlStatement1 += &#34;SELECT A.TempPlusKey, A.TempPlusID, A.ApplicantLastName, A.ApplicantMName, A.ApplicantFirstName &#34;; sqlStatement1 += &#34;FROM ApllicantInfoK A WHERE A.Emailsession = &#39;&#34; + Session[&#34;userEmail&#34;].ToString().Trim() + &#34;&#39;&#34;; if (appConnect.State == ConnectionState.Closed) { appConnect.OpenConnection(); appConnect.ExecuteQuery(sqlStatement1); appConnect.DataAdapterConnection(); } } catch (SqlException ex) { ShowMessage(ex.Message); } finally { if (appConnect.Conn.State == ConnectionState.Open) appConnect.CloseAll(); } string message = &#34;Your partial profile have been successfully added.&#34;; string url = &#34;/W4.aspx&#34;; string script = &#34;{ alert(&#39;&#34;; script += message; script += &#34;&#39;);&#34;; script += &#34;window.location = &#39;&#34;; script += url; script += &#34;&#39;; }&#34;; ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), &#34;alert&#34;, script, true); Response.Redirect(&#34;Videoscreen.aspx&#34;); } public void ShowMessage(string msg) { System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), &#34;AlertBox&#34;, &#34;alert(&#39;&#34; + msg + &#34;&#39;);&#34;, true); } protected void Button4_Click(object sender, EventArgs e) { DataTable dt = Session[&#34;ListItems&#34;] as DataTable; ListItemCollection liCol = FormList.Items; for (int i = 0; i &lt; dt.Rows.Count; i++) { ListItem li = liCol[i]; if (li.Selected) { li.Text = FormList.SelectedItem.Value; li.Value = FormList.SelectedItem.Text; if (FormList.SelectedItem.Value == &#34;1&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;CreateW4Form.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;2&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;SexualHarassment.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;3&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;ArbitrationAgreement.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;4&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;DisciplineAttendancePolicy.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;5&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;PaidSickLeave.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;6&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;AuthorizationforReleaseofInformation.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;7&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;GeneralCodeofSafePractices.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;8&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;RightsUndertheFairCreditReportingAct.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;9&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;MealPeriodPolicy.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;10&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;MealBreakWaiverAgreement.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;11&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;RestPeriodPolicy.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;12&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;EmployeesafetyOrientationSignOffSheet.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;13&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;PolicyStatementFirearmsWeaponsFreeWorkplace.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;14&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;AssignmentAbandonment.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;15&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;RemedyingtheEffectsofIdentityTheft.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;16&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;DrugAlcohol.aspx&#34;); } else if (FormList.SelectedItem.Value == &#34;17&#34;) { dt.Rows[i].Delete(); Response.Redirect(&#34;GeneralSafetyVideo.aspx&#34;); } } } } protected void Next_Click(object sender, EventArgs e) { Response.Redirect(&#34;Videoscreen.aspx&#34;); }</pre> <p><strong>CreateW4Form.aspx.cs</strong></p> <pre class="brush: vb">protected void Page_Load(object sender, EventArgs e) { DataTable dt = Session[&#34;ListItems&#34;] as DataTable; StringBuilder sb = new StringBuilder(); for (int i = 0; i &lt; dt.Rows.Count; i++) { sb.Append(&#34;&lt;p&gt;&#34;); sb.Append(dt.Rows[i][&#34;Text&#34;] + &#34;&#34; + dt.Rows[i][&#34;Value&#34;]); sb.Append(&#34;&lt;/p&gt;&#34;); File.WriteAllText(Server.MapPath(&#34;~/Filehtml/&#34;) + dt.Rows[i][&#34;Value&#34;] + &#34;.htm&#34;, sb.ToString()); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { using (StreamReader sr = new StreamReader(Server.MapPath(&#34;~/Filehtml/&#34;) + dt.Rows[i][&#34;Value&#34;] + &#34;.htm&#34;)) { using (FileStream stream = new FileStream(Server.MapPath(&#34;~/File/&#34;) + &#34;HTMLExport&#34; + dt.Rows[i][&#34;Value&#34;] + &#34;.pdf&#34;, FileMode.Create)) { Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); stream.Close(); } } } } } } protected void Download(object sender, EventArgs e) { int i = 0; using (ZipFile zip = new ZipFile()) { zip.AlternateEncodingUsage = ZipOption.AsNecessary; zip.AddDirectoryByName(&#34;Files&#34;); foreach (var filePath in Directory.GetFiles(Server.MapPath(&#34;~/File&#34;))) { i = i + 1; zip.AddFile(filePath, &#34;Files&#34;); } Response.Clear(); Response.BufferOutput = false; string zipName = String.Format(&#34;Zip_{0}.zip&#34;, DateTime.Now.ToString(&#34;yyyy-MMM-dd-HHmmss&#34;)); Response.ContentType = &#34;application/zip&#34;; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment; filename=&#34; + zipName); zip.Save(Response.OutputStream); Response.End(); } }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/116422/Convert-Web-Page-to-PDF-and-download-as-Zip-file-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/116422/Convert-Web-Page-to-PDF-and-download-as-Zip-file-using-C-in-ASPNet/Wed, 14 Aug 2019 01:54:50 GMT