public void addbody() { DateTime date = DateTime.Now; string Date = Convert.ToString(date); foreach (Student s in SelectedStudents) { iTextSharp.text.Font f = FontFactory.GetFont("Tahoma", 7f, 1); PdfPCell pdfcl = new PdfPCell(new Phrase(s.ARN, f)); pdfcl.BorderColor = BaseColor.DARK_GRAY; pdfcl.ExtraParagraphSpace = 0; PdfPCell pdfcl1 = new PdfPCell(new Phrase(s.Name, f)); pdfcl.BorderColor = BaseColor.DARK_GRAY; pdfcl.ExtraParagraphSpace = 0; PdfPCell pdfcl2 = new PdfPCell(new Phrase(s.aggregate.ToString(), f)); pdfcl.BorderColor = BaseColor.DARK_GRAY; pdfcl.ExtraParagraphSpace = 0; PdfPCell pdfcl3 = new PdfPCell(new Phrase(s.department, f)); pdfcl.BorderColor = BaseColor.DARK_GRAY; pdfcl.ExtraParagraphSpace = 0; PdfPCell pdfcl4 = new PdfPCell(new Phrase(s.Email, f)); pdfcl.BorderColor = BaseColor.DARK_GRAY; pdfcl.ExtraParagraphSpace = 0; PdfPCell pdfcl5 = new PdfPCell(new Phrase(s.Category, f)); pdfcl.BorderColor = BaseColor.DARK_GRAY; pdfcl.ExtraParagraphSpace = 0; pdfcl.BorderWidth = 1f; pdfcl1.BorderWidth = 1f; pdfcl2.BorderWidth = 1f; pdfcl3.BorderWidth = 1f; pdfcl4.BorderWidth = 1f; pdfcl5.BorderWidth = 1f; pdfcl.BorderColor = BaseColor.GRAY; pdfcl2.BorderColor = BaseColor.GRAY; pdfcl1.BorderColor = BaseColor.GRAY; pdfcl3.BorderColor = BaseColor.GRAY; pdfcl4.BorderColor = BaseColor.GRAY; pdfcl5.BorderColor = BaseColor.GRAY; pdft.AddCell(pdfcl); pdft.AddCell(pdfcl1); pdft.AddCell(pdfcl2); pdft.AddCell(pdfcl3); pdft.AddCell(pdfcl4); pdft.AddCell(pdfcl5); } iTextSharp.text.Font ff = FontFactory.GetFont("Arial", 7f); ff.IsBold(); iTextSharp.text.Font fff = FontFactory.GetFont("Arial", 7f); fff.SetStyle(4); PdfPCell pdfcl11 = new PdfPCell(new Phrase("@ all copy Rights reserved, www.uet.edu.pk")); pdfcl11.Colspan = 3; pdfcl11.Border = 0; PdfPCell pdfcl12 = new PdfPCell(new Phrase(Date)); pdfcl12.Colspan = 3; pdfcl12.Border = 0; pdfcl11.PaddingTop = 50f; pdfcl12.PaddingTop = 50f; pdft.AddCell(pdfcl11); pdft.AddCell(pdfcl12); }
public void addheader() { iTextSharp.text.Font f1 = FontFactory.GetFont("Arial", 13f, 1); f1.Color = BaseColor.BLUE; PdfPCell pdfcl = new PdfPCell(new Phrase("Merit List ", f1)); pdfcl.Colspan = 1; f1.IsItalic(); f1.IsBold(); //f1.SetStyle(4); pdfcl.PaddingTop = 10f; pdfcl.HorizontalAlignment = Element.ALIGN_CENTER; pdfcl.BackgroundColor = BaseColor.WHITE; pdfcl.VerticalAlignment = Element.ALIGN_LEFT; pdfcl.Border = 3; pdfcl.BorderColorBottom = BaseColor.BLACK; pdfcl.BorderColorTop = BaseColor.WHITE; pdfcl.BorderColorLeft = BaseColor.WHITE; pdfcl.BorderColorRight = BaseColor.WHITE; pdfcl.ExtraParagraphSpace = 0; pdft.AddCell(pdfcl); iTextSharp.text.Font f = FontFactory.GetFont("Arial", 15f, 1); f.IsBold(); f.Color = BaseColor.DARK_GRAY; PdfPCell pdfcl1 = new PdfPCell(new Phrase("University of Engg & Technology, Lahore ", f)); pdfcl1.FixedHeight = 30f; pdfcl1.PaddingTop = 30f; pdfcl1.Colspan = 3; pdfcl1.HorizontalAlignment = Element.ALIGN_CENTER; pdfcl1.BackgroundColor = BaseColor.WHITE; pdfcl1.Border = 0; pdfcl1.ExtraParagraphSpace = 0; pdft.AddCell(pdfcl1); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance("G:/Visual Studio Pros/Admission_Office/Admission_Office/Photos/UET_Lahore_Logo.png"); PdfPCell pdfcl7 = new PdfPCell(img); pdfcl7.Colspan = 2; pdfcl7.BorderColor = BaseColor.WHITE; pdfcl7.Border = 0; pdfcl7.PaddingBottom = 5f; pdft.AddCell(pdfcl7); iTextSharp.text.Font f2 = FontFactory.GetFont("calibri", 10f, 1); f2.SetColor(66, 134, 244); PdfPCell pdfcl2 = new PdfPCell(new Phrase("ARN number", f2)); PdfPCell pdfcl3 = new PdfPCell(new Phrase("Name of Student", f2)); PdfPCell pdfcl6 = new PdfPCell(new Phrase("Email", f2)); PdfPCell pdfcl4 = new PdfPCell(new Phrase("Aggregate", f2)); PdfPCell pdfcl5 = new PdfPCell(new Phrase("Dept of Admission", f2)); PdfPCell pdfcl9 = new PdfPCell(new Phrase("Category", f2)); pdfcl2.BackgroundColor = BaseColor.LIGHT_GRAY; pdfcl2.BorderWidth = 1f; pdfcl3.BorderWidth = 1f; pdfcl4.BorderWidth = 1f; pdfcl5.BorderWidth = 1f; pdfcl6.BorderWidth = 1f; pdfcl9.BorderWidth = 1f; pdfcl2.BorderColor = BaseColor.GRAY; pdfcl3.BorderColor = BaseColor.GRAY; pdfcl4.BorderColor = BaseColor.GRAY; pdfcl5.BorderColor = BaseColor.GRAY; pdfcl6.BorderColor = BaseColor.GRAY; pdfcl9.BorderColor = BaseColor.GRAY; pdfcl2.Left = 10f; pdfcl3.Left = 10f; pdfcl6.Left = 5f; pdfcl3.BackgroundColor = BaseColor.LIGHT_GRAY; pdfcl4.BackgroundColor = BaseColor.LIGHT_GRAY; pdfcl5.BackgroundColor = BaseColor.LIGHT_GRAY; pdfcl6.BackgroundColor = BaseColor.LIGHT_GRAY; pdfcl9.BackgroundColor = BaseColor.LIGHT_GRAY; pdft.AddCell(pdfcl2); pdft.AddCell(pdfcl3); pdft.AddCell(pdfcl4); pdft.AddCell(pdfcl5); pdft.AddCell(pdfcl6); pdft.AddCell(pdfcl9); }
public bool Generate(Cv cv) { Document doc = new Document(PageSize.A4, 7f, 5f, 40f, 0f); try { BaseColor black = new BaseColor(0, 0, 0); BaseColor blue = new BaseColor(0, 0, 255); BaseColor white = new BaseColor(255, 255, 255); string newFilePath = Environment.CurrentDirectory + "\\" + $"CV_{cv.PersonalInfo.FullName}.pdf"; PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(newFilePath, FileMode.Create)); doc.Open(); iTextSharp.text.Font CvHeaderFont = FontFactory.GetFont("Segoe UI", 40, blue); CvHeaderFont.IsBold(); CvHeaderFont.IsUnderlined(); iTextSharp.text.Font mainFont = FontFactory.GetFont("Segoe UI", 22, blue); iTextSharp.text.Font infoFont1 = FontFactory.GetFont("Kalinga", 15, black); iTextSharp.text.Font expHeadFond = FontFactory.GetFont("Calibri (Body)", 15, black); PdfContentByte contentByte = writer.DirectContent; ColumnText ct = new ColumnText(contentByte); doc.Open(); PdfPTable modelInfoTable = new PdfPTable(1); modelInfoTable.DefaultCell.Border = Rectangle.NO_BORDER; modelInfoTable.HorizontalAlignment = Element.ALIGN_CENTER; PdfPCell modelInfoCell1 = new PdfPCell(); modelInfoCell1.PaddingTop = 30f; modelInfoCell1.PaddingBottom = 30f; modelInfoCell1.Border = 0; #region Header Phrase mainPharse = new Phrase(); Chunk infoHeader = new Chunk("CV", CvHeaderFont); mainPharse.Add(infoHeader); mainPharse.Add(new Chunk(Environment.NewLine)); #endregion #region Personal Info Phrase mobPhrase = new Phrase(); mobPhrase.Add(Environment.NewLine); Chunk PersonalInfoheader = new Chunk("PERSONAL INFORMATION", mainFont); mobPhrase.Add(PersonalInfoheader); mobPhrase.Add(new Chunk(Environment.NewLine)); mobPhrase.Add(new Chunk(Environment.NewLine)); Chunk mChunk = new Chunk("Full Name - " + cv.PersonalInfo.FullName, infoFont1); mobPhrase.Add(mChunk); mobPhrase.Add(new Chunk(Environment.NewLine)); Chunk infoChunk1 = new Chunk("Profile - " + cv.PersonalInfo.Profile, infoFont1); mobPhrase.Add(infoChunk1); mobPhrase.Add(new Chunk(Environment.NewLine)); Chunk roleChunk1 = new Chunk("Role - " + cv.PersonalInfo.Role, infoFont1); mobPhrase.Add(roleChunk1); mobPhrase.Add(new Chunk(Environment.NewLine)); Chunk infoChunk22 = new Chunk("Age - " + cv.PersonalInfo.Age.ToString(), infoFont1); mobPhrase.Add(infoChunk22); mobPhrase.Add(new Chunk(Environment.NewLine)); modelInfoTable.AddCell(mainPharse); Chunk cmob = new Chunk("Phone - " + cv.PersonalInfo.Phone, infoFont1); mobPhrase.Add(cmob); mobPhrase.Add(new Chunk(Environment.NewLine)); modelInfoCell1.AddElement(mobPhrase); Phrase msgPhrase = new Phrase(); iTextSharp.text.Font msgFont = FontFactory.GetFont("Kalinga", 10, black); Chunk cmsg = new Chunk("EMail - " + cv.PersonalInfo.Email, infoFont1); msgPhrase.Add(cmsg); #endregion #region Experience modelInfoCell1.AddElement(msgPhrase); modelInfoTable.AddCell(modelInfoCell1); PdfPCell cell1 = new PdfPCell() { BorderWidthBottom = 0f, BorderWidthTop = 0f, BorderWidthLeft = 0f, BorderWidthRight = 0f }; cell1.PaddingTop = 30f; cell1.Border = 0; modelInfoTable.AddCell(cell1); PdfPCell cellExp = new PdfPCell() { BorderWidthBottom = 0f, BorderWidthTop = 0f, BorderWidthLeft = 0f, BorderWidthRight = 0f }; cellExp.Border = 0; Phrase ExperiencePhrase = new Phrase(); Chunk ExperienceChunk = new Chunk("EXPERIENCE", mainFont); ExperiencePhrase.Add(ExperienceChunk); ExperiencePhrase.Add(new Chunk(Environment.NewLine, mainFont)); ExperiencePhrase.Add(new Chunk(Environment.NewLine, mainFont)); cellExp.AddElement(ExperiencePhrase); modelInfoTable.AddCell(cellExp); foreach (var item in cv.Experience) { PdfPCell expcell = new PdfPCell() { BorderWidthBottom = 0f, BorderWidthTop = 0f, BorderWidthLeft = 0f, BorderWidthRight = 0f }; expcell.PaddingBottom = 10f; Phrase expPhrase = new Phrase(); StringBuilder expStringBuilder = new StringBuilder(); StringBuilder expStringBuilder1 = new StringBuilder(); expStringBuilder.Append("Title - " + item.Title + Environment.NewLine); expStringBuilder.Append("Company - " + item.Company + Environment.NewLine); expStringBuilder1.Append("From " + item.From.ToShortDateString() + " To " + item.To.ToShortDateString() + Environment.NewLine); Chunk expDetailChunk = new Chunk(expStringBuilder.ToString(), expHeadFond); expPhrase.Add(expDetailChunk); expPhrase.Add(new Chunk(expStringBuilder1.ToString(), infoFont1)); expcell.AddElement(expPhrase); modelInfoTable.AddCell(expcell); } #endregion #region Additional PdfPCell pCellAdditional = new PdfPCell() { BorderWidth = 0f }; pCellAdditional.PaddingTop = 10f; pCellAdditional.PaddingBottom = 10f; Phrase phMain = new Phrase(); Chunk expAdditionalInfo = new Chunk("ADDITIONAL INFO", mainFont); phMain.Add(new Chunk(Environment.NewLine, mainFont)); phMain.Add(expAdditionalInfo); pCellAdditional.AddElement(phMain); modelInfoTable.AddCell(pCellAdditional); if (cv.AdditionalInfo.Length > 600) { PdfPCell pCell1 = new PdfPCell() { BorderWidth = 0f }; PdfPCell pCell2 = new PdfPCell() { BorderWidth = 0f }; Phrase ph1 = new Phrase(); Phrase ph2 = new Phrase(); string experience1 = cv.AdditionalInfo.Substring(0, 599); string experience2 = cv.AdditionalInfo.Substring(599, cv.AdditionalInfo.Length - 600); ph1.Add(new Chunk(experience1, infoFont1)); ph2.Add(new Chunk(experience2, infoFont1)); pCell1.AddElement(ph1); pCell2.AddElement(ph2); modelInfoTable.AddCell(pCell1); modelInfoTable.AddCell(pCell2); } else { PdfPCell pCell1 = new PdfPCell() { BorderWidth = 0f }; Phrase ph1 = new Phrase(); string experience1 = cv.AdditionalInfo; ph1.Add(new Chunk(experience1, infoFont1)); pCell1.AddElement(ph1); modelInfoTable.AddCell(pCell1); } #endregion doc.Add(modelInfoTable); return(true); } catch (Exception exception) { return(false); throw exception; } finally { doc.Close(); } }
public void generarPDF(string NC, string asesor, string secretario, string vocal, string suplente, string nombre) { folder(); Document document = new Document(PageSize.A4, 25, 25, 30, 30); // Indicamos donde vamos a guardar el documento PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"C:\\CartasAsignacion\\" + (NC.ToString()) + ".pdf", FileMode.Create)); //new FileStream(@"C:\Users\Angel\Documents\OficioTitulacion.pdf", FileMode.Create)); //string image = "C:\\Users\\Angel\\Documents\\SharpDevelop Projects\\ProtocoloTitulacion\\ProtocoloTitulacion\\Recursos\\tec laguna.png"; //ResourceManager rm = Resources.ResourceManager; //Bitmap myImage2 = (Bitmap)rm.GetObject("logo_pdf.png"); //string image = myImage2.ToString() ; //Add the meta information document.AddAuthor("ITL Sistem Departament"); document.AddCreator("Sistem Asignacion de Revisores"); document.AddKeywords("PDF"); document.AddTitle("The document title - Asignacion de Comisión Revisora"); //open the document to enable you to wirte to the document document.Open(); #region logo string patimagen = Path.Combine(Application.StartupPath, "..\\..\\Recursos\\logo_pdf.png"); iTextSharp.text.Image myImage = iTextSharp.text.Image.GetInstance(patimagen); //iTextSharp.text.Image myImage = iTextSharp.text.Image.GetInstance(image); myImage.ScaleToFit(400, 233f); myImage.SpacingBefore = 50f; myImage.SpacingAfter = 10f; myImage.Alignment = Element.ALIGN_RIGHT; #endregion #region cabecera //estilos iTextSharp.text.Font title = FontFactory.GetFont("georgia", 20f); Paragraph titulo = new Paragraph("Instituto Tecnológico de la Laguna", title); titulo.Alignment = Element.ALIGN_CENTER; //document.Add(titulo); document.Add(myImage); document.Add(Chunk.NEWLINE); //Indicamos la fecha de sistema string Date = DateTime.Today.Date.ToString(); string aux = ""; for (int i = 0; i < 10; i++) { aux += Date[i].ToString(); } Paragraph fecha = new Paragraph("Torreon,Coah.," + aux); fecha.Alignment = Element.ALIGN_RIGHT; document.Add(fecha); //Fin de la fecha document.Add(Chunk.NEWLINE); Paragraph Asunto = new Paragraph("Asunto: Asignacion de comisión revisora "); Asunto.Alignment = Element.ALIGN_CENTER; document.Add(Asunto); #endregion document.Add(new Paragraph("COORDINADOR(A) DE ")); document.Add(Chunk.NEWLINE); document.Add(new Paragraph("Por medio del presente informo a usted la asignacion de los integrantes de la comision")); document.Add(Chunk.NEWLINE); String texto = "revisora del trabajo de titulacion, del trabajo de titulacion de (la) C." + nombre + " "; document.Add(new Paragraph(texto)); document.Add(Chunk.NEWLINE); document.Add(new Paragraph("cuya opcion es : ")); document.Add(Chunk.NEWLINE); document.Add(new Paragraph("Egresado(a) del instituto Tecnologico de la Laguna, con número de control " + NC + " pasante de la Carrera de Ingenieria en Sistemas")); #region Comision document.Add(Chunk.NEWLINE); string comision = "Presidente(a): " + asesor + "\nSecretario(a): " + secretario + "\nVocal : " + vocal + "\nVocal Suplente : " + suplente; Paragraph textoComision = new Paragraph(comision); textoComision.Alignment = Element.ALIGN_MIDDLE; /*string presidente = "Presidente(a): " + asesor; * document.Add(new Paragraph(presidente)); * string secretariodoc = "Secretario(a): " + secretario; * document.Add(new Paragraph(secretariodoc)); * string vocaldoc = "Vocal: " + vocal; * document.Add(new Paragraph(vocaldoc)); * string suplentedoc = "Vocal Suplente: "+suplente; * document.Add(new Paragraph(suplentedoc));*/ document.Add(textoComision); document.Add(Chunk.NEWLINE); document.Add(new Paragraph("Agradezco su atención al presente y envío un cordial saludo")); document.Add(Chunk.NEWLINE); #endregion iTextSharp.text.Font ateFont = FontFactory.GetFont("georgia", 10); ateFont.IsBold(); Paragraph Ate = new Paragraph("Atentamente", ateFont); Ate.Alignment = Element.ALIGN_CENTER; document.Add(Ate); document.Add(Chunk.NEWLINE); document.Add(Chunk.NEWLINE); document.Add(Chunk.NEWLINE); Paragraph linea = new Paragraph("-------------------------------------------"); linea.Alignment = Element.ALIGN_CENTER; document.Add(linea); document.Add(Chunk.NEWLINE); Paragraph jefatura = new Paragraph("Jefatura del Departamento de Sistemas Computacionales"); jefatura.Alignment = Element.ALIGN_CENTER; document.Add(jefatura); //Close the document document.Close(); //close the writer instance writer.Close(); MessageBox.Show("Oficio creado satisfactoriamente"); }
/// <summary> /// Exporttopdf /// </summary> /// <param name="ds"></param> /// <param name="fileName"></param> /// <returns></returns> private bool ExportToPdf(DataSet ds, string fileName, ExperimentsInfo expInfo) { ///设置导出字体 string FontPath = "C://WINDOWS//Fonts//simsun.ttc,1"; int FontSize = 8; Boolean result = true; //竖排模式,大小为A4,四周边距均为25 Document document = new Document(PageSize.A4, 10, 10, 10, 10); //调用PDF的写入方法流 //注意FileMode-Create表示如果目标文件不存在,则创建,如果已存在,则覆盖。 PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create)); //创建PDF文档中的字体 BaseFont baseFont = BaseFont.CreateFont( FontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); //根据字体路径和字体大小属性创建字体 iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, FontSize); iTextSharp.text.Font fontTitle = new iTextSharp.text.Font(baseFont, 9); iTextSharp.text.Font fontWanTag = new iTextSharp.text.Font(baseFont, 14); fontWanTag.IsBold(); DateTime dTime = DateTime.Now; HeaderFooter footer = new HeaderFooter(new Phrase(dTime.ToString("yyyy/MM/dd HH:mm:ss") + " Page: "), true); footer.Border = Rectangle.NO_BORDER; footer.Alignment = Element.ALIGN_RIGHT; document.Footer = footer; //HeaderFooter Header = new HeaderFooter(new Phrase("WanTag 实验报告"),false); //Header.Border = Rectangle.NO_BORDER; //Header.Alignment = Element.ALIGN_CENTER; //document.Header = Header; //打开目标文档对象 document.Open(); document.Add(new Paragraph("\n")); Paragraph p_WanTag = new Paragraph("WanTag 实验报告", fontWanTag); p_WanTag.Alignment = 1; document.Add(p_WanTag); document.Add(new Paragraph("\n")); Paragraph p_expName = new Paragraph(" 实验名称:" + expInfo.ExperimentName, fontTitle); //p_expName.Alignment = 1; document.Add(p_expName); Paragraph p_expLoginName = new Paragraph(" 操 作 员:" + expInfo.LoginName, fontTitle); //p_expName.Alignment = 1; document.Add(p_expLoginName); Paragraph p_expStartDate = new Paragraph(" 开始时间:" + expInfo.StartTime.ToString("yyyy/MM/dd HH:mm:ss"), fontTitle); //p_expName.Alignment = 1; document.Add(p_expStartDate); Paragraph p_expEndDate = new Paragraph(" 结束时间:" + Convert.ToDateTime(expInfo.EndTime).ToString("yyyy/MM/dd HH:mm:ss"), fontTitle); //p_expName.Alignment = 1; document.Add(p_expEndDate); document.Add(new Paragraph("\n")); for (int k = 0; k < ds.Tables.Count; k++) { if (k > 0) { document.NewPage(); } string tableName = ds.Tables[k].TableName; if (ds.Tables[k].Rows[0]["检测结果"].ToString() == "重新测定" || ds.Tables[k].Rows[1]["检测结果"].ToString() == "重新测定") { tableName += " 质控品结果不符合标准,实验结果无效"; } Paragraph p_Name = new Paragraph(tableName, fontTitle); document.Add(p_Name); document.Add(new Paragraph("\n")); //根据数据表内容创建一个PDF格式的表 PdfPTable table = new PdfPTable(ds.Tables[k].Columns.Count - 1); table.SetTotalWidth(new float[] { 5, 10, 12, 10, 8, 6, 12, 6, 13, 20 }); // 添加表头,每一页都有表头 for (int j = 0; j < ds.Tables[k].Columns.Count - 1; j++) { string cellName = ds.Tables[k].Columns[j].ColumnName; cellName = cellName.Replace("BarCode", "条码").Replace("Position", "孔位"); PdfPCell cell = new PdfPCell(new Phrase(cellName, font)); cell.UseAscender = true; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = new Color(220, 220, 220); table.AddCell(cell); } // 告诉程序这行是表头,这样页数大于1时程序会自动为你加上表头。 table.HeaderRows = 1; //遍历原datatable的数据行 for (int i = 0; i < ds.Tables[k].Rows.Count; i++) { for (int j = 0; j < ds.Tables[k].Columns.Count - 1; j++) { try { PdfPCell cell = new PdfPCell(new Phrase(ds.Tables[k].Rows[i][j].ToString(), font)); System.Drawing.Color Color = System.Drawing.ColorTranslator.FromHtml(ds.Tables[k].Rows[i]["Color"].ToString()); cell.BackgroundColor = new iTextSharp.text.Color(Color); table.AddCell(cell); // table.AddCell(new Phrase(ds.Tables[k].Rows[i][j].ToString(), font)); } catch (Exception e) { result = false; } } } //在目标文档中添加转化后的表数据 document.Add(table); } //关闭目标文件 document.Close(); //关闭写入流 writer.Close(); return(result); }