private void ExportGridToPDF() { string dt = System.DateTime.Now.ToString("MM/yyyy"); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=StudentFeesReport" + dt + ".pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); iTextSharp.text.html.simpleparser.StyleSheet ST = new iTextSharp.text.html.simpleparser.StyleSheet(); ST.LoadTagStyle("body", "encoding", "Identity-H"); Panel1.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc); htmlparser.Style = ST; PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); GridView1.AllowPaging = true; GridView1.DataBind(); }
//https://stackoverflow.com/questions/25164257/how-to-convert-html-to-pdf-using-itextsharp /************************************************** * Example #1 * * * * Use the built-in HTMLWorker to parse the HTML. * * Only inline CSS is supported. * * ************************************************/ public void HtmlAndInlineCssToPdfConvert(string html, string pdfLocation) { Byte[] bytes; using (MemoryStream ms = new MemoryStream()) { using (Document doc = new Document()) { using (PdfWriter writer = PdfWriter.GetInstance(doc, ms)) { doc.Open(); using (iTextSharp.text.html.simpleparser.HTMLWorker htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc)) { using (var sr = new StringReader(html)) { htmlWorker.Parse(sr); } } doc.Close(); } } bytes = ms.ToArray(); string testFile = pdfLocation; File.WriteAllBytes(testFile, bytes); } }
public static byte[] HtmlToPdf(string html, string filePath) { Byte[] bytes; using (var ms = new MemoryStream()) { using (var doc = new Document()) { using (var writer = PdfWriter.GetInstance(doc, ms)) { doc.Open(); using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc)) { using (var sr = new StringReader(html)) { htmlWorker.Parse(sr); } } //using (var srHtml = new StringReader(html)) //{ // iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, srHtml); //} //using (var msCss = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(example_css))) //{ // using (var msHtml = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(example_html))) // { // iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, msHtml, msCss); // } //} doc.Close(); } } bytes = ms.ToArray(); } return(bytes); }
private void ExportGridToPDF() { try { string dt = System.DateTime.Now.ToString("MM/yyyy"); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=StaffList" + dt + ".pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); Panel1.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); //GrdStaff.AllowPaging = true; //GrdStaff.DataBind(); } catch (Exception exs) { } }
public ActionResult Export(int id) { //Create a byte array that will eventually hold our final PDF Byte[] bytes; //Boilerplate iTextSharp setup here //Create a stream that we can write to, in this case a MemoryStream using (var ms = new MemoryStream()) { //Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF using (var doc = new Document()) { //Create a writer that's bound to our PDF abstraction and our stream using (var writer = PdfWriter.GetInstance(doc, ms)) { //Open the document for writing doc.Open(); //Our sample HTML and CSS var example_html = @"<p>This <em>is </em><span class=""headline"" style=""text-decoration: underline;"">some</span> <strong>sample <em> text</em></strong><span style=""color: red;"">!!!</span></p>"; var example_css = @".headline{font-size:200%}"; /************************************************** * Example #1 * * * * Use the built-in HTMLWorker to parse the HTML. * * Only inline CSS is supported. * * ************************************************/ //Create a new HTMLWorker bound to our document using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc)) { //HTMLWorker doesn't read a string directly but instead needs a TextReader (which StringReader subclasses) using (var sr = new StringReader(example_html)) { //Parse the HTML htmlWorker.Parse(sr); } } doc.Close(); } } //After all of the PDF "stuff" above is done and closed but **before** we //close the MemoryStream, grab all of the active bytes from the stream bytes = ms.ToArray(); } //Now we just need to do something with those bytes. //Here I'm writing them to disk but if you were in ASP.Net you might Response.BinaryWrite() them. //You could also write the bytes to a database in a varbinary() column (but please don't) or you //could pass them to another function for further PDF processing. var testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.pdf"); System.IO.File.WriteAllBytes(testFile, bytes); return(File(bytes, "application/pdf", "test1.pdf")); }
private void ProcessHTML(Document document, StringWriter sw) { document.SetPageSize(PageSize.A4); document.NewPage(); String htmlText = sw.ToString().Replace(sw.NewLine, string.Empty).Trim(); iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(document); htmlparser.Parse(new StringReader(htmlText)); }
private bool ConvertHtmlToPdf(StringBuilder sbHtmlText) { //StringBuilder sbHtmlText //StringBuilder sbHtmlText = new StringBuilder(); //sbHtmlText.Append("<html><head>Employee Info</head>"); //sbHtmlText.Append("<body>Hi This is Employee Info</body></html>"); //string userid = Session["UserId"].ToString(); string userid = User.UserId; Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\" + userid + ".pdf", FileMode.Create)); document.Open(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); try { hw.Parse(new StringReader(sbHtmlText.ToString())); } catch (Exception ex) { } document.Close(); try { Response.ClearHeaders(); Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + userid + ".pdf"); Response.TransmitFile(Request.PhysicalApplicationPath + "\\" + userid + ".pdf"); Response.End(); } catch (Exception ex) { } if (System.IO.File.Exists(Server.MapPath("\\" + userid + ".pdf"))) { // Use a try block to catch IOExceptions, to // handle the case of the file already being // opened by another process. try { System.IO.File.Delete(Server.MapPath("\\" + userid + ".pdf")); } catch (System.IO.IOException e) { Console.WriteLine(e.Message); } } return(true); }
private void CreateCriminalPDF(string criminalData, string fName) { string fileLoc = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/") + "/" + fName + ".pdf"; Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(fileLoc, FileMode.Create)); document.Open(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); hw.Parse(new StringReader(criminalData)); document.Close(); }
public string Convert(string html, string location, string pdfName = "") { string retValue = string.Empty; try { if (string.IsNullOrEmpty(pdfName)) { pdfName = "GenericPDF"; } string path = location + string.Format("{0}.pdf", pdfName); if (File.Exists(path)) { File.Delete(path); } // Step 1: Creating System.IO.FileStream object using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) // Step 2: Creating iTextSharp.text.Document object using (Document doc = new Document()) // Step 3: Creating iTextSharp.text.pdf.PdfWriter object // It helps to write the Document to the Specified FileStream using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) { // Step 4: Openning the Document doc.Open(); iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); string newhtml = ""; newhtml = html.Replace(System.Environment.NewLine, ""); hw.Parse(new StringReader(newhtml)); //document.Close(); //// Step 5: Adding a paragraph //// NOTE: When we want to insert text, then we've to do it through creating paragraph //doc.Add( new Paragraph( html ) ); // Step 6: Closing the Document doc.Close(); } } catch (DocumentException de) { retValue = string.Format("Error: {0}", de.Message); } catch (IOException ioe) { retValue = string.Format("Error: {0}", ioe.Message); } return(retValue); }
public byte[] pdfBytes(string escapedString) { Document doc = null; try { doc = new Document(PageSize.A4); MemoryStream memStream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(doc, memStream); writer.CloseStream = false; doc.Open(); string html = "<html><body>"; html += Microsoft.JScript.GlobalObject.unescape(escapedString); html += "</body></html>"; iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); hw.Parse(new StringReader(html)); //Chunk chunk = new Chunk(html, FontFactory.GetFont("arial")); //chunk.Font.Size = 10; //Phrase p1 = new Phrase(chunk); //Paragraph p = new Paragraph(p1); //doc.Add(p); //StringReader str = new StringReader(html); //XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, str); if (doc.IsOpen()) { doc.Close(); } return(memStream.ToArray()); } catch (Exception ex) { return(Encoding.ASCII.GetBytes("Error Occured")); } finally { if (doc.IsOpen()) { doc.Close(); } } }
//// Procedimiento para probar //public static void imprimeCarta(string text_carta) //{ // string vRta = ""; // string rutaPlanti = ""; // string rutaPDF = "carta.pdf"; // //Prepara el contenido de la carta y lo exporta a PDF // vRta = htmlPDF(rutaPlanti, rutaPDF, text_carta); // if (!string.IsNullOrEmpty(vRta.Trim())) // { // } // else { // } //} //Este metodo interpreta las etiquetas basicas html y las pasa a objetos itexsharp para generar el pdf con una plantilla public string htmlPDF(string rutaPlant, string rutaPDF, string textHTML) { string functionReturnValue = null; string vRta = ""; try { //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if (File.Exists(rutaPDF)) { File.Delete(rutaPDF); } MemoryStream mstream = new MemoryStream(); Document Documento = new Document(PageSize.LETTER, 60, 50, 70, 60); PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(Documento, mstream); Documento.Open(); //Apertura del documento. Documento.NewPage(); //Agregamos una pagina. iTextSharp.text.html.simpleparser.HTMLWorker htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(Documento); htmlWorker.Parse(new StringReader(textHTML)); Documento.Close(); //Cerramos el documento. if (!string.IsNullOrEmpty(rutaPlant)) { //si viene una ruta de una plantilla para utilizar como background realiza la fusion mstream = fusionarPDF(rutaPlant, mstream, ref vRta); } using (FileStream fs = new FileStream(rutaPDF, FileMode.Create)) { byte[] arrbyte = mstream.ToArray(); fs.Write(arrbyte, 0, arrbyte.Length); } } catch (Exception ex) { vRta = ex.Message + " " + ex.StackTrace; } finally { functionReturnValue = vRta; // } return(functionReturnValue); }
/// <summary> /// Generates the PDF from template. /// </summary> /// <param name="template">The template.</param> /// <returns>PDF byte stream</returns> public static byte[] GeneratePdfFromTemplate(string template) { var document = new Document(); using (var memStream = new System.IO.MemoryStream()) { using (var pdfWriter = PdfWriter.GetInstance(document, memStream)) { document.Open(); var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(document); htmlWorker.Parse(new System.IO.StringReader(GetTemplateData(template))); } document.Close(); return(memStream.ToArray()); } }
public ActionResult EncuestaPDF(int idencuesta) { Guid g = Guid.NewGuid(); string rutaarchivo = Server.MapPath("/Reportes") + g.ToString() + "Encuesta.pdf"; iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.A4, 20, 20, 20, 20); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(rutaarchivo, FileMode.Create)); document.Open(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document, null, null); string Contenido = contenidopdf(idencuesta); hw.Parse(new StringReader(Contenido)); document.Close(); return(File(rutaarchivo, "application/pdf", "Encuesta.pdf")); }
public void GerarPdf(List<Pagamento> listaPagamento) { var doc = new Document(); PdfWriter.GetInstance(doc, new FileStream(@"c:\temp\teste.pdf", FileMode.Create)); doc.Open(); var pagamento = listaPagamento.First(); var corpoEmail = CorpoEmail(); corpoEmail = corpoEmail.Replace("[mes]", pagamento.DataPagamento.ToString("Y")); corpoEmail = corpoEmail.Replace("[canal]", pagamento.Contrato.Vendedor.Nome); corpoEmail = corpoEmail.Replace("[body]", BodyTabelaComissao(listaPagamento)); corpoEmail = corpoEmail.Replace("[foot]", FooterTabelaComissao(listaPagamento)); var hw = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); hw.Parse(new StringReader(corpoEmail)); doc.Close(); //return corpoEmail; }
//Este metodo interpreta las etiquetas basicas html y las pasa a objetos itexsharp para generar el pdf /* * this[HtmlTags.A] = A; * this[HtmlTags.B] = EM_STRONG_STRIKE_SUP_SUP; * this[HtmlTags.BODY] = DIV; * this[HtmlTags.BR] = BR; * this[HtmlTags.DIV] = DIV; * this[HtmlTags.EM] = EM_STRONG_STRIKE_SUP_SUP; * this[HtmlTags.FONT] = SPAN; * this[HtmlTags.H1] = H; * this[HtmlTags.H2] = H; * this[HtmlTags.H3] = H; * this[HtmlTags.H4] = H; * this[HtmlTags.H5] = H; * this[HtmlTags.H6] = H; * this[HtmlTags.HR] = HR; * this[HtmlTags.I] = EM_STRONG_STRIKE_SUP_SUP; * this[HtmlTags.IMG] = IMG; * this[HtmlTags.LI] = LI; * this[HtmlTags.OL] = UL_OL; * this[HtmlTags.P] = DIV; * this[HtmlTags.PRE] = PRE; * this[HtmlTags.S] = EM_STRONG_STRIKE_SUP_SUP; * this[HtmlTags.SPAN] = SPAN; * this[HtmlTags.STRIKE] = EM_STRONG_STRIKE_SUP_SUP; * this[HtmlTags.STRONG] = EM_STRONG_STRIKE_SUP_SUP; * this[HtmlTags.SUB] = EM_STRONG_STRIKE_SUP_SUP; * this[HtmlTags.SUP] = EM_STRONG_STRIKE_SUP_SUP; * this[HtmlTags.TABLE] = TABLE; * this[HtmlTags.TD] = TD; * this[HtmlTags.TH] = TD; * this[HtmlTags.TR] = TR; * this[HtmlTags.U] = EM_STRONG_STRIKE_SUP_SUP; * this[HtmlTags.UL] = UL_OL; */ public MemoryStream htmlPDF(string textHTML, Document Documento = null) { MemoryStream mstream = new MemoryStream(); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if (Documento == null) { Documento = new Document(iTextSharp.text.PageSize.LETTER, 60, 50, 70, 60); } PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(Documento, mstream); Documento.Open(); //Apertura del documento. Documento.NewPage(); //Agregamos una pagina. iTextSharp.text.html.simpleparser.HTMLWorker htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(Documento); htmlWorker.Parse(new StringReader(textHTML)); Documento.Close(); //Cerramos el documento. return(mstream); }
public HttpResponseMessage Generisi_izvestaj(String jezik) { var response = Request.CreateResponse(HttpStatusCode.OK); using (var ms = new MemoryStream()) { //Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF using (var doc = new Document()) { using (var writer = PdfWriter.GetInstance(doc, ms)) { doc.Open(); var data = db.Faktura; String html = generateHtmlOutOfFaktura(data); using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc)) { //HTMLWorker doesn't read a string directly but instead needs a TextReader (which StringReader subclasses) using (var sr = new StringReader(html)) { //Parse the HTML htmlWorker.Parse(sr); } } doc.Close(); response = Request.CreateResponse(HttpStatusCode.OK); Byte[] bytes; bytes = ms.ToArray(); var msNew = new MemoryStream(bytes); response.Content = new StreamContent(msNew); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); response.Content.Headers.ContentLength = bytes.Length; ms.Close(); ms.Flush(); } } } return(response); }
private void ExportGridToPDF() { string dt = System.DateTime.Now.ToString("MM/yyyy"); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=SalarySlip_" + Session["UserCode"].ToString() + "_" + dt + ".pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); tbldata.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 20f, 20f, 0f, 0f); iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); }
private byte[] ConvertHtmlToPdf(StringBuilder sbHtmlText, string testname, string userid) { byte[] bPDF = null; string returnvalue = string.Empty; returnvalue = Request.PhysicalApplicationPath + "\\Upload\\" + userid + testname + ".pdf"; MemoryStream ms = new MemoryStream(); TextReader txtReader = new StringReader(sbHtmlText.ToString()); // 1: create object of a itextsharp document class Document doc = new Document(PageSize.A4, 25, 25, 25, 25); // 2: we create a itextsharp pdfwriter that listens to the document and directs a XML-stream to a file PdfWriter oPdfWriter = PdfWriter.GetInstance(doc, ms); // 3: we create a worker parse the document iTextSharp.text.html.simpleparser.HTMLWorker htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); // 4: we open document and start the worker on the document doc.Open(); htmlWorker.StartDocument(); // 5: parse the html into the document htmlWorker.Parse(txtReader); // 6: close the document and the worker htmlWorker.EndDocument(); htmlWorker.Close(); doc.Close(); ms.Close(); bPDF = ms.ToArray(); //System.IO.File.WriteAllBytes(returnvalue, bPDF); return(bPDF); }
public void HTMLToPdf(string HTML, string FilePath) { Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\Chap0101.pdf", FileMode.Create)); document.Open(); Image pdfImage = Image.GetInstance(Server.MapPath("\\store.png")); pdfImage.ScaleToFit(100, 50); pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING; pdfImage.SetAbsolutePosition(180, 760); document.Add(pdfImage); iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); hw.Parse(new StringReader(HTML)); document.Close(); Response.ContentType = "application/pdf"; //Set default file Name as current datetime Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMdd") + ".pdf"); System.Web.HttpContext.Current.Response.Write(document); ShowPdf("\\Chap0101.pdf"); }
public HttpResponseMessage getPdf() { /*var data = db.Roba; * * Byte[] res = null; * var response = Request.CreateResponse(HttpStatusCode.OK); * String html = generateHtmlOutOfObject(data); * using (MemoryStream ms = new MemoryStream()) * { * * var statuscode = HttpStatusCode.OK; * var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4); * pdf.Save(ms); * var buffer = ms.GetBuffer(); * var contentLength = buffer.Length; * res = ms.ToArray(); * response = Request.CreateResponse(statuscode); * response.Content = new StreamContent(new MemoryStream(buffer)); * response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); * response.Content.Headers.ContentLength = contentLength; * ms.Close(); * } */ /* * * var html = String.Format("<body>Hello world: {0}</body>", * DateTime.Now); * * * var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter(); * var pdfBytes = htmlToPdf.GeneratePdf(html); * var contentLength = pdfBytes.Length; * //res = ms.ToArray(); * var response = Request.CreateResponse(HttpStatusCode.OK); * response = Request.CreateResponse(statuscode); * var ms = new MemoryStream(pdfBytes); * response.Content = new StreamContent(ms); * response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); * response.Content.Headers.ContentLength = contentLength; * //ms.Close(); * //ms.Close(); * //ms.Flush(); */ //PDFCre using (var ms = new MemoryStream()) { //Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF using (var doc = new Document()) { using (var writer = PdfWriter.GetInstance(doc, ms)) { doc.Open(); var data = db.Roba; String html = "<body>asada</body>"; using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc)) { //HTMLWorker doesn't read a string directly but instead needs a TextReader (which StringReader subclasses) using (var sr = new StringReader(html)) { //Parse the HTML htmlWorker.Parse(sr); } } doc.Close(); var response = Request.CreateResponse(HttpStatusCode.OK); Byte[] bytes; bytes = ms.ToArray(); var msNew = new MemoryStream(bytes); response.Content = new StreamContent(msNew); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); response.Content.Headers.ContentLength = bytes.Length; ms.Close(); ms.Flush(); return(response); } } } }
protected void LinkPDF_Click(object sender, EventArgs e) { if (lblInforme.Text != "") { if (txtFechaInicio.Text != "" && txtFechaTermino.Text != "") { string[] str = txtFechaInicio.Text.Split('/'); DateTime f1 = Convert.ToDateTime(str[2] + "-" + str[1] + "-" + str[0] + " 00:00:00"); string[] str2 = txtFechaTermino.Text.Split('/'); DateTime f2 = Convert.ToDateTime(str2[2] + "-" + str2[1] + "-" + str2[0] + " 23:59:59"); if (ddlSeccion.SelectedValue.ToString() == "Todas") { if (ddlMaquinas.SelectedValue.ToString() != "Seleccione...") { lblInforme.Text = sc.Carga_Programacion_PDF("", ddlMaquinas.SelectedValue.ToString(), f1, f2, 2); } else { lblInforme.Text = sc.Carga_Programacion_PDF("", "", f1, f2, 1); } } else { if (ddlSeccion.SelectedValue.ToString() == "Rotativa") { if (ddlMaquinas.SelectedValue.ToString() != "Seleccione...") { lblInforme.Text = sc.Carga_Programacion_PDF("", ddlMaquinas.SelectedValue.ToString(), f1, f2, 4); } else { lblInforme.Text = sc.Carga_Programacion("", "", f1, f2, 3); } } else if (ddlSeccion.SelectedValue.ToString() == "Planas") { if (ddlMaquinas.SelectedValue.ToString() != "Seleccione...") { lblInforme.Text = sc.Carga_Programacion_PDF("", ddlMaquinas.SelectedValue.ToString(), f1, f2, 6); } else { lblInforme.Text = sc.Carga_Programacion_PDF("", "", f1, f2, 5); } } } } else { string[] str = DateTime.Now.ToString("dd/MM/yyyy").Split('/'); DateTime f1 = Convert.ToDateTime(str[2] + "-" + str[1] + "-" + str[0] + " 00:00:00"); DateTime f2 = Convert.ToDateTime(str[2] + "-" + str[1] + "-" + str[0] + " 23:59:59"); if (ddlSeccion.SelectedValue.ToString() == "Todas") { lblInforme.Text = sc.Carga_Programacion_PDF("", "", f1, f2, 1); } else { if (ddlSeccion.SelectedValue.ToString() == "Rotativa") { if (ddlMaquinas.SelectedValue.ToString() != "Seleccione...") { lblInforme.Text = sc.Carga_Programacion_PDF("", ddlMaquinas.SelectedValue.ToString(), f1, f2, 4); } else { lblInforme.Text = sc.Carga_Programacion_PDF("", "", f1, f2, 3); } } else if (ddlSeccion.SelectedValue.ToString() == "Planas") { if (ddlMaquinas.SelectedValue.ToString() != "Seleccione...") { lblInforme.Text = sc.Carga_Programacion_PDF("", ddlMaquinas.SelectedValue.ToString(), f1, f2, 6); } else { lblInforme.Text = sc.Carga_Programacion_PDF("", "", f1, f2, 5); } } } } Document document = new Document(); document.SetPageSize(PageSize.A4.Rotate()); PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\ProgramacionProduccion.pdf", FileMode.Create)); document.Open(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); hw.Parse(new StringReader("<div align='center'><h1>Programacion de Producción</h1></div> " + lblInforme.Text)); HeaderFooter header = new HeaderFooter(new Paragraph("Header\n <div style='color:red;'>apekedikdjaj</div>"), false); document.Header = header; document.Close(); Response.Clear(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=ProgramacionProduccion"); Response.WriteFile(Request.PhysicalApplicationPath + "\\ProgramacionProduccion.pdf"); Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { OrdenesCompra o = oc.GeneraPDF(Request.QueryString["id"], "", 7); string contenido = "<div align='right' style='font-weight: bold;font-size:10px;'>Orden de Compra</div>" + "<table style='width:100%;' border='0' >" + "<tr>" + "<td class='style1' align='left'>" + "<img height='95px' alt='Logo AImpresores'" + "src='http://intranet.qgchile.cl/Images/LOGO%20A.png' width='240px' ></td>" + "<td align='center'>" + "<table style='border:1px solid black;border-collapse:collapse;width:100%;' border='1'>" + "<tr >" + "<td align='center' style='font-size:9px;'>" + "Orden de Compra</td>" + "<td align='center' style='font-size:9px;'>" + "Fecha Orden</td>" + "</tr>" + "<tr>" + "<td align='center' style='font-weight: bold;font-size:9px;'>" + o.NroOC + "</td>" + "<td align='center' style='font-weight: bold;font-size:9px;'>" + Convert.ToDateTime(o.FechaCreacion).ToString("dd/MM/yyyy") + "</td>" + "</tr>" + "<tr>" + "<td align='center' style='font-size:9px;'>" + "Condición de Pago</td>" + "<td align='center' style='font-size:9px;'>" + "Moneda</td>" + "</tr>" + "<tr>" + "<td align='center' style='font-weight: bold;font-size:9px;'>" + o.CondicionPago + "</td>" + "<td align='center' style='font-weight: bold;font-size:9px;'>" + o.Moneda + "</td>" + "</tr>" + "<tr>" + "<td colspan='2' align='right' style='font-weight: bold;font-size:8px;'>" + "Generado Por: " + o.CreadoPor + " " + Convert.ToDateTime(o.FechaCreacion).ToString("dd/MM/yyyy HH:mm") + "</td>" + "</tr>" + "</table>" + "</td>" + "</tr>" + "</table>" + "<table style='width: 100%;'>" + "<tr>" + "<td>" + "<div><a style='font-weight: bold;font-size:11px;'>Enviar a: A Impresores S.A.</a></div>" + "<div><a style='font-size:11px;'>Avda. Las Parcelas, No 4568, Estación Central<br />Santiago, Chile.</a></div>" + "</td>" + "<td>" + "<div><a style='font-weight: bold;font-size:11px;'>Facturar a: A Impresores S.A.</a></div>" + "<div><a style='font-size:11px;'>Avda. Gladys Marin No 6920, Estación Central<br />Santiago, Chile.</a></div>" + "<div><a style='font-size:11px;'>R.U.T.: 96830710-k</a></div>" + "<div><a style='font-size:11px;'>Tel: 4405700</a></div>" + "</td>" + "</tr>" + "</table>" + // "<table style='width:100%;'> " + //"<tr>" + //"<td class='style32'><a style='font-weight: bold;font-size:9px;'> Proveedor:</a></td>" + //"<td class='style26'><a style='font-size:9px;' > FERROSTAL CHILE S.A.C </a></td> " + // "<td class='style28' > </td> " + // "<td class='style21' ><a style='font-size:9px;'> </a></td> " + //"</tr> " + //"<tr> " + //"<td class='style33' ><a style='font-weight: bold;font-size:9px;'> Direccion:</a></td> " + //"<td class='style27' ><a style='font-size:9px;'> AV. SANTA MARIA 2810, SANTIAGO </a></td> " + // "<td class='style29' > </td> " + // "<td > </td> " + //"</tr> " + //"<tr> " + //"<td class='style33' ><a style='font-weight: bold;font-size:9px;'> Rut:</a></td> " + //"<td class='style27' >91336000-1</td> " + // "<td > </td> " + // "<td colspan='2'> </td> " + //"</tr> " + //"<tr> " + //"<td class='style34' ><a style='font-weight: bold;font-size:9px;'> Contacto:</a></td> " + //"<td colspan='2' ><a style='font-size:9px;'> ANDRES GALLARDO </a></td> " + // "<td class='style36' ><a style='font-weight: bold;font-size:9px;'> Correo:</a></td> " + // "<td colspan='2' ><a style='font-size:9px;'> [email protected] </a></td> " + //"</tr> " + //"<tr> " + //"<td class='style33' ><a style='font-weight: bold;font-size:9px;'> Telefono:</a></td> " + //"<td colspan='2' ><a style='font-size:9px;'> 22372020 </a></td> " + // "<td class='style29' ><a style='font-weight: bold;font-size:9px;'> Fecha de Entrega:</a></td> " + // "<td colspan='2'><a style='font-size:9px;'> 17/03/2016 </a></td> " + //"</tr> " + //"</table> " + "<br /><table style='width:100%;'>" + "<tr> " + "<td class='style32'><a style='font-weight: bold;font-size:10px;'> Rut:</a></td> " + "<td class='style26' colspan='3'><a style='font-size:10px;' >" + o.Rut + "</a></td> " + "</tr> " + "<tr> " + "<td class='style32'><a style='font-weight: bold;font-size:10px;'> Proveedor:</a></td> " + "<td class='style26' colspan='3'><a style='font-size:10px;' >" + o.Proveedor.ToUpper() + "</a></td> " + // "<td class='style28' > </td> " + //"<td class='style21' ><a style='font-size:9px;'> o.Rut </a></td> " + "</tr> " + "<tr> " + "<td class='style33' ><a style='font-weight: bold;font-size:10px;'> Direccion:</a></td> " + "<td class='style27' colspan='3'><a style='font-size:10px;'>" + o.Direccion.ToUpper() + "</a></td> " + //"<td class='style29' > </td> " + //"<td > </td> " + "</tr> " + //"<tr> " + //"<td class='style33' ><a style='font-weight: bold;font-size:10px;'> Rut:</a></td> " + //"<td class='style27' ><a style='font-size:10px;'>91336000-1</a></td> " + // "<td class='style29' > </td>" + // "<td > </td> " + //"</tr> " + "<tr> " + "<td class='style34' ><a style='font-weight: bold;font-size:10px;'> Contacto:</a></td> " + "<td class='style37' ><a style='font-size:10px;'>" + o.Contacto + "</a></td> " + "<td class='style36' ><a style='font-weight: bold;font-size:10px;'> Correo:</a></td> " + "<td class='style35' ><a style='font-size:8px;'>" + o.Email + "</a></td> " + "</tr> " + "<tr> " + "<td class='style33' ><a style='font-weight: bold;font-size:10px;'> Telefono:</a></td> " + "<td class='style27' ><a style='font-size:10px;'>" + o.Telefono + "</a></td> " + "<td class='style29' ><a style='font-weight: bold;font-size:10px;'> Fecha de Entrega:</a></td> " + "<td ><a style='font-size:10px;'>" + Convert.ToDateTime(o.FechaEntrega).ToString("dd/MM/yyyy") + "</a></td> " + "</tr> " + "</table> " + oc.GeneraItemsPDF(Request.QueryString["id"], "", 8) + "<table style='width:100%;'>" + " <tr>" + " <td>" + " </td>" + "<td>" + " <table style='width:100%;'>" + " <tr>" + " <td align='right'>" + " <a style='font-size:9px;'> Subtotal:</a></td>" + " <td align='right'>" + " <a style='font-size:9px;'>" + o.Unidad + " $ " + Convert.ToDouble(o.ValorTotal).ToString("N2") + "</a></td>" + " </tr>" + "<tr>" + " <td align='right'>" + " <a style='font-size:9px;'> I.V.A.:</a></td>" + " <td align='right'>" + " <a style='font-size:9px;'>" + o.Unidad + " $ " + Convert.ToDouble(o.ValorIVA).ToString("N2") + "</a></td>" + "</tr>" + "<tr>" + " <td align='right'>" + " <a style='font-weight: bold;font-size:9px;'> Total:</a></td>" + "<td align='right'>" + " <a style='font-weight: bold;font-size:9px;'>" + o.Unidad + " $ " + Convert.ToDouble(o.ValorTotalConIVA).ToString("N2") + "</a></td>" + "</tr>" + "</table>" + "</td>" + "</tr>" + "</table>" + // "<table>"+ // "<tr>"+ // "<td>"+ // " </td>"+ // " <td>"+ //" <div>Valor</div>"+ //" <div>Valor</div>" + //" <div>Valor</div>" + // "</td>"+ // // " <table style='font-size:12px;' border='1'> "+ // // "<tr> "+ // // " <td> "+ // // " <div align='center' style='font-weight: bold;font-size:9px;'>Valor</div> "+ // // " </td> "+ // // " <td> "+ // // " <div align='right' style='font-size:9px;'> 10.000.000,00 </div></td> "+ // // "</tr> "+ // // "<tr> "+ // // " <td> "+ // // " <div align='center' style='font-weight: bold;font-size:9px;'>I.V.A</div></td> "+ // // " <td> "+ // // " <div align='right' style='font-size:9px;'> 1.900.000,00 </div></td> "+ // //" </tr> "+ // //" <tr> "+ // //" <td> "+ // //" <div align='center' style='font-weight: bold;font-size:9px;'>Total</div></td> "+ // //" <td> "+ // //" <div align='right' style='font-size:9px;'> 11.900.000,00 </div></td> "+ // //" </tr></table> </td>"+ // " </tr>"+ // "</table>" + //"<table style='border:1px solid black;border-collapse:collapse;width:100%;' border='1'> "+ //"<tr> "+ //"<th style='border:1px solid black;' class='style23'>Descripcion</th> "+ // "<th style='border:1px solid black;' class='style8'>Cantidad</th> "+ // "<th style='border:1px solid black;' class='style18'>Precio</th> "+ // "<th style='border:1px solid black;'>Total</th> "+ //"</tr> "+ //"<tr> "+ //"<td style='border:1px solid black;' class='style15'>Table cell 1</td> "+ // "<td style='border:1px solid black;' class='style13'>Table cell 2</td>"+ // "<td style='border:1px solid black;' class='style19'></td> "+ // "<td style='border:1px solid black;' class='style12'></td> "+ //"</tr> "+ //"<tr> "+ //"<td style='border:1px solid black;' class='style23'>Table cell 3</td> "+ // "<td style='border:1px solid black;' class='style8'>Table cell 4</td> "+ // "<td style='border:1px solid black;' class='style18'> </td> "+ // "<td style='border:1px solid black;'> </td> "+ //"</tr> "+ //"</table>"+ "<a style='font-size:10px;'>ANOTAR EN GUIA/FACTURA LOS NÚMEROS DE ORDEN DE COMPRA</a><br /><br />" + "<table style='border:1px solid black;border-collapse:collapse;width:100%;' border='1'>" + "<tr >" + "<td>" + "<div><a style='font-weight: bold;font-size:9px;'>Observación:</a></div>" + "<div><a style='font-size:9px;'>" + o.Observacion + "</a></div>" + "<br />" + "</td>" + "</tr>" + "</table> " + "<br />" + "<div align='center'> __________________________<br /> " + "<a style='font-weight: bold;font-size:9px;'> " + "Rafael Maroto<br /> " + "Sub-Gerente de Abastecimiento " + "</a></div>" + "<br />" + "<a style='font-weight: bold;font-size:8px;'>UNA VEZ QUE EL MATERIAL Y/O SERVICIO HAYA SIDO ENTREGADO Y REALIZADO, LAS FACTURAS ELECTRONICAS DEBEN SER ENVIADAS POR CORREO ELECTRÓNICO A: [email protected]; [email protected]</a>"; // string contenido = "<table style='width:100%;' border='0' >" + // "<tr>" + // "<td class='style1' align='left'>" + // "<img height='109px' alt='Logo Quad' src='http://falabella.qgchile.cl/images/quadlogo.PNG' width='252px' /></td>" + // "<td align='center'>" + // "<div style='font-weight: bold;font-size:18px;'>QUAD/GRAPHICS CHILE S.A.</div>" + // "<div style='font-size:8px;'>Av. Gladys Marín Millie 6920, Estación Central, Santiago de Chile" + // "<br />" + // "Teléfono: 4405700 / Fax: 4405890<br />" + // "Rut: 96.830.710-k" + // "<br /> <br /></div>" + // "</td>" + // "</tr>" + // "</table>" + // "<table>" + // "<tr>" + // "<td align='center' class='style24'>" + // "<div style='font-weight: bold;font-size:15px;font-style:italic;'>Orden de Compra N° " + Request.QueryString["id"] + "</div>" + // "<div align='right' style='font-size:7px;font-style:italic;'>Emitida Por: " + o.CreadoPor + " " + Convert.ToDateTime(o.FechaCreacion).ToString("dd/MM/yyyy") + "</div>" + // "</td>" + // "</tr>" + // "</table>" + // "<a>______________________________________________________________________________</a>" + ////"<table style='width:100%;'>" + // //"<tr>" + // //"<td class='style32'><a style='font-weight: bold;font-size:9px;'> Proveedor</a></td>" + // //"<td class='style26'><a style='font-size:9px;'>" + o.Proveedor + "</a></td>" + // // "<td class='style28' ><a style='font-weight: bold;font-size:9px;'> Rut</a></td>" + // // "<td class='style21' ><a style='font-size:9px;'>" + o.Rut + "</a></td>" + // //"</tr>" + // //"<tr>" + // //"<td class='style33' ><a style='font-weight: bold;font-size:9px;'> Direccion</a></td>" + // //"<td class='style27' ><a style='font-size:9px;'>" + o.Direccion + "</a></td>" + // // "<td class='style29' > </td>" + // // "<td > </td>" + // //"</tr>" + // //"<tr>" + // //"<td class='style33' > </td>" + // //"<td class='style27' > </td>" + // // "<td class='style29' > </td>" + // // "<td > </td>" + // //"</tr>" + // //"<tr>" + // //"<td class='style34' ><a style='font-weight: bold;font-size:9px;'> Contacto</a></td>" + // //"<td class='style37' ><a style='font-size:9px;'>" + o.Contacto + "</a></td>" + // // "<td class='style36' ></td>" + // // "<td class='style35' ></td>" + // //"</tr>" + // //"<tr>" + // //"<td class='style33' ><a style='font-weight: bold;font-size:9px;'> Telefono</a></td>" + // //"<td class='style27' ><a style='font-size:9px;'>" + o.Telefono + "</a></td>" + // // "<td class='style29' ><a style='font-weight: bold;font-size:9px;'> Correo</a></td>" + // // "<td ><a style='font-size:9px;'>" + o.Email + "</a></td>" + // //"</tr>" + // //"</table>" + // "<table style='width:100%;'>" + //"<tr>" + //"<td class='style32'><a style='font-weight: bold;font-size:9px;'> Proveedor:</a></td>" + //"<td class='style26' colspan='2'><a style='font-size:9px;'> " + o.Proveedor + " </a></td>" + // "<td class='style28' ><a style='font-weight: bold;font-size:9px;'> Rut:</a></td>" + // "<td class='style21' ><a style='font-size:9px;'> " + o.Rut + " </a></td>" + //"</tr>" + //"<tr>" + //"<td class='style33' ><a style='font-weight: bold;font-size:9px;'> Direccion:</a></td>" + //"<td class='style27' colspan='2' ><a style='font-size:9px;'> " + o.Direccion + " </a></td>" + // "<td class='style29' > </td>" + // "<td > </td>" + //"</tr>" + //"<tr>" + //"<td class='style33' > </td>" + //"<td class='style27' > </td>" + //"<td class='style27' > </td>" + // "<td class='style29' > </td>" + // "<td > </td>" + //"</tr>" + //"<tr>" + //"<td class='style34' ><a style='font-weight: bold;font-size:9px;'> Contacto:</a></td>" + //"<td class='style37' colspan='2' ><a style='font-size:9px;'> " + o.Contacto + " </a></td>" + // "<td class='style36' ><a style='font-weight: bold;font-size:9px;'> Correo:</a></td>" + // "<td class='style35' ><a style='font-size:9px;'> " + o.Email + " </a></td>" + //"</tr>" + //"<tr>" + //"<td class='style33' ><a style='font-weight: bold;font-size:9px;'> Telefono:</a></td>" + //"<td class='style27' colspan='2' ><a style='font-size:9px;'> " + o.Telefono + " </a></td>" + // "<td class='style29' ><a style='font-weight: bold;font-size:9px;'> Fecha de Entrega:</a></td>" + // "<td ><a style='font-size:9px;'> " + Convert.ToDateTime(o.FechaEntrega).ToString("dd/MM/yyyy") + " </a></td>" + //"</tr> " + //"</table> " + //"<a>______________________________________________________________________________</a>" + // "<a style='font-size:9px;'>Solicitamos despachar lo siguiente:</a><br /><br />" + //// "<table style='border:1px solid black;border-collapse:collapse;width:100%;' border='1'>" + // //"<tr>" + // //"<th style='border:1px solid black;' class='style23'>Descripcion</th>" + // // "<th style='border:1px solid black;' class='style8'>Cantidad</th>" + // // "<th style='border:1px solid black;' class='style18'>Precio</th>" + // // "<th style='border:1px solid black;'>Total</th>" + // //"</tr>" + // //"<tr>" + // //"<td style='border:1px solid black;' class='style15'>Table cell 1</td>" + // // "<td style='border:1px solid black;' class='style13'>Table cell 2</td>" + // // "<td style='border:1px solid black;' class='style19'></td>" + // // "<td style='border:1px solid black;' class='style12'></td>" + // //"</tr>" + // //"<tr>" + // //"<td style='border:1px solid black;' class='style23'>Table cell 3</td>" + // // "<td style='border:1px solid black;' class='style8'>Table cell 4</td>" + // // "<td style='border:1px solid black;' class='style18'> </td>" + // // "<td style='border:1px solid black;'> </td>" + // //"</tr>" + // //"</table>"+ //oc.GeneraItemsPDF(Request.QueryString["id"], "", 8) + // "<br />" + // "<table style='width:100%;' align='center'>" + // "<tr>" + // "<td align='center' class='style20'>" + // "<table style='width:100%;font-size:12px;margin-top:-50px;' border='1'>" + // "<tr>" + // "<td>" + // "<div align='center' style='font-weight: bold;font-size:9px;'>Observacion</div>" + // "</td>" + // "</tr>" + // "<tr>" + // "<td >" + // "<div align='center'><a style='font-size:9px;'>" + // o.Observacion + // "</a></div><br /></td>" + // "</tr>" + // "</table>" + // "</td>" + // "<td >" + // "<br /><table style='width:50%;font-size:12px;' border='1'>" + // "<tr>" + // "<td>" + // "<div align='center' style='font-weight: bold;font-size:9px;'>Valor</div>" + // "</td>" + // "<td>" + // "<div align='right' style='font-size:9px;'>" + Convert.ToDouble(o.ValorTotal).ToString("N2") + "</div></td>" + // "</tr>" + // "<tr>" + // "<td>" + // "<div align='center' style='font-weight: bold;font-size:9px;'>I.V.A</div></td>" + // "<td>" + // "<div align='right' style='font-size:9px;'>" + Convert.ToDouble(o.ValorIVA).ToString("N2") + "</div></td>" + // "</tr>" + // "<tr>" + // "<td>" + // "<div align='center' style='font-weight: bold;font-size:9px;'>Total</div></td>" + // "<td>" + // "<div align='right' style='font-size:9px;'>" + Convert.ToDouble(o.ValorTotalConIVA).ToString("N2") + "</div></td>" + // "</tr></table>" + // "<br />" + // "<br />" + // "<br /><div align='center'>" + // "__________________________<br />" + // "<a style='font-weight: bold;font-size:9px;'>" + // "V°B°<br />" + // "Rafael Maroto<br />" + // "Gerente de Abastecimiento" + // "</a></div>" + // "</td>" + // "</tr>" + // "</table>"; Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "PDF\\" + Request.QueryString["id"] + ".pdf", FileMode.Create)); document.Open(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); hw.Parse(new StringReader(contenido)); document.Close(); Response.Redirect("../../PDF/" + Request.QueryString["id"] + ".pdf"); //Response.Clear(); //Response.ContentType = "application/pdf"; //Response.AddHeader("Content-Disposition", "attachment; filename=MySamplePDF"); //Response.WriteFile(Request.PhysicalApplicationPath + "\\MySamplePDF.pdf"); //Response.End(); }
public void CreatePdf(int id) { var userList = db.video_usuarios.FirstOrDefault(a => a.ncodusua == id); string path = Server.MapPath("PDF"); // var doc = new Document(PageSize.A4, 50, 50, 70, 50); //var doc = new Document(new Rectangle(288f, 144f), 50, 50, 70, 50); var doc = new Document(PageSize.A4, 50, 50, 110, 50); //PdfWriter.GetInstance(doc, new FileStream("D:/VK/SecureDriving/SecureDriving/PDF/" + "/"+ id +".pdf", FileMode.Create)); PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("/PDF/" + "/" + id + ".pdf"), FileMode.Create)); // ...initialize 'doc'... // Set the page size doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); doc.Open(); iTextSharp.text.Image myImg = iTextSharp.text.Image.GetInstance(Server.MapPath("/img/PdfLogo1.jpg")); myImg.Alignment = Element.ALIGN_CENTER; myImg.ScaleToFit(900, 900); doc.Add(myImg); PdfPTable table = new PdfPTable(4); table.WidthPercentage = 100; table.DefaultCell.Border = Rectangle.TOP_BORDER; table.AddCell("Name:"); table.AddCell(userList.vfullname); table.AddCell("DL#:"); table.AddCell("346dh475fhg47"); PdfPCell cellBlankRow = new PdfPCell(new Phrase(" ")); cellBlankRow.Colspan = 2; cellBlankRow.Border = Rectangle.NO_BORDER; cellBlankRow.HorizontalAlignment = 2; table.AddCell(cellBlankRow); table.AddCell(""); table.AddCell(""); table.AddCell("Address:"); table.AddCell("dsfghjfdgjdghd"); table.AddCell("Course Complition Date:"); string date = Convert.ToString(DateTime.Now.ToShortDateString()); table.AddCell(date); PdfPCell cellBlankRows = new PdfPCell(new Phrase(" ")); cellBlankRows.Colspan = 2; cellBlankRows.Border = Rectangle.NO_BORDER; table.AddCell(cellBlankRows); table.AddCell(""); table.AddCell(""); table.AddCell("City State Zip:"); table.AddCell("Newyork"); table.AddCell("Instructor Signature:"); table.AddCell("fghfghgf"); //myImg.Alignment = Element.ALIGN_LEFT; //doc.Add(table); // String htmlText = "<font " + //" color=\"#0000FF\"><b><i>Title One</i></b></font><font " + //" color=\"black\"><br><br>Some text here<br><br><br><font " + //" color=\"#0000FF\"><b><i>Another title here " + //" </i></b></font><font " + //" color=\"black\"><br><br>Text1<br>Text2<br><OL><LI><DIV Style='color:green'>Pham Duy Hoa</DIV></LI><LI>how are u</LI></OL><br/>" + //"<table border='1'><tr><td style='color:red;text-align:right;width:20%'>123456</td><td style='color:green;width:60%'>78910</td><td style='color:red;width:20%'>ASFAFA</td></tr><tr><td style='color:red;text-align:right'>123456</td><td style='color:green;width:60%'>78910</td><td style='color:red;width:20%'>DAFSDGAFW</td></tr></table><br/>" + //"<div><ol><li>123456</li><li>123456</li><li>123456</li><li>123456</li></ol></div>"; string htmlText = " <table width='880' style='border-spacing:0px;border:1px' class='contact'>" + //"<tr> " + //"<td colspan='2'>___________________________________________________________</td>" + //"<td colspan='2'>___________________________________________________________</td>" + //"</tr>" + "<tr class='name'> " + "<td ><h3><b>Name</b></h3></td>" + "<td ><h3><span class='name12'>" + userList.vfullname + "</span></h3></td>" + "<td ><h3><b>DL#</b> </h3></td>" + "<td ><h3> <span class='name12'> " + userList.NJDL_ + "</span></h3></td>" + "</tr>" + "<tr class='name' >" + "<td ><h3><b>Address</b></h3></td>" + "<td><h3><span class='name12'> " + userList.Address + "</span></h3></td>" + "<td><h3><b>Course Completion Date</b> </h3></td>" + "<td><h3> <span class='name12'> " + DateTime.Now.ToShortDateString() + "</span></h3></td>" + "</tr>" + "<tr class='name' >" + "<td ><h3><b>City State Zip</b></h3></td>" + "<td><h3><span class='name12'> " + userList.City + "," + userList.State + "," + userList.Zip + "</span></h3></td>" + "<td><h3><b>Instructor Signature</b> </h3></td>" + "<td><h3> <span class='name12'> </span></h3></td>" + "</tr>" + "</table>"; //String htmlText = " <div class='contact' style='display:inline-table'><div class='name' style='width:40%; float:left;'><h3><b>Name</b> <span class='name12'> Dharmander</span></h3><h3><b>Address</b> <span class='name12'> Dharmander</span></h3> <h3><b>City State Zip</b> <span class='name12'> Dharmander</span></h3></div><div class='name' style='width:40%; float:left;'><h3><b>DL#</b> <span class='name12'> Dharmander</span></h3><h3><b>Course Completion Date</b> <span class='name12'> Dharmander</span></h3></div> </div>"; iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); hw.Parse(new StringReader(htmlText)); //doc.Add(table); doc.Close(); }
protected void Button1_Click(object sender, EventArgs e) { btnCupon.Visible = false; lblPuntos.Text = DropDownList1.SelectedItem.ToString(); lblRubro.Text = ddlProducto.SelectedItem.ToString(); etiquetaDescuento.Visible = true; etiquetaFecha.Visible = true; lblDescuento.Visible = true; lblPuntos.Visible = true; lblRubro.Visible = true; etiquetaCondiciones.Visible = true; lblVencimiento.Visible = true; lblTope.Visible = true; DropDownList1.Visible = false; ddlProducto.Visible = false; if (lblPuntos.Text == "100") { lblDescuento.Text = "5%"; } if (lblPuntos.Text == "500") { lblDescuento.Text = "10%"; } if (lblPuntos.Text == "1000") { lblDescuento.Text = "15%"; } if (lblRubro.Text == "Electrónica") { lblTope.Text = "$300.000."; } if (lblRubro.Text == "Alimentos") { lblTope.Text = "$100.000."; } if (lblRubro.Text == "Línea Blanca") { lblTope.Text = "$150.000."; } if (lblRubro.Text == "Ropa") { lblTope.Text = "$300.000."; } Response.ContentType = "aplication/pdf"; Response.AddHeader("content-disposition", "attachment;filename=cupón_de_descuento.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(generarCupon(), System.Drawing.Imaging.ImageFormat.Jpeg); var logo = iTextSharp.text.Image.GetInstance("ftp://*****:*****@18.222.173.173/logo_MO2.jpg"); var image = iTextSharp.text.Image.GetInstance(pic); this.Panel1.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 10f, 10f, 100f, 10f); iTextSharp.text.html.simpleparser.HTMLWorker htmlParser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc); image.ScaleAbsoluteHeight(100); image.ScaleAbsoluteWidth(200); logo.ScaleAbsoluteHeight(100); logo.ScaleAbsoluteWidth(100); logo.SetAbsolutePosition((iTextSharp.text.PageSize.LETTER.Width - logo.ScaledWidth) / 2, (iTextSharp.text.PageSize.LETTER.Height - logo.ScaledHeight) / (4 / 3)); image.SetAbsolutePosition((iTextSharp.text.PageSize.LETTER.Width - image.ScaledWidth) / 2, (iTextSharp.text.PageSize.LETTER.Height - image.ScaledHeight) / 3); iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); pdfDoc.Add(logo); htmlParser.Parse(sr); pdfDoc.Add(image); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); }
protected void lnkpdfdownload_Click(object sender, EventArgs e) { using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { //To Export all pages gvStudents.AllowPaging = false; this.RefreshGridView(); gvStudents.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 5f, 5f, 5f, 0f); iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc); iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.pdf", String.Concat("StudentsDetails", DateTime.Now.Ticks))); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfDoc); Response.End(); } } }
public static string EmailTodayCallLogs(string Search = "") { NJ_CallLogs obj = new NJ_CallLogs(); var Result = obj.CallLogs(Search); var doc = new Document(PageSize.A4, 50, 50, 5, 5); string PathStart = System.Web.HttpContext.Current.Server.MapPath("/CallLogsPDF"); if (!System.IO.Directory.Exists(PathStart)) { System.IO.Directory.CreateDirectory(PathStart); } string FolderNameByDate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString(); PdfWriter.GetInstance(doc, new System.IO.FileStream(System.Web.HttpContext.Current.Server.MapPath("/CallLogsPDF/" + "/" + "CallLog" + FolderNameByDate + ".pdf"), System.IO.FileMode.Create)); string Filepath = System.Web.HttpContext.Current.Server.MapPath("/CallLogsPDF/" + "/" + "CallLog" + FolderNameByDate + ".pdf"); doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); doc.Open(); string row = ""; foreach (var item in Result) { row = row + @"<tr> <td align='center' style="" font-size: 11px;"" colspan=""2""> " + item.FirstName + @" </td> <td align='center' style="" font-size: 11px;"" colspan=""2""> " + item.LastName + @" </td> <td align='center' style="" font-size: 11px;"" colspan=""2""> " + item.Phone + @" </td> <td align='center' style="" font-size: 11px;"" colspan=""2""> " + item.Notes + @"</td> <td align='center' style="" font-size: 11px;"" colspan=""2""> " + item.AddedName + @"</td> <td align='center' style="" font-size:11px;"" colspan=""2""> " + item.Users + @"</td> </tr>"; } string footer = @"</tbody> </table > <table style='width:100%;'> <thead> </thead> <tbody> </table> </div> </body> <html>"; string htmlText = @"<html><title></title> <p> <table style='width:100%;'> <thead> </thead> <tbody> <tr><td>.</td></tr> <tr> <td style=""font-weight:bold"" colspan=""4""align='center'>Call Log Report of " + DateTime.Now.ToShortDateString() + @"</td> </tr> <tr > <td colspan=""4"">.</td> </tr> </tbody> </table> <head> </head> <body> <p> <div><table border=""1"" style='width:100%;'> <thead> </thead> <tbody> <tr > <td align='center' colspan=""2"" style=""font-weight:bold; font-size: 11px;""> FirstName</td> <td align='center' colspan=""2"" style=""font-weight:bold; font-size: 11px;""> LastName</td> <td align='center' colspan=""2"" style=""font-weight:bold; font-size: 11px;"">Phone</td> <td align='center' colspan=""2"" style=""font-weight:bold; font-size:11px;"">Notes</td> <td align='center' colspan=""2"" style=""font-weight:bold; font-size: 11px;"">AddedBy</td> <td align='center' colspan=""2"" style=""font-weight:bold; font-size: 11px;"">Mail Sent To</td> </tr>" + row + footer; iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); hw.Parse(new System.IO.StringReader(htmlText)); doc.Close(); CallLogs objCalllog = new CallLogs(); string Emailresult = objCalllog.SendCalllogsEmail(Filepath); // string Emailresult = objCalllog.SendEmail(Filepath); return(Emailresult); }
private void ExportToPDF() { JobTypeGraphReport(); string fileName = "QuickJobSummary_Pdf_" + DateTime.Now.ToShortDateString(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName + ".pdf")); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); //gridViewReport.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A3, 10f, 10f, 100f, 0f); iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc); iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); using (MemoryStream stream = new MemoryStream()) { ChartPrint.SaveImage(stream, ChartImageFormat.Png); iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer()); chartImage.ScalePercent(75f); pdfDoc.Add(chartImage); } using (MemoryStream stream = new MemoryStream()) { ChartCopy.SaveImage(stream, ChartImageFormat.Png); iTextSharp.text.Image chartImageCopy = iTextSharp.text.Image.GetInstance(stream.GetBuffer()); chartImageCopy.ScalePercent(75f); pdfDoc.Add(chartImageCopy); } using (MemoryStream stream = new MemoryStream()) { ChartScan.SaveImage(stream, ChartImageFormat.Png); iTextSharp.text.Image chartImageScan = iTextSharp.text.Image.GetInstance(stream.GetBuffer()); chartImageScan.ScalePercent(75f); pdfDoc.Add(chartImageScan); } pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); //Response.ClearContent(); //Response.Buffer = true; //Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Panel.xls")); //Response.ContentType = "application / vnd.ms - excel"; //StringWriter objSW = new StringWriter(); //HtmlTextWriter objTW = new HtmlTextWriter(objSW); //gridViewReport.RenderControl(objTW); //Response.Write(objSW); //Response.End(); }
private void treamentReceipt() { DataTable dt = new DataTable(); //select * from treatement where pid=@pid and Dateofconsultancy=@dt dt = Operation.GetDataTable("select * from treatement where Pid ='" + patientCode + "' and DateOfConsultancy = #" + dtpDateOfConsult.Value + "#"); if (dt.Rows.Count > 0) { var dateGroup = dt.AsEnumerable().GroupBy(x => Convert.ToString(x["chiefComplainName"])).Select(x => new dateGroupingTreatement() { chiefComplainName = x.Key, rows = x.ToList() }); //Create a byte array that will eventually hold our final PDF Byte[] bytes; //Boilerplate iTextSharp setup here //Create a stream that we can write to, in this case a MemoryStream using (var ms = new MemoryStream()) { //Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF using (var doc = new Document(PageSize.A4, 10f, 10f, 10f, 10f)) { //Create a writer that's bound to our PDF abstraction and our stream using (var writer = PdfWriter.GetInstance(doc, ms)) { //Open the document for writing doc.Open(); foreach (var grouprecord in dateGroup) { string tablestringCart = ""; //Our sample HTML and CSS var receiptHtml = File.ReadAllText(Application.StartupPath + "\\Treament.html"); receiptHtml = receiptHtml.Replace("{{PtName}}", patientName); receiptHtml = receiptHtml.Replace("{{Pid}}", Convert.ToString(patientCode)); receiptHtml = receiptHtml.Replace("{{Complain}}", lstChiefComplain.Items.Count > 0 ? Convert.ToString(lstChiefComplain.Items[0]) : ""); receiptHtml = receiptHtml.Replace("{{BP}}", Convert.ToString(txtBp.Text)); receiptHtml = receiptHtml.Replace("{{ConsultDate}}", Convert.ToString(dtpDateOfConsult.Value.ToShortDateString())); receiptHtml = receiptHtml.Replace("{{Age}}", Convert.ToString(grouprecord.rows[0]["age"])); receiptHtml = receiptHtml.Replace("{{Sex}}", Convert.ToString(grouprecord.rows[0]["sex"])); receiptHtml = receiptHtml.Replace("{{FollowupDate}}", Convert.ToString(dtpFollowupDate.Value.ToShortDateString())); receiptHtml = receiptHtml.Replace("{{RS}}", Convert.ToString(grouprecord.rows[0]["RS"])); receiptHtml = receiptHtml.Replace("{{AS}}", Convert.ToString(grouprecord.rows[0]["AS1"])); receiptHtml = receiptHtml.Replace("{{Pulse}}", Convert.ToString(grouprecord.rows[0]["Pulse"])); receiptHtml = receiptHtml.Replace("{{Temp}}", Convert.ToString(grouprecord.rows[0]["Temp"])); receiptHtml = receiptHtml.Replace("{{Cvs}}", Convert.ToString(grouprecord.rows[0]["CVS"])); receiptHtml = receiptHtml.Replace("{{Cns}}", Convert.ToString(grouprecord.rows[0]["CNS"])); tablestringCart = tablestringCart + "<table width='100%'>"; //for (int i = 0; i < dt.Rows.Count; i++) //{ foreach (var record in grouprecord.rows) { string rx = Convert.ToString(record["Rx"]); string medicineName = Convert.ToString(record["Name"]); string qty = Convert.ToString(record["Qty"]); string morning = Convert.ToString(record["MorningDose"]); string noon = Convert.ToString(record["NoonDose"]); string evening = Convert.ToString(record["EveningDose"]); tablestringCart = tablestringCart + "<tr>" + "<td align='center' width='25%'>" + rx + " :</td>" + "<td align='left' width='30%'>" + medicineName + "</td><td align='center' width='45%'>( " + qty + " )</td>" + "</tr>" + "<tr><td align='center' width='25%'></td><td align='left' width='50%'>" + morning + " ------- " + noon + " ------- " + evening + "</td><td align='center' width='25%'></td></tr>"; } tablestringCart = tablestringCart + "</table>"; receiptHtml = receiptHtml.Replace("{{MedicineDetails}}", tablestringCart); //Create a new HTMLWorker bound to our document using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc)) { //HTMLWorker doesn't read a string directly but instead needs a TextReader (which StringReader subclasses) using (var sr = new StringReader(receiptHtml)) { //Parse the HTML htmlWorker.Parse(sr); } } } doc.Close(); } } //After all of the PDF "stuff" above is done and closed but **before** we //close the MemoryStream, grab all of the active bytes from the stream bytes = ms.ToArray(); } //Now we just need to do something with those bytes. //Here I'm writing them to disk but if you were in ASP.Net you might Response.BinaryWrite() them. //You could also write the bytes to a database in a varbinary() column (but please don't) or you //could pass them to another function for further PDF processing. var pdfFile = Application.StartupPath + "\\" + "Plain_" + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond + ".pdf"; File.WriteAllBytes(pdfFile, bytes); System.Diagnostics.Process.Start(pdfFile); } }
public IHttpActionResult PostPDF(User user) { Byte[] bytes; using (var ms = new MemoryStream()) { //Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF using (var doc = new Document()) { //Create a writer that's bound to our PDF abstraction and our stream using (var writer = PdfWriter.GetInstance(doc, ms)) { //Open the document for writing doc.Open(); //Our sample HTML and CSS var content = user.Objectives; var css = @".test{font-size:500%; font-family:'Times New Roman'; background-color: black;}"; /************************************************** * Example #1 * * * * Use the built-in HTMLWorker to parse the HTML. * * Only inline CSS is supported. * * ************************************************/ //Create a new HTMLWorker bound to our document using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc)) { //HTMLWorker doesn't read a string directly but instead needs a TextReader (which StringReader subclasses) using (var sr = new StringReader(content)) { //Parse the HTML htmlWorker.Parse(sr); } } /************************************************** * Example #2 * * * * Use the XMLWorker to parse the HTML. * * Only inline CSS and absolutely linked * * CSS is supported * * ************************************************/ //XMLWorker also reads from a TextReader and not directly from a string using (var srHtml = new StringReader(content)) { //Parse the HTML iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, srHtml); } /************************************************** * Example #3 * * * * Use the XMLWorker to parse HTML and CSS * * ************************************************/ //In order to read CSS as a string we need to switch to a different constructor //that takes Streams instead of TextReaders. //Below we convert the strings into UTF8 byte array and wrap those in MemoryStreams using (var msCss = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(css))) { using (var msHtml = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(content))) { //Parse the HTML iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, msHtml, msCss); } } doc.Close(); } } //After all of the PDF "stuff" above is done and closed but **before** we //close the MemoryStream, grab all of the active bytes from the stream bytes = ms.ToArray(); } var pathToSave = AppDomain.CurrentDomain.BaseDirectory + @"ResumeList/temporary/" + user.FirstName.ToLower() + ".pdf"; System.IO.File.WriteAllBytes(pathToSave, bytes); return(Ok()); }
protected void Page_Load(object sender, EventArgs e) { try { string id = Request.QueryString["id"].ToString();//1.ToString();// Controller_Cotizador controlpre = new Controller_Cotizador(); Cotizador p = controlpre.BuscarPresupuestoxID(Convert.ToInt32(id)); string Tapas = ""; string PapelTapas = ""; string Barniz = ""; switch (p.PaginasTap) { case 0: Tapas = "******"; PapelTapas = "******"; break; default: Tapas = p.PaginasTap + " páginas impresas a 4/4 colores proceso</td>"; PapelTapas = p.PapelTap.Replace("Couché", "Couché Opaco") + " de " + p.GramajeTapas + " grs. Certificado PEFC</td>"; if (p.BarnizAcuosoTap != "No") { Barniz = "<tr><td class='style1'><div style='font-weight: bold;' align='right'>Terminación Tapa:</div></td><td colspan='2' class='style1'>Barniz Acuoso Parejo en el " + p.BarnizAcuosoTap + ".</td></tr>"; } break; } p.Empresa = "GRUPO COPESA"; //Falta Los barniz Acuosos en Todo string formatoExt = ""; string[] str = p.Formato.Replace(",", ".").Split('x'); Double fextendAncho = Convert.ToDouble(str[0].Trim()) * 10.0; Double fextendLargo = Convert.ToDouble(str[1].Trim()) * 10.0; string Formato = fextendAncho.ToString() + " x " + fextendLargo; formatoExt = (Convert.ToDouble(fextendAncho) * 2).ToString() + " x " + fextendLargo; string encuadernacion = p.Encuadernacion; if (encuadernacion == "Hotmelt") { encuadernacion = "Entapado hotmelt"; } else if (encuadernacion == "Corchete") { encuadernacion = "Dos corchetes al Lomo"; } else { encuadernacion = "No Considera Encuadernación"; } // PPTO_Tirajes tiraje1 = p.Tiraje1; string TirajeTotales = ""; // string TextoCantidad = ""; // string TextoTotalNeto = ""; TirajeTotales = "<tr>" + "<td style='100px'></td>" + "<td>" + "<div style='font-weight: bold;' align='right'>Cantidad de Ejemplares:</div>" + "</td>" + "<td>" + Convert.ToInt32(p.Tiraje).ToString("N0").Replace(",", ".") + "</td>" + "<td style='width: 1%;'>" + "<div align='right'>" + "<a style='font-weight: bold;'>" + "Total Neto:" + "</a> $ " + Convert.ToInt32(p.TotalNeto).ToString("N0").Replace(",", ".") + "</div>" + "</td>" + "</tr>" + //Inicio mini tabla de detalle "<tr><td style='100px'></td>" + "<td>" + "</td>" + "<td>" + "</td>" + "<td style='width: 1%;'>" + "<div align='right'>" + "<table><tr>" + "<td><span style='font-weight: bold;' align='center'>C.F.</span></td>" + "<td><span style='font-weight: bold;' align='center'>C.V.</span></td>" + "</div></td></tr></table>" + "</td></tr>" + "<tr><td style='100px'></td>" + "<td>" + "</td>" + "<td>" + "<span style='font-weight: bold;' align='right'>Papel:</span>" + "</td>" + "<td style='width: 1%;'>" + "<div align='right'>" + "<table><tr>" + "<td>" + Convert.ToInt32(p.Tiraje).ToString("N0").Replace(",", ".") + "</td>" + "<td>" + Convert.ToInt32(p.TotalNeto).ToString("N0").Replace(",", ".") + "</td>" + "</div></td></tr></table>" + "</td></tr>" + "<tr><td style='100px'></td>" + "<td>" + "</td>" + "<td>" + "<span style='font-weight: bold;' align='right'>Impresión:</span>" + "</td>" + "<td style='width: 1%;'>" + "<div align='right'>" + "<table><tr>" + "<td>" + Convert.ToInt32(p.Tiraje).ToString("N0").Replace(",", ".") + "</td>" + "<td>" + Convert.ToInt32(p.TotalNeto).ToString("N0").Replace(",", ".") + "</td>" + "</div></td></tr></table>" + "</td></tr>" + "<tr><td style='100px'></td>" + "<td>" + "</td>" + "<td>" + "<span style='font-weight: bold;' align='right'>Encuadernación:</span>" + "</td>" + "<td style='width: 1%;'>" + "<div align='right'>" + "<table><tr>" + "<td>" + Convert.ToInt32(p.Tiraje).ToString("N0").Replace(",", ".") + "</td>" + "<td>" + Convert.ToInt32(p.TotalNeto).ToString("N0").Replace(",", ".") + "</td>" + "</div></td></tr></table>" + "</td></tr>" + "<tr><td style='100px'></td>" + "<td>" + "</td>" + "<td>" + "<span style='font-weight: bold;' align='right'>Terminación:</span>" + "</td>" + "<td style='width: 1%;'>" + "<div align='right'>" + "<table><tr>" + "<td>" + Convert.ToInt32(p.Tiraje).ToString("N0").Replace(",", ".") + "</td>" + "<td>" + Convert.ToInt32(p.TotalNeto).ToString("N0").Replace(",", ".") + "</td>" + "</div></td></tr></table>" + "</td></tr>" + "<tr><td style='100px'></td>" + "<td>" + "</td>" + "<td>" + "<span style='font-weight: bold;' align='right'>Manufactura:</span>" + "</td>" + "<td style='width: 1%;'>" + "<div align='right'>" + "<table><tr>" + "<td>" + Convert.ToInt32(p.Tiraje).ToString("N0").Replace(",", ".") + "</td>" + "<td>" + Convert.ToInt32(p.TotalNeto).ToString("N0").Replace(",", ".") + "</td>" + "</div></td></tr></table>" + "</td></tr>"; string contenido = "<table style='width: 100%;height:100%;' border='1'>" + "<tr><td>" + "<table style='width: 100%;' border='0'>" + "<tr><td>" + "<img " + //height='50px' " alt='Logo AImpresores' src='http://cencosud.aimpresores.cl/Estructura/Image/índice.jpg'" + " />" + "<div style='font-size: 8px;'>" + "Av. Gladys Marín Millie 6920, Estación Central, Santiago de Chile" + "<br />" + "Teléfono: (56 2) 2440 5700 / Fax: " + p.PersonalComercial.Fax + "<br />[email protected]" + "</div>" + "</td>" + "<td align='right'>" + "<br /><br /><br /><br />" + "<div style='font-weight: bold;' align='center'>PRESUPUESTO " + p.ID_Presupuesto.ToString() + "</div>" + "</td></tr></table></td></tr></table>" + "<table border='1'><tr>" + "<td align='center' style='vertical-align:center'>" + "<div style='font-weight: bold; font-size: 8px; font-style: italic;'>" + "De acuerdo a lo solicitado por ustedes, remitimos el siguiente presupuesto:</div>" + "</td></tr></table>" + "<div style='font-size: 9px;'>" + "<table style='width: 100%;'>" + "<tr><td>" + "<div style='font-weight: bold;' align='right'>" + "Empresa:</div></td><td>" + p.Empresa.ToUpper() + "</td><td style='width: 1%;'>" + "<a style='font-weight: bold;'>Fecha: </a>" + p.FechaCreacion.ToString("dd/MM/yyy") + "</td></tr><tr><td>" + "<div style='font-weight: bold;' align='right'>" + "Atención a:</div></td><td>" + p.Usuario_Creador + "</td><td style='width: 1%;'></td></tr>" + "<tr>" + "<td>" + "<div style='font-weight: bold;' align='right'>" + "Ejecutivo Directo:</div>" + "</td>" + "<td>" + p.PersonalComercial.NombreCompleto + "</td>" + "<td style='width: 1%;'>" + "</td>" + "</tr>" + "<tr><td>" + "<div style='font-weight: bold;' align='right'>" + "Teléfono:</div>" + "</td>" + "<td>" + p.PersonalComercial.Telefono + " / " + p.PersonalComercial.Celular + "</td>" + "<td style='width: 1%;'>" + "</td>" + "</tr>" + "<tr>" + "<td colspan='3' align='center'>" + "___________________________________________________________________________________________" + "</td>" + "</tr>" + "<tr>" + "<td>" + "<div style='font-weight: bold;' align='right'>" + "Producto:</div>" + "</td>" + "<td>" + "<a style='font-weight: bold;'>" + p.NombrePresupuesto.ToUpper() + "</a>" + "</td>" + "<td style='width: 1%;'>" + "</td>" + "</tr>" + "<tr>" + "<td>" + "<div style='font-weight: bold;' align='right'>" + "Formato Cerrado:</div>" + "</td>" + "<td>" + Formato + " (mm.)" + "</td>" + "<td style='width: 1%;'>" + "</td>" + "</tr>" + "<tr>" + "<td>" + "<div style='font-weight: bold;' align='right'>" + "Formato Extendido:</div>" + "</td>" + "<td>" + formatoExt + " (mm.)" + "</td>" + "<td style='width: 1%;'>" + "</td>" + "</tr>" + "<tr>" + "<td>" + "<div style='font-weight: bold;' align='right'>" + "</div>" + "</td>" + "<td>" + "</td>" + "<td style='width: 1%;'>" + "</td>" + "</tr>" + "<tr>" + "<td>" + "<div style='font-weight: bold;' align='right'>" + "Extensión:</div>" + "</td>" + "<td colspan='2'>" + p.PaginasInt + " páginas Interiores impresas a 4/4 colores " + "proceso " + "</td>" + "</tr>" + "<tr>" + "<td>" + "<div style='font-weight: bold;' align='right'>" + "Papel:</div>" + "</td>" + "<td colspan='2'>" + p.PapelInterior.Replace("Couché", "Couché Opaco") + " de " + p.GramajeInterior + " grs. Certificado PEFC" + "</td>" + "</tr>" + "<tr>" + "<td>" + "<div style='font-weight: bold;' align='right'>" + "Tapa:</div>" + "</td>" + "<td colspan='2'>" + Tapas + "</tr>" + "<tr>" + "<td class='style1'>" + "<div style='font-weight: bold;' align='right'>" + "Papel:</div>" + "</td>" + "<td colspan='2' class='style1'>" + PapelTapas + "</tr>" + Barniz + "<tr>" + "<td>" + "<div style='font-weight: bold;' align='right'>" + "Encuadernación:</div>" + "</td>" + "<td>" + encuadernacion + "</td>" + "<td>" + "</td>" + "</tr>" + "</table>" + "<table style='width: 100%;' align='center'>" + TirajeTotales + "</table>" + "</div>" + "<br />" + "<br />" + "<br />" + "<br />" + "<table style='width: 100%;' align='center'>" + "<tr>" + "<td align='center'>" + "__________________________" + "<br />" + "<a style='font-weight: bold; font-size: 9px;'>ACEPTADO CLIENTE</a>" + "</td>" + "<td align='center'>" + "__________________________" + "<br />" + "<a style='font-weight: bold; font-size: 9px;'>A IMPRESORES S.A.</a>" + "</td>" + "</tr>" + "</table>" + "<br />" + "<a style='font-weight: bold; font-size: 9px;'>Precios no Incluyen IVA</a>" + "" + "<div style='font-size: 8px;' border='1' align='center'>" + "<table style='width: 100%; font-size: 8px;' align='center' border='1'>" + "<tr>" + "<td align='center'>" + "La Validez de este presupuesto es de 30 días, vencido este plazo el presupuesto " + "queda nulo " + "<br />" + "Se acepta una variación de la cantidad solicitada en un rango +/- 5% la cual será " + "facturada al valor del ejemplar adicional" + "<br />" + "Este Presupuesto se mantiene proforma hasta el cierre completo del material proporcionado " + "por el cliente" + "<br />" + "Despacho del volumen total solo a un lugar físico dentro de la Región Metropolitana" + "<br />" + "Si este presupuesto es acertado,se deberá confirmar disponibilidad de máquina y " + "papeles con su ejecutivo directo." + "<br />" + "Tipo de cambio vigente : UF " + p.ValorUFActual.Valor.ToString("N2") + " informado por el Banco Central de Chile." + "</td>" + "</table>"; //" </div>" + // "<a style='font-weight: bold;font-size:9px;'> En caso de recepción Incompleta o ilegible, favor comunicarse al 56 (2) 2440 5740</a>"; Document document = new Document(PageSize.LETTER, 15f, 15f, 20f, 10f); PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "PDF\\" + id + ".- " + p.NombrePresupuesto + ".pdf", FileMode.Create)); document.Open(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); hw.Parse(new StringReader(contenido)); document.Close(); //if (EnviarCorreo(id + ".- " + p.NombrePresupuesto, ""))//falta el correo de Comercial //{ Response.Redirect("../../PDF/" + id + ".- " + p.NombrePresupuesto + ".pdf"); //} //Response.Clear(); //Response.ContentType = "application/pdf"; //Response.AddHeader("Content-Disposition", "attachment; filename=MySamplePDF"); //Response.WriteFile(Request.PhysicalApplicationPath + "\\MySamplePDF.pdf"); //Response.End(); } catch (Exception a) { string popupScript = "<script language='JavaScript'>alert('A ocurrido el siguiente error:" + a.Message + "');</script>"; Page.RegisterStartupScript("PopupScript", popupScript); } }
public void CreateStudentInfoPDF(int id) { var userList = db.video_usuarios.FirstOrDefault(a => a.ncodusua == id); var doc = new Document(PageSize.A4, 50, 50, 5, 5); //PdfWriter.GetInstance(doc, new FileStream("D:/VK/SecureDriving/SecureDriving/PDF/" + "/"+ id +".pdf", FileMode.Create)); PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("/NewPDF/" + "/" + id + ".pdf"), FileMode.Create)); // Set the page size doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); doc.Open(); iTextSharp.text.Image myImg = iTextSharp.text.Image.GetInstance(Server.MapPath("/img/PdfDefensive.jpg")); myImg.Alignment = Element.ALIGN_LEFT; myImg.ScaleToFit(800, 800); doc.Add(myImg); string htmlText = @"<html><title></title> <head> </head> <body> <p> <div><table border=""1"" style='width:100%;'> <thead> </thead> <tbody> <tr > <td align='center' colspan=""2""> Name</td> <td align='center' colspan=""2""> Complete Address</td> <td align='center' colspan=""2"" >NJ Drivers License No</td> <td align='center'>Sex</td> <td align='center'>Date Of Birth</td> <td align='center'>Eye Color</td> </tr> <tr> <td align='center' colspan=""2""> " + userList.vfullname + @" </td> <td align='center'colspan=""2""> " + userList.Address + "," + userList.State + "," + userList.City + "," + userList.Zip + @" </td> <td align='center' colspan=""2""> " + userList.NJDL_ + @" </td> <td align='center'> " + userList.Gender + @"</td> <td align='center'> " + Convert.ToDateTime(userList.DOB).ToShortDateString() + @" </td> <td align='center'> " + userList.EyeColor + @" </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan=""2""> </td> <td colspan=""2""> </td> <td colspan=""2""> </td> <td> </td> <td> </td> <td> </td> </tr> </tbody> </table > </p> <p>Numbers of Student Completing __________________________________</p></n> <table style='width:100%;'> <thead> </thead> <tbody> <tr > <td colspan=""4"">Mail report Plus $8 student to : USA Training, P.O Box 26309, Austin,TX 78766-0309 </td> </tr> </tbody> </table> </div> </body> <html> "; iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); hw.Parse(new StringReader(htmlText)); doc.Close(); }
private void VisualizarReporte() { FileStream fs = new FileStream(Environment.CurrentDirectory + @"\reportediario.pdf", FileMode.Create, FileAccess.Write, FileShare.None); iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(PageSize.A4.Rotate()); Document doc = new Document(rec); PdfWriter writer = PdfWriter.GetInstance(doc, fs); string HTML = "<table width='100%' border='0'><tr align='center' color = '#424242'>" + "<td><h3>Presentes: " + this.nudPresentes.Value.ToString() + "</h3></td>" + "<td><h3>Ausentes: " + this.nudAusentes.Value.ToString() + "</h3></td>" + "<td><h3>Tarde: " + this.nudTarde.Value.ToString() + "</h3></td>" + "</tr></table>"; HTML += "<table width='100%' border='1'><tr color = 'white' bgcolor='black'><td><h2><div align ='center'>REPORTE DIARIO DE AGENTES DEL " + this.dateTimePicker1.Value.ToShortDateString() + "</div></h2></td></tr>" + "</table><table width='100%' border='1' color='black'>"; string header = " <tr align = 'center' color ='white' bgcolor ='#424242'> <td >Legajo</td>" + " <td>Apellido</td>" + " <td>Nombre</td> " + " <td>Tardanza</td> " + " <td>J.Incomp.</td> " + " <td>Ausente</td> " + " <td>Lactancia</td> " + " <td>Comision</td> " + " <td>Novedad</td> " + " <td>Reloj</td> " + " <td>OK</td> " + "</tr>"; HTML += header; foreach (var linea in lista) { HTML += " <tr align = 'center' ><td>" + linea.Legajo + "</td>" + " <td>" + linea.Apellido + "</td>" + " <td>" + linea.Nombre + "</td>" + " <td>" + linea.Tarde + " </td> " + " <td>" + linea.JornadaIncompleta + " </td> " + " <td>" + linea.Ausente + " </td> " + " <td>" + linea.Lact + " </td> " + " <td>" + linea.Comision + " </td> " + " <td>" + linea.Nov + " </td> " + " <td>" + linea.Reloj + " </td> " + " <td>" + linea.EstaOK + " </td> " + "</tr>"; } HTML += "</table>"; var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); doc.Open(); htmlWorker.Parse(new StringReader(HTML)); doc.Close(); // ejecutar archivo pdf System.Diagnostics.Process proceso = new System.Diagnostics.Process(); proceso.StartInfo.FileName = "reportediario.pdf"; proceso.StartInfo.WorkingDirectory = Environment.CurrentDirectory; proceso.Start(); }