public AddHeader ( string name, string content ) : bool | ||
name | string | the name of the header |
content | string | the content of the header |
리턴 | bool |
private void btnCreateReport_Click(object sender, EventArgs e) { // _______________________________________________________1_______________________________________________________ // Setting pagetype, margins and encryption iTextSharp.text.Rectangle pageType = iTextSharp.text.PageSize.A4; float marginLeft = 72; float marginRight = 36; float marginTop = 60; float marginBottom = 50; String reportName = "Test.pdf"; Document report = new Document(pageType, marginLeft, marginRight, marginTop, marginBottom); PdfWriter writer = PdfWriter.GetInstance(report, new FileStream(reportName, FileMode.Create)); //writer.SetEncryption(PdfWriter.STRENGTH40BITS, "Good", "Bad", PdfWriter.ALLOW_COPY); report.Open(); // _______________________________________________________2_______________________________________________________ // Setting Document properties(Meta data) // 1. Title // 2. Subject // 3. Keywords // 4. Creator // 5. Author // 6. Header report.AddTitle("Employee Details Report"); report.AddSubject("This file is generated for administrative use only"); report.AddKeywords("Civil Security Department, Employee Management System, Version 1.0.0, Report Generator"); report.AddCreator("Ozious Technologies"); report.AddAuthor("Eranga Heshan"); report.AddHeader("Owner", "Civil Security Department"); // _______________________________________________________3_______________________________________________________ // Setup the font factory /* int totalFonts = FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); StringBuilder sb = new StringBuilder(); foreach (string fontname in FontFactory.RegisteredFonts) { sb.Append(fontname + "\n"); } report.Add(new Paragraph("All Fonts:\n" + sb.ToString())); */ iTextSharp.text.Font fontHeader_1 = FontFactory.GetFont("Calibri", 30, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0)); iTextSharp.text.Font fontHeader_2 = FontFactory.GetFont("Calibri", 15, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(125, 125, 125)); // _______________________________________________________x_______________________________________________________ // Create header PdfContentByte cb = writer.DirectContent; cb.MoveTo(marginLeft, marginTop); cb.LineTo(500, marginTop); cb.Stroke(); Paragraph paraHeader_1 = new Paragraph("Civil Security Department", fontHeader_1); paraHeader_1.Alignment = Element.ALIGN_CENTER; paraHeader_1.SpacingAfter = 0f; report.Add(paraHeader_1); Paragraph paraHeader_2 = new Paragraph("Employee Detailed Report", fontHeader_2); paraHeader_2.Alignment = Element.ALIGN_CENTER; paraHeader_2.SpacingAfter = 10f; report.Add(paraHeader_2); // _______________________________________________________x_______________________________________________________ // Adding employee image iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imgEmployee.ImageLocation); img.ScaleToFit(100f, 100f); img.Border = iTextSharp.text.Rectangle.BOX; img.BorderColor = iTextSharp.text.BaseColor.BLACK; img.BorderWidth = 5f; img.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT | iTextSharp.text.Image.ALIGN_TOP; img.IndentationLeft = 50f; img.SpacingAfter = 20f; img.SpacingBefore = 20f; report.Add(img); Paragraph para1 = new Paragraph("Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... "); para1.Alignment = Element.ALIGN_JUSTIFIED; report.Add(para1); report.Close(); this.Close(); }
/// <summary> /// 读取或创建Pdf文档并打开写入文件流 /// </summary> /// <param name="fileName"></param> /// <param name="folderPath"></param> public Document GetOrCreatePDF(string fileName, string folderPath) { string filePath = folderPath + fileName; FileStream fs = null; if (!File.Exists(filePath)) { fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None); } else { fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.None); } //获取A4纸尺寸 Rectangle rec = new Rectangle(PageSize.A4); Document doc = new Document(rec); //创建一个 iTextSharp.text.pdf.PdfWriter 对象: 它有助于把Document书写到特定的FileStream: PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.AddTitle(fileName.Remove(fileName.LastIndexOf('.'))); doc.AddSubject(fileName.Remove(fileName.LastIndexOf('.'))); doc.AddKeywords("Metadata, iTextSharp 5.4.4, Chapter 1, Tutorial"); doc.AddCreator("MCS"); doc.AddAuthor("Chingy"); doc.AddHeader("Nothing", "No Header"); //打开 Document: doc.Open(); ////关闭 Document: //doc.Close(); return doc; }
/// <summary> /// Render all data add and writes it to the specified writer /// </summary> /// <param name="model"> /// The model to render /// </param> /// <param name="os"> /// The output to write to /// </param> public override void RenderAllTables(IDataSetModel model, Stream os) { // TODO check the number of horizontal & vertical key values to determine the orientation of the page var doc = new Document(this._pageSize, 80, 50, 30, 65); // This doesn't seem to do anything... doc.AddHeader(Markup.HTML_ATTR_STYLESHEET, "style/pdf.css"); doc.AddCreationDate(); doc.AddCreator("NSI .NET Client"); try { PdfWriter.GetInstance(doc, os); doc.Open(); this.WriteTableModels(model, doc); } catch (DocumentException ex) { Trace.Write(ex.ToString()); LogError.Instance.OnLogErrorEvent(ex.ToString()); } catch (DbException ex) { Trace.Write(ex.ToString()); LogError.Instance.OnLogErrorEvent(ex.ToString()); } finally { if (doc.IsOpen()) { doc.Close(); } } }
private void CreatePdf(string filePath) { iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(); PdfWriter.GetInstance(pdfDoc, new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite)); // For Turkish Characters iTextSharp.text.pdf.BaseFont STF_Helvetica_Turkish = BaseFont.CreateFont("Helvetica", "CP1254", BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fontTitle = new iTextSharp.text.Font(STF_Helvetica_Turkish, 12, iTextSharp.text.Font.NORMAL); pdfDoc.AddAuthor("FirstName Lastname"); pdfDoc.AddCreationDate(); pdfDoc.AddHeader(tbxPdfFileName.Text, tbxSubject.Text); if (pdfDoc.IsOpen() == false) { pdfDoc.Open(); } pdfDoc.Add(new Paragraph(rtbPdfText.Text, fontTitle)); pdfDoc.Close(); }
public void WriteTaskListToUserFile(string path, ObservableCollection <TaskTodo> ListofTasks) { iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4.Rotate()); PdfWriter.GetInstance(doc, new FileStream(path, FileMode.Create)); doc.Open(); doc.AddHeader("TodoList", " "); foreach (var task in ListofTasks) { doc.Add(new iTextSharp.text.Phrase("Name of Task : " + task.Name + "\n")); doc.Add(new iTextSharp.text.Phrase("Description of Task : " + task.Description + "\n")); doc.Add(new iTextSharp.text.Phrase("Tag of Task : " + task.Tag + "\n")); doc.Add(new iTextSharp.text.Phrase("Priority Level of Task : " + task.Prioriti + "\n")); doc.Add(new iTextSharp.text.Phrase("Due To date : " + task.DueTo.ToString("d") + "\n")); doc.Add(new iTextSharp.text.Phrase("Finished status of Task : " + task.Finished + "\n")); doc.Add(new iTextSharp.text.Phrase("\n")); } doc.AddAuthor("Dudchak A.V."); doc.Close(); }
void CreatePdf() { Itext.Document idoc = new Itext.Document(Itext.PageSize.A4); try { if (saveCWFileDialog.ShowDialog() == DialogResult.OK) { var newfilePath = saveCWFileDialog.FileName; PdfWriter.GetInstance(idoc, new FileStream(newfilePath, FileMode.Create)); #region 设置PDF的头信息,一些属性设置,在Document.Open 之前完成 idoc.AddAuthor(""); idoc.AddCreationDate(); idoc.AddCreator(""); idoc.AddSubject(""); idoc.AddTitle(""); idoc.AddKeywords(""); idoc.AddHeader("cw", "export pdf"); #endregion idoc.Open(); //载入字体 idoc.Add(new Itext.Paragraph(editContentBox.Text, new Itext.Font(BaseFontAndSize("")))); idoc.Close(); if (MessageBox.Show("是否打开文件?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { Process.Start(newfilePath); } } } catch (Itext.DocumentException de) { Console.WriteLine(de.Message); Console.ReadKey(); WriteLog.Logging(de.Message); } catch (IOException io) { Console.WriteLine(io.Message); Console.ReadKey(); WriteLog.Logging(io.Message); } catch (Exception err) { WriteLog.Logging(err); } }
private void button1_Click(object sender, EventArgs e) { if (Directory.Exists("C:mezunOgrenciler.pdf")) { File.Delete("C:mezunOgrenciler.pdf"); } //Kutuphane\Kutuphane\bin\Debug PdfWriter.GetInstance(pdfDosya, new FileStream("C:mezunOgrenciler.pdf", FileMode.Create)); pdfDosya.Open(); pdfDosya.AddCreator(main.ad); //Oluşturan kişinin isminin eklenmesi pdfDosya.AddHeader("PDF UYGULAMASI OLUSTUR", null); Paragraph eklenecekMetin = new Paragraph(richTextBox1.Text); pdfDosya.Add(eklenecekMetin); pdfDosya.Close(); button1.Enabled = false; RaporEkle rp = new RaporEkle(); rp.ShowDialog(); }
void WriteDocument(iTextSharp.text.Document doc, List <KeyValuePair <ISearchAlgorithm <string>, SearchReport <string> > > results, System.Drawing.Image initialGraph) { doc.AddCreationDate(); doc.AddAuthor("GraphSEA"); doc.AddCreator("GraphSEA"); doc.AddHeader("Header", "GraphSEA - Graph search algorithms benchmark report"); WriteHeader(doc); doc.NewPage(); WriteGraph(doc, initialGraph, results[0].Value.Result.Start, results[0].Value.Result.End); doc.NewPage(); WriteResultSummary(doc, results); doc.NewPage(); // algorithms benchmarks foreach (var res in results) { CurrentReport = res.Value; WriteAlgorithmBenchmark(doc, res.Key, res.Value); } WriteTableOfContent(doc); }
private void Btnpdfolustur_Click_1(object sender, EventArgs e) { iTextSharp.text.Document pdfdosya = new iTextSharp.text.Document(); //pdf dosyamızı temsil edecek nesnemizi oluşturuyoruz PdfWriter.GetInstance(pdfdosya, new FileStream("C:CSharpPDF.pdf", FileMode.Create)); //pdf dosyamızın yolunu belirledik ve dosyanın açılış biçimi olrarak pdf ayarladık pdfdosya.Open(); //dosyayı aç pdfdosya.AddCreator(txtolusturulan.Text); //oluşturan ismi pdfdosya.AddCreationDate(); //tarih pdfdosya.AddAuthor(txticeriksahibi.Text); //yazarın ismi eklendi pdfdosya.AddHeader(txtustbaslik.Text, "PDF UYGULAMASI OLUŞTUR"); pdfdosya.AddTitle(txtaltbaslik.Text); //başlık ve title eklenmesi Paragraph eklenecekmetin = new Paragraph(txtaciklamametni.Text); pdfdosya.Add(eklenecekmetin); //eklenecek metnimizin dosyaya eklenmesi decimal satir = numaricsatirsayisi.Value; //satir bilgisi decimal sutun = numaricsutunsayisi.Value; //sutun bilgisi iTextSharp.text.Table tablo = new Table((int)sutun, (int)satir); for (int i = 0; i < satir; i++) { for (int j = 0; j < sutun; j++) { Cell hucre = new Cell((i + 1).ToString() + " " + (j + 1).ToString()); hucre.BackgroundColor = iTextSharp.text.Color.RED; tablo.AddCell(hucre, i, j); } } tablo.cellspacing = 5; pdfdosya.Add(tablo); if (txtolusturulan.Text != "") { Uri yol = new Uri(txtolusturulan.Text); iTextSharp.text.Jpeg resim = new iTextSharp.text.Jpeg(yol); resim.ScalePercent((int)numaricsikistirmeorani.Value); pdfdosya.Add(resim); } pdfdosya.Close(); }
protected void Prepare_Print() { String[] weekDays = new String[] { " ","Sun", "Mon", "Tue", "Wed", "Thu" }; int[] sessions = new int[] {0,1,2,3,4,5,6,7,8,9}; PdfPTable tblSchedule = new PdfPTable(10); PdfPRow[] tempRow = new PdfPRow[6]; PdfPCell[][] tempCell = new PdfPCell[6][]; int rowIndex = 0; int cellIndex = 0; Paragraph subject = new Paragraph(); Paragraph teacher = new Paragraph(); Paragraph lunch = new Paragraph(); Paragraph dayPara = new Paragraph(); Paragraph sessionPara = new Paragraph(); Paragraph teacherPara = new Paragraph(); Font lunch_font = new Font(); Font day_session_para = new Font(); Font session_font = new Font(); Font teacher_font = new Font(); session_font.Size = 10; teacher_font.SetStyle("Italics"); teacher_font.Size = 7; lunch_font.SetColor(153, 153, 255); lunch_font.SetStyle("italics"); lunch = new Paragraph("Lunch", lunch_font); day_session_para.SetColor(0, 0, 153); foreach (String weekDay in weekDays) { tempCell[rowIndex] = new PdfPCell[10]; tempRow[rowIndex] = new PdfPRow(tempCell[rowIndex]); foreach (int session in sessions) { if (session == 0 || session == 6) { if (session == 0) { dayPara = new Paragraph(weekDays[rowIndex],day_session_para); tempCell[rowIndex][cellIndex] = new PdfPCell(dayPara); } else if (weekDay != " ") { tempCell[rowIndex][cellIndex] = new PdfPCell(lunch); } else { //tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(Convert.ToString(sessions[cellIndex]))); dayPara = new Paragraph(Convert.ToString(sessions[cellIndex]), day_session_para); tempCell[rowIndex][cellIndex] = new PdfPCell(dayPara); } } else { if (weekDay == " ") { dayPara = new Paragraph(Convert.ToString(sessions[cellIndex]), day_session_para); tempCell[rowIndex][cellIndex] = new PdfPCell(dayPara); //tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(Convert.ToString(sessions[cellIndex]))); } else { string query = "select B.CourseTitle,A.TeacherID from tblStudentCourseMap as A,tblCourses as B where A.ComCod = B.ComCod and A.DaySession = '" + weekDay + session + "' and A.StudentID = '" + Current_User_ID + "'"; myCon.ConOpen(); SqlDataReader sessionDet = myCon.ExecuteReader(query); if (sessionDet.Read()) if (!sessionDet.IsDBNull(0)) { sessionPara = new Paragraph(sessionDet.GetString(0), session_font); //tempCell[rowIndex][cellIndex] = new PdfPCell(sessionPara); teacherPara = new Paragraph(sessionDet.GetString(1), teacher_font); tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(sessionPara)); tempCell[rowIndex][cellIndex].Phrase.Add(new Phrase("\n")); tempCell[rowIndex][cellIndex].Phrase.Add(teacherPara); //tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(sessionDet.GetString(0) + "\n" + sessionDet.GetString(1))); } else { tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase("")); //tempCell[rowIndex][cellIndex } else tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase("")); myCon.ConClose(); tempCell[rowIndex][cellIndex].FixedHeight = 75; } } //tempCell[rowIndex][cellIndex].Width = 50; cellIndex++; //tempRow[rowIndex].Cells.Add(tempCell[cellIndex++, rowIndex]); } cellIndex = 0; //rowIndex++; tblSchedule.Rows.Add(tempRow[rowIndex++]); } Font HeaderFont = new Font(); Font HeadingFont = new Font(); HeaderFont.Size = 20; HeaderFont.SetStyle(Font.UNDERLINE); HeadingFont.Size = 15; HeadingFont.SetStyle(Font.UNDERLINE); Paragraph HeaderPara = new Paragraph("BITS PILANI, DUBAI OFFCAMPUS - TIMETABLE", HeaderFont); Paragraph HeadingPara = new Paragraph("Time Table allotment for " + Current_User_ID + ".",HeadingFont); HeaderPara.Alignment = HeadingPara.Alignment = 1; Document rptTimetable = new Document(PageSize.A4_LANDSCAPE.Rotate()); PdfWriter.GetInstance(rptTimetable, new FileStream(Request.PhysicalApplicationPath + "\\" + Current_User_ID + "_timetable.pdf", FileMode.Create)); rptTimetable.Open(); rptTimetable.AddCreationDate(); rptTimetable.AddHeader("BITS PILANI, DUBAI OFFCAMPUS", "TIMETABLE"); rptTimetable.Add(new Paragraph("\n")); rptTimetable.AddTitle("BITS PILANI, DUBAI OFFCAMPUS - TIMETABLE"); rptTimetable.Add(HeaderPara); rptTimetable.Add(HeadingPara); rptTimetable.Add(new Paragraph("\n\n")); if (rptTimetable != null && tblSchedule != null) { rptTimetable.Add(tblSchedule); } rptTimetable.Close(); Response.Redirect("~\\" + Current_User_ID + "_timetable.pdf"); }
protected void btntetkikkaydet_Click(object sender, EventArgs e) { MongoClient client = new MongoClient(); var database = client.GetDatabase("hastane"); var collection = database.GetCollection <yatanhastalar>("yatanhastalar"); var servislistesi = collection.Find(x => x._id != null).ToList().SelectMany(x => x.ServisList).ToList(); var hastalistesi = servislistesi.SelectMany(x => x.HastaList).ToList().Where(x => x._id == ObjectId.Parse(ddlHasta.SelectedValue)).ToList(); var radyolojilistesi = hastalistesi.SelectMany(x => x.RadyolojiList).ToList().Where(x => x._id == ObjectId.Parse(ddlRadyoloji.SelectedValue)); var tetkiklistesi = radyolojilistesi.SelectMany(x => x.TetkiklerList).ToList().Where(x => x.tahlil_adi == ListBox1.SelectedItem.Text); var hst = hastalistesi.FirstOrDefault(); var rad = radyolojilistesi.FirstOrDefault(); #region Font seç BaseFont trArial = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\tahoma.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fontArial = new iTextSharp.text.Font(trArial, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.DARK_GRAY); iTextSharp.text.Font fontArialHeader = new iTextSharp.text.Font(trArial, 13, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Font fontArialbold = new iTextSharp.text.Font(trArial, 9, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.DARK_GRAY); iTextSharp.text.Font fontArialboldgeneral = new iTextSharp.text.Font(trArial, 10, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); #endregion #region Sonuç pdf oluştur iTextSharp.text.Document pdfFile = new iTextSharp.text.Document(); PdfWriter.GetInstance(pdfFile, new FileStream("C:\\Users\\Önder\\Desktop\\Yeni klasör\\Radyoloji Sonuç (" + hst.hasta_tc + " " + hst.hasta_adi + " " + hst.hasta_soyadi + " " + DateTime.UtcNow.ToShortDateString() + ").pdf", FileMode.Create)); pdfFile.Open(); #endregion #region Sonuç oluşturan bilgileri pdfFile.AddCreator("Önder"); //Oluşturan kişinin isminin eklenmesi pdfFile.AddCreationDate(); //Oluşturulma tarihinin eklenmesi pdfFile.AddAuthor("Radyoloji"); //Yazarın isiminin eklenmesi pdfFile.AddHeader("Başlık", "PDF UYGULAMASI OLUSTUR"); pdfFile.AddTitle("Sonuç Raporu"); //Başlık ve title eklenmesi #endregion #region Sonuç firma resmi ve tarihi oluştur iTextSharp.text.Image jpgimg = iTextSharp.text.Image.GetInstance(@"C:/Users/Önder/Desktop/Önder Fatih Buhurcu Staj Projesi/WebApplicationHastane/WebApplicationHastane/login/images/İsimsiz-1.png"); jpgimg.ScalePercent(35); jpgimg.Alignment = iTextSharp.text.Image.LEFT_ALIGN; PdfPTable pdfTableHeader = new PdfPTable(3); pdfTableHeader.TotalWidth = 500f; pdfTableHeader.LockedWidth = true; //pdfTableHeader.DefaultCell.Border = Rectangle; PdfPCell cellheader1 = new PdfPCell(jpgimg); cellheader1.HorizontalAlignment = PdfPCell.ALIGN_LEFT; cellheader1.VerticalAlignment = PdfPCell.ALIGN_BOTTOM; cellheader1.FixedHeight = 60f; cellheader1.Border = 0; pdfTableHeader.AddCell(cellheader1); PdfPCell cellheader2 = new PdfPCell(new Phrase("SONUÇ RAPORU", fontArialHeader)); cellheader2.HorizontalAlignment = PdfPCell.ALIGN_CENTER; cellheader2.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; cellheader2.FixedHeight = 60f; cellheader2.Border = 0; pdfTableHeader.AddCell(cellheader2); PdfPCell cellheader3 = new PdfPCell(new Phrase(DateTime.Now.ToShortDateString(), fontArial)); cellheader3.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; cellheader3.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; cellheader3.FixedHeight = 60f; cellheader3.Border = 0; pdfTableHeader.AddCell(cellheader3); #endregion Phrase p = new Phrase("\n"); Paragraph yazi = new Paragraph("Hasta TC: " + hst.hasta_tc + "\nHasta Adı: " + hst.hasta_adi + "\nHasta Soyadı: " + hst.hasta_soyadi + "\n\n\n"); #region Tabloyu Oluştur PdfPTable pdfTable = new PdfPTable(1); pdfTable.TotalWidth = 500f; pdfTable.LockedWidth = true; pdfTable.HorizontalAlignment = 1; pdfTable.DefaultCell.Padding = 5; pdfTable.DefaultCell.BorderColor = iTextSharp.text.BaseColor.GRAY; pdfTable.AddCell(new Phrase(ListBox1.SelectedItem.Text + " Sonucu", fontArialboldgeneral)); pdfTable.AddCell(new Phrase(sonucText.Value, fontArial)); #endregion #region Pdfe yaz ve dosyayı kapat if (pdfFile.IsOpen() == false) { pdfFile.Open(); } pdfFile.Add(pdfTableHeader); pdfFile.Add(p); pdfFile.Add(yazi); pdfFile.Add(pdfTable); pdfFile.Close(); #endregion var filter = Builders <yatanhastalar> .Filter.ElemMatch(x => x.ServisList, Builders <servis> .Filter.ElemMatch(x => x.HastaList, Builders <hasta> .Filter.And(Builders <hasta> .Filter.Eq(x => x._id, ObjectId.Parse(ddlHasta.SelectedValue)), Builders <hasta> .Filter.ElemMatch(x => x.RadyolojiList, Builders <radyolojitetkikler> .Filter.And(Builders <radyolojitetkikler> .Filter.Eq(x => x._id, ObjectId.Parse(ddlRadyoloji.SelectedValue)), Builders <radyolojitetkikler> .Filter.ElemMatch(x => x.TetkiklerList, Builders <tetkikler> .Filter.Eq(x => x.tahlil_adi, ListBox1.SelectedItem.Text))))))); var update = Builders <yatanhastalar> .Update.Pull("ServisList.$[].HastaList.$[].RadyolojiList.$[].TetkiklerList", tetkiklistesi); collection.UpdateOne(filter, update); var sayı = radyolojilistesi.SelectMany(x => x.TetkiklerList).ToList(); if (sayı.Count == 0) { var filter2 = Builders <yatanhastalar> .Filter.ElemMatch(x => x.ServisList, Builders <servis> .Filter.ElemMatch(x => x.HastaList, Builders <hasta> .Filter.Eq(x => x._id, ObjectId.Parse(ddlHasta.SelectedValue)))); hst.hasta_radyoloji_durum = "Sonuçlandı"; var update2 = Builders <yatanhastalar> .Update.Set(b => b.ServisList, servislistesi); } }
public void Build() { iTextSharp.text.Document doc = null; try { // Initialize the PDF document doc = new Document(); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new System.IO.FileStream(System.IO.Directory.GetCurrentDirectory() + "\\ScienceReport.pdf", System.IO.FileMode.Create)); // Set the margins and page size this.SetStandardPageSize(doc); // Add metadata to the document. This information is visible when viewing the // document properities within Adobe Reader. doc.AddTitle("My Science Report"); doc.AddHeader("title", "My Science Report"); doc.AddHeader("author", "M. Lichtenberg"); doc.AddCreator("M. Lichtenberg"); doc.AddKeywords("paper airplanes"); doc.AddHeader("subject", "paper airplanes"); // Add Xmp metadata to the document. this.CreateXmpMetadata(writer); // Open the document for writing content doc.Open(); // Add pages to the document this.AddPageWithBasicFormatting(doc); this.AddPageWithInternalLinks(doc); this.AddPageWithBulletList(doc); // Add a page with an image to the document. The page will be sized to match the image size. this.AddPageWithImage(doc, System.IO.Directory.GetCurrentDirectory() + "\\FinalGraph.jpg"); // Add a final page this.SetStandardPageSize(doc); // Reset the margins and page size this.AddPageWithExternalLinks(doc); // Add page labels to the document iTextSharp.text.pdf.PdfPageLabels pdfPageLabels = new iTextSharp.text.pdf.PdfPageLabels(); pdfPageLabels.AddPageLabel(1, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Basic Formatting"); pdfPageLabels.AddPageLabel(2, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Internal Links"); pdfPageLabels.AddPageLabel(3, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Bullet List"); pdfPageLabels.AddPageLabel(4, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Image"); pdfPageLabels.AddPageLabel(5, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "External Links"); writer.PageLabels = pdfPageLabels; } catch (iTextSharp.text.DocumentException dex) { // Handle iTextSharp errors } finally { // Clean up doc.Close(); doc = null; } }
private void button1_Click(object sender, EventArgs e) { if (openFile1.SafeFileName == "" || openFile2.SafeFileName == "") { MessageBox.Show("No haz seleccionado ningún PDF", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("Se unira \"" + openFile1.SafeFileName + "\" con \"" + openFile2.SafeFileName + "\""); saveFile.Filter = "Adobe Acrobat Document PDF (*.pdf)|*.pdf"; saveFile.FilterIndex = 1; if (saveFile.ShowDialog() == DialogResult.OK) { MessageBox.Show("Se guardara en la siguiente ruta:\n" + saveFile.FileName); FileStream myStream = new FileStream(saveFile.FileName,FileMode.OpenOrCreate); PdfReader reader = new PdfReader(openFile1.FileName); PdfReader reader2 = new PdfReader(openFile2.FileName); Document document = new Document(reader.GetPageSizeWithRotation(1)); PdfCopy writer = new PdfCopy(document, myStream); document.Open(); document.AddCreationDate(); if (txtAutor.Text != null) { document.AddAuthor(txtAutor.Text); } if (txtHeader.Text != null) { document.AddHeader(txtHeader.Text, "Document"); } if (txtKeywords.Text != null) { document.AddKeywords(txtKeywords.Text); } document.AddProducer(); if (txtTitulo.Text != null) { document.AddTitle(txtTitulo.Text); } // Calculando incremento progressBar.Refresh(); int incremento = (int)(100 / (reader.NumberOfPages + reader2.NumberOfPages)); MessageBox.Show("Incremento es: " + incremento); for (int i = 1; i <= reader.NumberOfPages; i++) { writer.AddPage(writer.GetImportedPage(reader, i)); progressBar.PerformStep(); progressBar.Increment(++incremento); } progressBar.Increment(50); for (int i = 1; i <= reader2.NumberOfPages; i++) { writer.AddPage(writer.GetImportedPage(reader2, i)); progressBar.PerformStep(); } progressBar.Increment(100); document.Close(); } }
protected void SonucYazdır_Click(object sender, EventArgs e) { MongoClient client = new MongoClient(); var database = client.GetDatabase("hastane"); var collection = database.GetCollection <yatanhastalar>("yatanhastalar"); var servislistesi = collection.Find(x => x._id != null).ToList().SelectMany(x => x.ServisList).ToList(); var hastalistesi = servislistesi.SelectMany(x => x.HastaList).ToList().Where(x => x._id == ObjectId.Parse(ddlHasta2.SelectedValue)).ToList().FirstOrDefault(); var sonuc = database.GetCollection <islemsonuc>("sonuclistesi").Find(x => x._id == ObjectId.Parse(ddlsonuctarih.SelectedValue) && x.sonuc_cesidi == "Laboratuvar").ToList().SelectMany(x => x.SonucList).ToList(); #region Font seç BaseFont trArial = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\tahoma.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fontArial = new iTextSharp.text.Font(trArial, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.DARK_GRAY); iTextSharp.text.Font fontArialHeader = new iTextSharp.text.Font(trArial, 13, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Font fontArialbold = new iTextSharp.text.Font(trArial, 9, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.DARK_GRAY); iTextSharp.text.Font fontArialboldgeneral = new iTextSharp.text.Font(trArial, 10, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); #endregion #region Sonuç pdf oluştur iTextSharp.text.Document pdfFile = new iTextSharp.text.Document(); PdfWriter.GetInstance(pdfFile, new FileStream("C:\\Users\\Önder\\Desktop\\Yeni klasör\\Kan Sonucu (" + hastalistesi.hasta_adi + " " + hastalistesi.hasta_soyadi + " " + ddlsonuctarih.SelectedItem.Text + ").pdf", FileMode.Create)); pdfFile.Open(); #endregion #region Sonuç oluşturan bilgileri pdfFile.AddCreator("Önder"); //Oluşturan kişinin isminin eklenmesi pdfFile.AddCreationDate(); //Oluşturulma tarihinin eklenmesi pdfFile.AddAuthor("Laboratuvar"); //Yazarın isiminin eklenmesi pdfFile.AddHeader("Başlık", "PDF UYGULAMASI OLUSTUR"); pdfFile.AddTitle("Sonuç Raporu"); //Başlık ve title eklenmesi #endregion #region Sonuç firma resmi ve tarihi oluştur iTextSharp.text.Image jpgimg = iTextSharp.text.Image.GetInstance(@"C:/Users/Önder/Desktop/Önder Fatih Buhurcu Staj Projesi/WebApplicationHastane/WebApplicationHastane/login/images/İsimsiz-1.png"); jpgimg.ScalePercent(35); jpgimg.Alignment = iTextSharp.text.Image.LEFT_ALIGN; PdfPTable pdfTableHeader = new PdfPTable(3); pdfTableHeader.TotalWidth = 500f; pdfTableHeader.LockedWidth = true; pdfTableHeader.DefaultCell.Border = Rectangle.NO_BORDER; PdfPCell cellheader1 = new PdfPCell(jpgimg); cellheader1.HorizontalAlignment = PdfPCell.ALIGN_LEFT; cellheader1.VerticalAlignment = PdfPCell.ALIGN_BOTTOM; cellheader1.FixedHeight = 60f; cellheader1.Border = 0; pdfTableHeader.AddCell(cellheader1); PdfPCell cellheader2 = new PdfPCell(new Phrase("SONUÇ RAPORU", fontArialHeader)); cellheader2.HorizontalAlignment = PdfPCell.ALIGN_CENTER; cellheader2.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; cellheader2.FixedHeight = 60f; cellheader2.Border = 0; pdfTableHeader.AddCell(cellheader2); PdfPCell cellheader3 = new PdfPCell(new Phrase(DateTime.Now.ToShortDateString(), fontArial)); cellheader3.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; cellheader3.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; cellheader3.FixedHeight = 60f; cellheader3.Border = 0; pdfTableHeader.AddCell(cellheader3); #endregion Phrase p = new Phrase("\n"); Paragraph yazi = new Paragraph("Hasta TC: " + hastalistesi.hasta_tc + "\nHasta Adı: " + hastalistesi.hasta_adi + "\nHasta Soyadı: " + hastalistesi.hasta_soyadi + "\n\n\n"); #region Tabloyu Oluştur PdfPTable pdfTable = new PdfPTable(2); pdfTable.TotalWidth = 500f; pdfTable.LockedWidth = true; pdfTable.HorizontalAlignment = 1; pdfTable.DefaultCell.Padding = 5; pdfTable.DefaultCell.BorderColor = iTextSharp.text.BaseColor.GRAY; foreach (var item in sonuc) { pdfTable.AddCell(new Phrase(item.tahlil_adi, fontArialboldgeneral)); pdfTable.AddCell(new Phrase(item.sonuc, fontArial)); } #endregion #region Pdfe yaz ve dosyayı kapat if (pdfFile.IsOpen() == false) { pdfFile.Open(); } pdfFile.Add(pdfTableHeader); pdfFile.Add(p); pdfFile.Add(yazi); pdfFile.Add(pdfTable); pdfFile.Close(); #endregion }
/// <summary> /// This function prints the invoice in pdf. /// </summary> /// <param name="_name">This parameter is customer's name.</param> /// <param name="_phoneNumber">This parameter is customer's phone number.</param> /// <param name="_adress">This parameter is customer's addres.</param> /// <param name="_paymentType">This parameter is Customer's payment type.</param> /// <param name="_delivery">This parameter is shipping cost.</param> /// <param name="_taxex">This parameter is tax.</param> /// <param name="_totalCost">This parameter is the total cost.</param> public void Document(string _name, string _phoneNumber, string _adress, string _paymentType, string _subtotal, string _delivery, string _taxex, string _totalCost) { try { NumberFormatInfo provider = new NumberFormatInfo(); provider.NumberDecimalSeparator = "."; iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(PageSize.A4, 40f, 40f, 80f, 80f); PdfWriter.GetInstance(pdfDoc, new FileStream("InvoicePDF.pdf", FileMode.Create)); pdfDoc.Open(); pdfDoc.AddCreator("Dream Book Store"); pdfDoc.AddCreationDate(); pdfDoc.AddAuthor("Admin"); pdfDoc.AddHeader("Dream Book Store", "Involce"); pdfDoc.AddTitle("Dream Book Store"); Paragraph spacer = new Paragraph("") { SpacingBefore = 30f, SpacingAfter = 30f }; string[] headers = new string[5]; headers[0] = "ID"; headers[1] = "Product Name"; headers[2] = "Quantity"; headers[3] = "Price"; headers[4] = "Total Price"; var logo = iTextSharp.text.Image.GetInstance(Resources.invoice, Resources.invoice.RawFormat); logo.ScalePercent(21f); logo.SetAbsolutePosition(pdfDoc.Left, pdfDoc.Top - 30); pdfDoc.Add(logo); var timeTable = new PdfPTable(new[] { .75f }) { HorizontalAlignment = 2, WidthPercentage = 40, DefaultCell = { MinimumHeight = 12f, } }; timeTable.AddCell("Date"); timeTable.AddCell(DateTime.Now.ToString()); pdfDoc.Add(timeTable); pdfDoc.Add(spacer); Paragraph elements1 = new Paragraph("Bill to :" + Environment.NewLine + "Dream Book Store" + Environment.NewLine + "Root" + Environment.NewLine + "Eskisehir Osmangazi University " + Environment.NewLine + "Computer Engineering Department " + Environment.NewLine + "0222 222 01 01" + Environment.NewLine + "*****@*****.**" + Environment.NewLine); Paragraph elements2 = new Paragraph("Ship to :" + Environment.NewLine + "Customer ID: " + MainWindow.cart.CustomerId1 + Environment.NewLine + _name + Environment.NewLine + _adress + Environment.NewLine + _phoneNumber + Environment.NewLine + _paymentType); elements1.Alignment = Element.ALIGN_LEFT; elements2.Alignment = Element.ALIGN_RIGHT; pdfDoc.Add(elements1); pdfDoc.Add(elements2); pdfDoc.Add(spacer); PdfPTable table = new PdfPTable(new[] { .75f, 2.5f, 1f, 1f, 1.5f }) { HorizontalAlignment = 1, WidthPercentage = 75, DefaultCell = { MinimumHeight = 22f, } }; for (int i = 0; i < headers.Length; i++) { PdfPCell cell = new PdfPCell(new PdfPCell()); cell.AddElement(new Chunk(headers[i])); table.AddCell(cell); } for (int i = 0; i < ShoppingCart.ItemsToPurchase.Count; i++) { double TotalPrice = Convert.ToDouble((ShoppingCart.ItemsToPurchase[i].Product.Price), provider) * ShoppingCart.ItemsToPurchase[i].Quantity; table.AddCell(ShoppingCart.ItemsToPurchase[i].Product.Id); table.AddCell(ShoppingCart.ItemsToPurchase[i].Product.Name); table.AddCell(ShoppingCart.ItemsToPurchase[i].Quantity.ToString()); table.AddCell(ShoppingCart.ItemsToPurchase[i].Product.Price); table.AddCell(TotalPrice.ToString()); } pdfDoc.Add(table); Paragraph elements3 = new Paragraph("Subtotal :" + _subtotal + Environment.NewLine + "Delivery :" + _delivery + Environment.NewLine + "Taxex :" + _taxex + Environment.NewLine + "-----------------------" + Environment.NewLine + "Total Cost =" + _totalCost); elements3.Alignment = Element.ALIGN_RIGHT; pdfDoc.Add(elements3); pdfDoc.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Creates the PDF. /// </summary> /// <param name="workReportData">The work report data.</param> public static void CreateWorkReportPdf(WorkReportData workReportData) { try { Document document = new Document(PageSize.A4, 10, 10, 42, 35); FileStream fileStream = new FileStream(Filename, FileMode.Create); PdfWriter pdfWriter = PdfWriter.GetInstance(document, fileStream); document.Open(); #region Header //// Header Paragraph paragraph = new Paragraph("Work report"); document.Add(paragraph); document.AddHeader("Header", "Work report"); #endregion #region Report information table PdfPTable rptTable = new PdfPTable(5); rptTable.SpacingBefore = 30f; rptTable.SpacingAfter = 15f; rptTable.TotalWidth = 500f; rptTable.LockedWidth = true; float[] rptWidths = { 2.1f, 1.5f, 2.1f, 1f, 1f }; rptTable.SetWidths(rptWidths); #region Row 1 PdfPCell cell = new PdfPCell(new Phrase("Creation Date:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.DateOfCreation.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase("Period:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.PeriodStart.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.PeriodStop.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); #endregion #region Row 2 cell = new PdfPCell(new Phrase("Serial Number:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.SerialNumber, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase("Project Number:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.ProjectNumber, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; cell.Colspan = 2; rptTable.AddCell(cell); #endregion #region Row 3 cell = new PdfPCell(new Phrase("Machine Type:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.MachineType, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(string.Empty, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; cell.Colspan = 3; rptTable.AddCell(cell); #endregion #region Row 4 cell = new PdfPCell(new Phrase("Engineer Name:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.EngineerName, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(string.Empty, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; cell.Colspan = 3; rptTable.AddCell(cell); #endregion #region Row 5 cell = new PdfPCell(new Phrase("Coordinator:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.Coordinator, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase("Customer coordinator:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.CustomerCoordinator, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; cell.Colspan = 2; rptTable.AddCell(cell); #endregion #region Row 6 cell = new PdfPCell(new Phrase("Module serial numbers:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.ModuleSerialNumbers, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; cell.Colspan = 4; rptTable.AddCell(cell); #endregion #region Row 7 cell = new PdfPCell(new Phrase("Job description:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; rptTable.AddCell(cell); cell = new PdfPCell(new Phrase(workReportData.JobDescription, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; cell.Colspan = 4; rptTable.AddCell(cell); #endregion document.Add(rptTable); #endregion #region Work day table foreach (WorkDay day in workReportData.WorkDayCollection) { PdfPTable workDayTable = new PdfPTable(5); workDayTable.TotalWidth = 470f; workDayTable.LockedWidth = true; workDayTable.SpacingAfter = 10f; float[] workDayWidths = { 1f, 1f, 2f, 1f, 1f }; workDayTable.SetWidths(workDayWidths); #region Row 1 cell = new PdfPCell(new Phrase("Date:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(day.DateOfCreation.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase("Travel Time:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(day.TravelTimeStartAway.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(day.TravelTimeStopAway.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(string.Empty)); cell.Colspan = 2; cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase("Working Time:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(day.WorkingTimeStart.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(day.WorkingTimeStop.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(string.Empty)); cell.Colspan = 2; cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase("Travel Time:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(day.TravelTimeStartReturn.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(day.TravelTimeStopReturn.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.FixedHeight = 20f; workDayTable.AddCell(cell); cell = new PdfPCell(new Phrase(day.Content, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL))); cell.Colspan = 5; workDayTable.AddCell(cell); document.Add(workDayTable); #endregion } #endregion document.Close(); } catch (Exception exception) { Console.WriteLine(exception); } }
public void ExtractPdf(DataGridView dataGridView, bool selectedParameter) { Phrase p = new Phrase("\n"); #region Font seç BaseFont trArial = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\tahoma.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fontArial = new iTextSharp.text.Font(trArial, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.DARK_GRAY); iTextSharp.text.Font fontArialHeader = new iTextSharp.text.Font(trArial, 11, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Font fontArialbold = new iTextSharp.text.Font(trArial, 9, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.DARK_GRAY); iTextSharp.text.Font fontArialboldgeneral = new iTextSharp.text.Font(trArial, 10, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); #endregion #region Fatura pdf oluştur SaveFileDialog save = new SaveFileDialog(); save.OverwritePrompt = false; save.Title = "PDF Dosyaları"; save.DefaultExt = "pdf"; save.Filter = "pdf Dosyaları (*.pdf)|*.pdf|Tüm Dosyalar(*.*)|*.*"; if (save.ShowDialog() == DialogResult.OK) { iTextSharp.text.Document pdfFile = new iTextSharp.text.Document(); PdfWriter.GetInstance(pdfFile, new FileStream(save.FileName, FileMode.Create)); pdfFile.Open(); #region Fatura oluşturan bilgileri pdfFile.AddCreator("Hakedis"); //Oluşturan kişinin isminin eklenmesi pdfFile.AddCreationDate(); //Oluşturulma tarihinin eklenmesi pdfFile.AddAuthor("Hakedis" + applicationVersion); //Yazarın isiminin eklenmesi pdfFile.AddHeader(DateTime.Now.ToLongDateString(), "Hakediş " + DateTime.Now.ToLongDateString()); pdfFile.AddTitle("Hakediş Rapor"); //Başlık ve title eklenmesi #endregion #region Tablo Başlık tarih ve marka bilgileri PdfPTable markAndDateTable = new PdfPTable(2); markAndDateTable.TotalWidth = 250f; markAndDateTable.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; PdfPCell markName = new PdfPCell(new Phrase("Hakediş " + applicationVersion, fontArialbold)); markName.HorizontalAlignment = Element.ALIGN_LEFT; markName.VerticalAlignment = Element.ALIGN_LEFT; markName.Border = 0; PdfPCell dateTimeReport = new PdfPCell(new Phrase(DateTime.Now.ToLongDateString(), fontArialbold)); dateTimeReport.VerticalAlignment = Element.ALIGN_RIGHT; dateTimeReport.HorizontalAlignment = Element.ALIGN_RIGHT; dateTimeReport.Border = 0; dateTimeReport.ExtraParagraphSpace = 5f; markAndDateTable.AddCell(markName); markAndDateTable.AddCell(dateTimeReport); #endregion #region Veri Tablosu İşlemleri #region Pdf Kolon Başlıklarını Belirleme int columnCount = dataGridView.Columns.Count; PdfPTable pdfColumnheader = new PdfPTable(columnCount - 2); pdfColumnheader.TotalWidth = 400f; pdfColumnheader.LockedWidth = true; pdfColumnheader.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; if (selectedParameter == true) { for (int i = 0; i < columnCount; i++) { if (i != 0 && i != 1) { PdfPCell columnName = new PdfPCell(new Phrase(dataGridView.Columns[i].HeaderText, fontArialHeader)); columnName.HorizontalAlignment = PdfPCell.ALIGN_CENTER; columnName.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; columnName.FixedHeight = 30f; columnName.Border = 1; pdfColumnheader.AddCell(columnName); } } } else { pdfColumnheader = new PdfPTable(columnCount - 1); for (int i = 0; i < columnCount; i++) { if (i != 0) { PdfPCell columnName = new PdfPCell(new Phrase(dataGridView.Columns[i].HeaderText, fontArialHeader)); columnName.HorizontalAlignment = PdfPCell.ALIGN_CENTER; columnName.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; columnName.FixedHeight = 30f; columnName.Border = 1; pdfColumnheader.AddCell(columnName); } } } #region Satır işlemleri int rowsCount = dataGridView.Rows.Count; PdfPTable pdfDataTable = new PdfPTable(columnCount - 2); if (selectedParameter == true) { for (int i = 0; i <= rowsCount - 1; i++) { for (int j = 0; j < dataGridView.Rows[i].Cells.Count; j++) { if (j != 0 && j != 2) { PdfPCell cell2 = new PdfPCell(new Phrase(dataGridView.Rows[i].Cells[j].Value.ToString(), fontArial)); pdfDataTable.AddCell(cell2); } } } } else { pdfDataTable = new PdfPTable(columnCount - 1); for (int i = 0; i <= rowsCount - 1; i++) { for (int j = 0; j < dataGridView.Rows[i].Cells.Count; j++) { if (j != 0) { PdfPCell cell2 = new PdfPCell(new Phrase(dataGridView.Rows[i].Cells[j].Value.ToString(), fontArial)); pdfDataTable.AddCell(cell2); } } } } #endregion #region Toplam Bilgi Verileri PdfPTable tableTotalInfo = new PdfPTable(2); tableTotalInfo.TotalWidth = 250f; tableTotalInfo.LockedWidth = true; tableTotalInfo.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; double totalManOfDay = 0; if (selectedParameter == true) { for (int i = 0; i < dataGridView.Rows.Count; i++) { totalManOfDay += double.Parse(dataGridView.Rows[i].Cells[6].Value.ToString()); } } else { for (int i = 0; i < dataGridView.Rows.Count; i++) { totalManOfDay += double.Parse(dataGridView.Rows[i].Cells[2].Value.ToString()); } } PdfPCell cellTotalManOfDay = new PdfPCell(new Phrase(totalManOfDay.ToString(), fontArial)); cellTotalManOfDay.HorizontalAlignment = Element.ALIGN_CENTER; cellTotalManOfDay.VerticalAlignment = Element.ALIGN_LEFT; PdfPCell cellTotal = new PdfPCell(new Phrase("Toplam İş Günü", fontArial)); cellTotal.HorizontalAlignment = Element.ALIGN_CENTER; cellTotal.VerticalAlignment = Element.ALIGN_LEFT; tableTotalInfo.AddCell(cellTotal); tableTotalInfo.AddCell(cellTotalManOfDay); #endregion #endregion #region Pdf Dosyasını yaz ve kapat if (pdfFile.IsOpen() == false) { pdfFile.Open(); } pdfFile.Add(markAndDateTable); pdfFile.Add(p); pdfFile.Add(pdfColumnheader); pdfFile.Add(p); pdfFile.Add(pdfDataTable); pdfFile.Add(p); pdfFile.Add(tableTotalInfo); //pdfFile.Add(p); //pdfFile.Add(p); //pdfFile.Add(p); //pdfFile.Add(nameSurname); //pdfFile.Add(p); //pdfFile.Add(signature); pdfFile.Close(); #endregion #endregion } #endregion }