string src = string.Empty; string AbsolutePath = string.Empty; _Filter.Clear(); _Filter.Add("Id",hdnCertificateId.Value); _CertificatesEntityCollection = CertificatesManager.SelectFiltered(_Filter); ScriptManager.RegisterStartupScript(this, typeof(string), "script123", "AsPdf()", true); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; //Response.AddHeader("content-disposition", "attachment;filename=" + _CertificatesEntityCollection.First().Name + ".pdf"); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + _CertificatesEntityCollection.First().Name + "\""); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); pnlCertificate.RenderControl(hw); pnlCertificate.Style.Add("border", "2px solid black"); pnlCertificate.Style.Add("margin-top", "60px"); pnlCertificate.Style.Add("text-align", "justify"); src = sw.ToString(); AbsolutePath = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath; src = src.Replace("img src=\"/", string.Format("img src=\"{0}", AbsolutePath)); StringReader sr = new StringReader(src); //Document pdfDoc = new Document(PageSize.A4_LANDSCAPE, 20f, 10f, 50f, 0f); Document pdfDoc = new Document(); pdfDoc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End();
iTextSharp
var doc1 = new iTextSharp.text.Document(); string path = Server.MapPath("PDF_Files"); PdfWriter.GetInstance(doc1, new FileStream(path + "/Doc1.pdf", FileMode.Create)); doc1.Open(); doc1.Add(new Paragraph(textbox.text)); doc1.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)