/// <summary> /// 使用字体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { #region //var doc = new Document(PageSize.A4); //BaseFont basefont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); //iTextSharp.text.Font font = new iTextSharp.text.Font(basefont, 16, iTextSharp.text.Font.ITALIC, iTextSharp.text.BaseColor.RED); //PdfWriter.GetInstance(doc, new FileStream("pdf/test4.pdf", FileMode.Create)); //doc.Open(); //doc.Add(new Paragraph("This is a Read Font test using Times Roman.", font)); //doc.Add(new Paragraph("This is a default Font test.")); //doc.Close(); #endregion #region int totalFonts = FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); StringBuilder sb = new StringBuilder(); foreach (string name in FontFactory.RegisteredFonts) { sb.Append(string.Format("{0}\n", name)); } var doc = new Document(); PdfWriter.GetInstance(doc, new FileStream("pdf/test5.pdf", FileMode.Create)); doc.Open(); doc.Add(new Paragraph(string.Format("Total Fonts:{0}", totalFonts))); doc.Add(new Paragraph(sb.ToString())); doc.Close(); #endregion }
protected void Button1_Click(object sender, EventArgs e) { System.IO.StringWriter stringWrite = new System.IO.StringWriter(); string fileName = " EmployeeTranferReport.pdf"; Response.AppendHeader("Content-Type", "application/pdf"); Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName); Response.Cache.SetCacheability(HttpCacheability.NoCache); stringWrite.WriteLine("<html><body encoding=" + BaseFont.IDENTITY_H + " style='font-family:Arial Unicode MS;font-size:12;'> <table style='width:100%'><tr><td align='center'><b>Vãi nồi</b></td></tr><tr><td align='center'>अगरतला</td></tr></table> </body></html>"); HtmlTextWriter hw = new HtmlTextWriter(stringWrite); StringReader sr = new StringReader(stringWrite.ToString()); Document pdfDoc = new Document(PageSize.A4, 20f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter wi = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); string fontpath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts) + "\\ARIALUNI.TTF"; // "ARIALUNI.TTF" file copied from fonts folder and placed in the folder BaseFont bf = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); FontFactory.RegisterDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), true); FontFactory.Register(fontpath, "Arial Unicode MS"); //FontFactory.RegisterFamily("Arial Unicode MS", "Arial Unicode MS", fontpath); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); }
public pdfWriter(string pOutPath) { // TODO add more exception checking... try { // Open file stream for exported pdf _fileStream = new System.IO.FileStream(pOutPath, System.IO.FileMode.Create); } catch (Exception e) { Log.Error("Creating pdf file at: '" + pOutPath + "' failed with error: '" + e.Message + "'."); return; } // initialize iTextSharp pdf writer _writer = PdfWriter.GetInstance(_doc, _fileStream); // just put something in there, doesn't really matter... _doc.AddAuthor("Cewe2pdf.exe"); _doc.AddCreator("Cewe2Pdf"); _doc.AddTitle("ConvertedCewePhotobook"); // TODO: move font loading to Config class? // necessary for loading .ttf it seams System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); const string fontPath = "C:\\Windows\\Fonts"; // FIXME: windows only obviously Log.Info("Loading fonts from " + fontPath); FontFactory.RegisterDirectory(fontPath); string cwfontPath = Config.ProgramPath + "\\Resources\\photofun\\fonts"; Log.Info("Loading fonts from " + cwfontPath); FontFactory.RegisterDirectory(cwfontPath); // recursivly search for fonts folders in full hps path const string hpsPath = "C:\\ProgramData\\hps"; // FIXME ^^ if (System.IO.Directory.Exists(hpsPath)) { Log.Info("Searching for fonts directory at " + hpsPath); string[] fontDirs = System.IO.Directory.GetDirectories(hpsPath, "fonts", System.IO.SearchOption.AllDirectories); foreach (string dir in fontDirs) { Log.Info("Loading fonts from: '" + dir + "'."); FontFactory.RegisterDirectory(dir); } } else { Log.Warning("Directory at: '" + hpsPath + "' does not exist. Skipping."); } Log.Info("Found " + FontFactory.RegisteredFonts.Count + " fonts."); // start writing _doc.Open(); }
public PrintHelper() { _doc = new Document(PageSize.A4, 10, 10, 10, 2); _tilte = new Paragraph("Page Title"); _tilte.Alignment = 1; //center FileName = Guid.NewGuid() + ".pdf"; FontFactory.RegisterDirectory(Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts"); _h1 = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 28f, Font.BOLD, BaseColor.BLACK); _h2 = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 20f, Font.NORMAL, BaseColor.BLACK); _h3 = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 14f, Font.NORMAL, BaseColor.BLACK); _normal = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10f, Font.NORMAL, BaseColor.BLACK); _bold = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10f, Font.BOLD, BaseColor.BLACK); _underline = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10f, Font.UNDERLINE, BaseColor.BLACK); }
/// <summary> /// Loads the installed fonts. /// </summary> public void LoadInstalledFonts() { try { string windowsFontDir = @"C:\Windows\Fonts\"; if (System.IO.Directory.Exists(windowsFontDir)) { FontFactory.RegisterDirectory(windowsFontDir); } } catch (Exception) { // Currently do nothing maybe we are running under a linux system } }
static void Main(string[] args) { int totalfonts = FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); StringBuilder sb = new StringBuilder(); foreach (string fontname in FontFactory.RegisteredFonts) { sb.Append(fontname + "\n"); } const string fileName = "Files/BinMoves(2).xlsx"; //todo read excel file var bins = ReadFile(fileName); //todo generate pdf file from bins GeneratePdfFile(bins); //Console.ReadKey(); }
private void LoadFonts() { int totalfonts = FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); DataTable dt = new DataTable(); dt.Columns.Add("Font", typeof(String)); foreach (string fontname in FontFactory.RegisteredFonts) { dt.Rows.Add(new object[1] { fontname }); } dt.DefaultView.Sort = "Font"; this.ddlChequeFont.DataSource = dt; this.ddlChequeFont.DataTextField = "Font"; this.ddlChequeFont.DataValueField = "Font"; this.ddlChequeFont.DataBind(); this.ddlChequeFont.SelectedIndex = 0; }
/// <summary> /// Start the process /// </summary> public void Start() { //register the system font folder FontFactory.RegisterDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Fonts)); //create the pdf writer and open the document PdfWriter writer = PdfWriter.GetInstance(document, memoryStream); document.Open(); //assigne the pdf content to the writer pdfContent = writer.DirectContent; //stamp the pdf info document.AddAuthor(report.Author); document.AddCreationDate(); document.AddCreator("ReportingCloud"); document.AddSubject(report.Description); document.AddTitle(report.Name); }
public byte[] PdfFromHtml(string html, float width, float height, float marginLeft = 50, float marginRight = 50, float marginTop = 10, float marginBottom = 10, IPdfPageEvent pdfPageEvent = null) { var effectivePageSize = new Rectangle(width, height); byte[] buffer = null; using (var memoryStream = new MemoryStream()) { using (var document = new Document(effectivePageSize, marginLeft, marginRight, marginTop, marginBottom)) { using (var writer = PdfWriter.GetInstance(document, memoryStream)) { writer.PageEvent = pdfPageEvent; int totalfonts = FontFactory.RegisterDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Fonts)); using (var sr = new StringReader(html)) { document.Open(); XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, sr); document.Close(); buffer = memoryStream.ToArray(); } } } } return(buffer); }
// =========================================================================== public void Write(Stream stream) { // step 1 using (Document document = new Document()) { // step 2 PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 Font font = FontFactory.GetFont("Times-Roman"); document.Add(new Paragraph("Times-Roman", font)); Font fontbold = FontFactory.GetFont("Times-Roman", 12, Font.BOLD); document.Add(new Paragraph("Times-Roman, Bold", fontbold)); document.Add(Chunk.NEWLINE); FontFactory.Register("c:/windows/fonts/garabd.ttf", "my_bold_font"); Font myBoldFont = FontFactory.GetFont("my_bold_font"); BaseFont bf = myBoldFont.BaseFont; document.Add(new Paragraph(bf.PostscriptFontName, myBoldFont)); String[][] name = bf.FullFontName; for (int i = 0; i < name.Length; i++) { document.Add(new Paragraph( name[i][3] + " (" + name[i][0] + "; " + name[i][1] + "; " + name[i][2] + ")" )); } Font myBoldFont2 = FontFactory.GetFont("Garamond vet"); document.Add(new Paragraph("Garamond Vet", myBoldFont2)); document.Add(Chunk.NEWLINE); document.Add(new Paragraph("Registered fonts:")); FontFactory.RegisterDirectory(Utility.ResourceFonts); /* * string fontDirectory = Utility.ResourceFonts; * FontFactory.RegisterDirectory( * fontDirectory.Substring(0, fontDirectory.Length - 3 * )); */ foreach (String f in FontFactory.RegisteredFonts) { document.Add(new Paragraph( f, FontFactory.GetFont(f, "", BaseFont.EMBEDDED ))); } document.Add(Chunk.NEWLINE); Font cmr10 = FontFactory.GetFont("cmr10"); cmr10.BaseFont.PostscriptFontName = "Computer Modern Regular"; Font computerModern = FontFactory.GetFont( "Computer Modern Regular", "", BaseFont.EMBEDDED ); document.Add(new Paragraph("Computer Modern", computerModern)); document.Add(Chunk.NEWLINE); FontFactory.RegisterDirectories(); foreach (String f in FontFactory.RegisteredFamilies) { document.Add(new Paragraph(f)); } document.Add(Chunk.NEWLINE); Font garamond = FontFactory.GetFont( "garamond", BaseFont.WINANSI, BaseFont.EMBEDDED ); document.Add(new Paragraph("Garamond", garamond)); Font garamondItalic = FontFactory.GetFont( "Garamond", BaseFont.WINANSI, BaseFont.EMBEDDED, 12, Font.ITALIC ); document.Add(new Paragraph("Garamond-Italic", garamondItalic)); } }
private void genPDF() { System.Drawing.Font font = new System.Drawing.Font("Microsoft Sans Serif", 12); iTextSharp.text.pdf.BaseFont bfR, bfR1, bfRB; iTextSharp.text.BaseColor clrBlack = new iTextSharp.text.BaseColor(0, 0, 0); //MemoryStream ms = new MemoryStream(); string myFont = Environment.CurrentDirectory + "\\THSarabun.ttf"; string myFontB = Environment.CurrentDirectory + "\\THSarabun Bold.ttf"; String hn = "", name = "", doctor = "", fncd = "", birthday = "", dsDate = "", dsTime = "", an = ""; decimal total = 0; bfR = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bfR1 = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bfRB = BaseFont.CreateFont(myFontB, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); iTextSharp.text.Font fntHead = new iTextSharp.text.Font(bfR, 12, iTextSharp.text.Font.NORMAL, clrBlack); String[] aa = dsDate.Split(','); if (aa.Length > 1) { dsDate = aa[0]; an = aa[1]; } String[] bb = dsDate.Split('*'); if (bb.Length > 1) { dsDate = bb[0]; dsTime = bb[1]; } var logo = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\LOGO-BW-tran.jpg"); logo.SetAbsolutePosition(10, PageSize.A4.Height - 90); logo.ScaleAbsoluteHeight(70); logo.ScaleAbsoluteWidth(70); FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4, 36, 36, 36, 36); try { FileStream output = new FileStream(Environment.CurrentDirectory + "\\" + txtHn.Text.Trim() + ".pdf", FileMode.Create); PdfWriter writer = PdfWriter.GetInstance(doc, output); doc.Open(); //PdfContentByte cb = writer.DirectContent; //ColumnText ct = new ColumnText(cb); //ct.Alignment = Element.ALIGN_JUSTIFIED; //Paragraph heading = new Paragraph("Chapter 1", fntHead); //heading.Leading = 30f; //doc.Add(heading); //Image L = Image.GetInstance(imagepath + "/l.gif"); //logo.SetAbsolutePosition(doc.Left, doc.Top - 180); doc.Add(logo); //doc.Add(new Paragraph("Hello World", fntHead)); Chunk c; String foobar = "Foobar Film Festival"; //float width_helv = bfR.GetWidthPoint(foobar, 12); //c = new Chunk(foobar + ": " + width_helv, fntHead); //doc.Add(new Paragraph(c)); //if (dt.Rows.Count > 24) //{ // doc.NewPage(); // doc.Add(new Paragraph(string.Format("This is a page {0}", 2))); //} int i = 0, r = 0, row2 = 0, rowEnd = 24; //r = dt.Rows.Count; int next = r / 24; int linenumber = 820, colCenter = 200, fontSize0 = 8, fontSize1 = 14, fontSize2 = 16, fontSize3 = 18; PdfContentByte canvas = writer.DirectContent; canvas.BeginText(); canvas.SetFontAndSize(bfR, 12); canvas.ShowTextAligned(Element.ALIGN_LEFT, "โรงพยาบาล บางนา5 55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, linenumber, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, 780, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "BANGNA 5 GENERAL HOSPITAL 55 M.4 Theparuk Road, Bangplee, Samutprakan Thailand0", 100, linenumber - 15, 0); canvas.EndText(); linenumber = 720; canvas.BeginText(); canvas.SetFontAndSize(bfR, fontSize3); canvas.ShowTextAligned(Element.ALIGN_CENTER, "ใบรับรองแพทย์", PageSize.A4.Width / 2, linenumber + 40, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ส่วนที่ 1", 50, linenumber += 10, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ของผู้ขอรับใบรับรองสุขภาพ", 100, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ข้าพเจ้า นาย/นาง/นางสาว ", 50, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................................................................................................................ ", 170, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text.Trim(), 173, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "สถานที่อยู่ (ที่สามารถติดต่อได้)", 50, linenumber -= 20, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddr1.Text, 172, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................................................................................................................ ", 170, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................................................................................................................................................................... ", 50, linenumber -= 20, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddr2.Text, 55, linenumber + 5, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "หมายเลขบัตรประจำตัวประชาชน", 50, linenumber -= 20, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtId.Text, 172, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................... ", 170, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ข้าพเจ้าขอใบรับรองสุขภาพ โดยมีประวัติสุขภาพดังนี้", 330, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "1. โรคประจำตัว", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ไม่มี [ ] มี ระบุ ........................................................................................................................", 200, linenumber, 0); if (chk1Normal.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 205, linenumber, 0); } else if (chk1AbNormal.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 248, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txt1AbNormal.Text, 290, linenumber + 5, 0); } canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "2. อุบัติเหตุ และ ผ่าตัด", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ไม่มี [ ] มี ระบุ ........................................................................................................................", 200, linenumber, 0); if (chk2Normal.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 205, linenumber, 0); } else if (chk2AbNormal.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 248, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txt2AbNormal.Text, 290, linenumber + 5, 0); } canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "3. เคยเข้ารับการรักษาในโรงพยาบาล", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ไม่มี [ ] มี ระบุ ........................................................................................................................", 200, linenumber, 0); if (chk3Normal.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 205, linenumber, 0); } else if (chk3AbNormal.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 248, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txt3AbNormal.Text, 290, linenumber + 5, 0); } canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "4. ประวัติอื่นที่สำคัญ", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................................................................................. ", 130, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtOther.Text, 133, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ลงชื่อ .............................................................. วันที่ .............. เดือน .............................. พ.ศ. ...............", 150, linenumber -= 40, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("dd"), 340, linenumber + 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, bc.getMonth(DateTime.Now.ToString("MM")), 400, linenumber + 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("yyyy"), 490, linenumber + 5, 0); canvas.SetFontAndSize(bfRB, fontSize1); canvas.ShowTextAligned(Element.ALIGN_CENTER, "ในกรณีเด็กทีไม่สามารถรับรองตนเองได้ ให้ผู้ปกครองลงนามรับรองแทนได้", PageSize.A4.Width / 2, linenumber -= 20, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ส่วนที่ 2 ของแพทย์", 50, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "สถานที่ตรวจ", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................................................................ ", 100, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, TxtHospitalName.Text, 110, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "วันที่ ", 380, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "..........", 398, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("dd"), 401, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, " เดือน", 420, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".........................", 445, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, bc.getMonth(DateTime.Now.ToString("MM")), 448, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, " พ.ศ. ", 500, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "............", 520, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("yyyy"), 523, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(1) ข้าพเจ้า นายแพทย์/แพทย์หญิง", 40, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "..................................................................................................................... ", 175, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorName.Text, 178, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ใบอนุญาตประกอบวิชาชีพเวชกรรมเลขที่", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "..................................... ", 205, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorId.Text, 208, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "สถานพยาบาลชื่อ", 292, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "......................................................................................... ", 355, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, TxtHospitalName.Text, 358, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ที่อยู่", 50, linenumber -= 20, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัดสมุทรปราการ 10540", 77, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................................................................................................................... ", 72, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ได้ตรวจร่างกาย นาย/นาง/นางสาว", 50, linenumber -= 20, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text, 187, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................. ", 182, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "แล้วเมื่อ วันที่", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "..........", 120, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("dd"), 123, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, " เดือน", 142, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".........................", 167, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, bc.getMonth(DateTime.Now.ToString("MM")), 170, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, " พ.ศ. ", 230, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "............", 250, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("yyyy"), 253, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, " มีรายละเอียดดังนี้ ", 290, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "น้ำหนักตัว", 50, linenumber -= 20, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtWeight.Text, 105, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "......................", 88, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "กก. ความสูง", 140, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtHeight.Text, 205, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "......................", 190, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "เซนติเมตร ความดันโลหิต", 240, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtBloodPressure.Text, 345, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "......................", 340, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "มม.ปรอท ชีพจร ", 400, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPulse.Text, 480, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................", 468, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ครั้ง/นาที ", 520, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "สภาพร่างกายทั่วไปอยู่ในเกณฑ์ [ ] ปกติ [ ] ผิดปกติ ระบุ", 50, linenumber -= 20, 0); if (chkNormal.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 173, linenumber, 0); } else if (chkAbNormal.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 214, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAbnormal.Text, 287, linenumber, 0); } canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "....................................................................................................................", 280, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ขอรับรองว่า บุคคลดังกล่าว ไม่เป็นผู้มีร่างกายทุพพลภาพจนไม่สามารถปฏิบัติหน้าที่ได้ ไม่ปรากฏอาการของโรคจิต ", 100, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "หรือจิตฟั่นเฟือน หรือปัญญาอ่อน ไม่ปรากฏอาการของการติดยาเสพติดให้โทษ และอาการของโรคพิษสุราเรื้อรัง และไม่", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ปรากฏอาการและอาการแสดงของโรคต่อไปนี้", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(1) โรคเรื้อนในระยะติดต่อ หรือในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม", 80, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(2) วัณโรคในระยะอันตราย", 80, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(3) โรคเท้าช้างในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม", 80, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(4) ถ้าจำเป็นต้องตรวจหาโรคที่เกี่ยวข้องกับการปฏิบัติงานของผูัรับการตรวจให้ระบุข้อนี้ ", 80, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".......................................................................", 400, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "สรุปความเห็นและข้อแนะนำของแพทย์ ", 100, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] " + chk1.Text, 120, linenumber -= 20, 0); if (chk1.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 124, linenumber, 0); } canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] " + chk2.Text, 120, linenumber -= 20, 0); if (chk2.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 124, linenumber, 0); } canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] " + chk3.Text, 120, linenumber -= 20, 0); if (chk3.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 124, linenumber, 0); } canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] " + chk4.Text, 120, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................................................", 178, linenumber - 5, 0); if (chk4.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 124, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txt4Other.Text, 180, linenumber, 0); } canvas.SetFontAndSize(bfR, fontSize1); //canvas.ShowTextAligned(Element.ALIGN_LEFT, ".......................................................................................................................................", 50, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ลงชื่อ ", 270, linenumber -= 40, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................................................", 290, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "แพทย์ผู้ตรวจร่างกาย", 480, linenumber, 0); //canvas.SetFontAndSize(bfRB, fontSize2); //canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorName.Text, 213, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "หมายเหตุ (1) ต้องเป็นแพทย์ซึ่งได้ขึ้นทะเบียนรับใบอนุญาตประกอบวิชาชีพเวชกรรม ", 50, linenumber -= 10, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(2) ให้แสดงว่าเป็นผู้มีร่างกายสมบูรณ์เพียงใด ใบรับรองแพทย์ฉบับนี้ให้ใช้ได้ 1 เดือน นับแต่วันที่ตรวจร่างกาย ", 72, linenumber -= 10, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(3) คำรับรองนี้เป็นการตรวจวินิจฉัยเบื้องต้น ", 72, linenumber -= 10, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "แบบฟอร์มนี้ได้รับการรับรองจากมติคณะกรรมการแพทยสภาในการประชุมครั้งที่ ค/2561 วันที่ 14 สิงหาคม 2561 ", 50, linenumber -= 10, 0); canvas.EndText(); canvas.Stroke(); //canvas.RestoreState(); //pB1.Maximum = dt.Rows.Count; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { doc.Close(); Process p = new Process(); ProcessStartInfo s = new ProcessStartInfo(Environment.CurrentDirectory + "\\" + txtHn.Text.Trim() + ".pdf"); //s.Arguments = "/c dir *.cs"; p.StartInfo = s; //p.StartInfo.Arguments = "/c dir *.cs"; //p.StartInfo.UseShellExecute = false; //p.StartInfo.RedirectStandardOutput = true; p.Start(); //string output = p.StandardOutput.ReadToEnd(); //p.WaitForExit(); //Application.Exit(); } }
private void RegisterDefaultFontDirectoryFromConfigurationFile() { // TO DO: make this configurable FontFactory.RegisterDirectory("C:\\Windows\\Fonts"); }
/// <summary> /// 导出图片和表格数据到Pdf /// </summary> /// <param name="strhead">表头文字</param> /// <param name="strfoot">表</param> /// <param name="filepath">文件名</param> /// <param name="图片地址">imgurl</param> public static void ExportPicToPdf(string strhead, string strfoot, string filename, string imgurl) { //Document.compress = false; Document document = new Document(PageSize.A3, 20f, 20f, 20f, 20f); //string strFileName = "Export" + 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() + ".pdf"; //string path = HttpContext.Current.Server.MapPath(BasePage.AppUrl + "_Temp") + @"\" + strFileName; string path = filename; try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create)); // step 3: we open the document document.Open(); StyleSheet style = new StyleSheet(); style.LoadTagStyle("body", "face", "SIMHEI"); style.LoadTagStyle("body", "encoding", "Identity-H"); style.LoadTagStyle("body", "leading", "12,0"); FontFactory.RegisterDirectory("c:\\Windows\\Fonts"); FontSelector selector = new FontSelector(); selector.AddFont(FontFactory.GetFont("Gulim", BaseFont.IDENTITY_H, false, 10)); if (!string.IsNullOrEmpty(strhead)) { Paragraph para1 = new Paragraph(selector.Process("")); HTMLWorker worker = new HTMLWorker(document); StringReader stringReader = new StringReader(strhead); System.Collections.ArrayList p = HTMLWorker.ParseToList(stringReader, style); for (int k = 0; k < p.Count; k++) { para1.Add((IElement)p[k]); } document.Add(para1); } // step 4: we create a table and add it to the document string url = imgurl; iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(url); //图片自适应大小 经验证PDF宽度大致为800以上像素 小于此宽不论 大于则自动缩放图片到宽度800 if (img.PlainWidth > 800) { img.ScalePercent(100 * 800 / img.PlainWidth); } //img.ScalePercent(100); document.Add(img); if (!string.IsNullOrEmpty(strfoot)) { Paragraph para2 = new Paragraph(selector.Process("")); HTMLWorker worker = new HTMLWorker(document); StringReader stringReader = new StringReader(strfoot); System.Collections.ArrayList p = HTMLWorker.ParseToList(stringReader, style); for (int k = 0; k < p.Count; k++) { para2.Add((IElement)p[k]); } document.Add(para2); } //document.Add(AddTable(strfoot)); } catch (DocumentException de) { System.Web.HttpContext.Current.Response.Write(de.Message); } catch (IOException ioe) { System.Web.HttpContext.Current.Response.Write(ioe.Message); } // step 5: we close the document document.Close(); // DownloadFile(path); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(Path.GetFileName(path).Trim()) + "\""); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.WriteFile(path); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Close(); if (File.Exists(path)) { File.Delete(path); } HttpContext.Current.Response.End(); }
//todo:potwierdzenie dotarcia i potwierdzenia pobrania dodać na spodzie załącznika private void CreateAttachmentNr6(string officialPositionWhoGetNewNotification, int howManyMonthsAnimalLive, string numberLastNotification, string savepath) // tworzymy załącznik nr 6 w pdfie { checkBseOrTseTest(out string testType); System.IO.FileStream fs = new FileStream(savepath + numberLastNotification + "-" + mainWindow.txtFarmNumber.Text + "-zal6-" + savingDateTime + ".pdf", FileMode.Create); // tworzymy instancje klasy dokumentu pdf z wymiarem A4 Document document = new Document(PageSize.A4, 25, 25, 30, 30); // klasa writer używająca dokument i strumienia w konstruktorze PdfWriter writer = PdfWriter.GetInstance(document, fs); // meta informacje o dokumencie document.AddAuthor(officialPositionWhoGetNewNotification); document.AddTitle("Rejestr zgłoszeń padłego bydła - załącznik 6"); // otwieramy dokument aby dodac do niego zawartość document.Open(); // dodajemy zawartość FontFactory.RegisterDirectory("C:WINDOWSFonts"); //dodajemy polskie znaki var polskie_znaki = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Phrase("Rejestr zgłoszeń padłego bydła - załącznik 6 Olesno " + DateTime.Now.ToString("yyyy-MM-dd") + "\n ", polskie_znaki)); cell.Colspan = 2; cell.Border = 0; cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right table.AddCell(cell); PdfPCell cell2 = new PdfPCell(new Phrase("\nSkierowanie sztuki padłej/zabitej do ZU/ZP", polskie_znaki)); cell2.Colspan = 2; cell2.Border = 0; cell2.HorizontalAlignment = 0; table.AddCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase("\nAdresat: (właściwy dla miejsca lokalizacji zakładu utylizacyjnego/zakładu pośredniego)", polskie_znaki)); cell3.Colspan = 2; cell3.Border = 0; cell3.HorizontalAlignment = 0; table.AddCell(cell3); table.AddCell(new Phrase("Powiatowy Lekarz Weterynarii", polskie_znaki)); table.AddCell(new Phrase(comboBox_PLWUtilizationArea.Text, polskie_znaki)); PdfPCell cell4 = new PdfPCell(new Phrase("\nNadawca: (właściwy dla miejsca padnięcia/zabicia zwierzęcia)", polskie_znaki)); cell4.Colspan = 2; cell4.Border = 0; cell4.HorizontalAlignment = 0; table.AddCell(cell4); table.AddCell(new Phrase("Powiatowy Lekarz Weterynarii ", polskie_znaki)); table.AddCell(new Phrase(comboBox_PLWDeadArea.Text, polskie_znaki)); table.AddCell(new Phrase("Numer dokumentu", polskie_znaki)); table.AddCell("1608/" + numberLastNotification + "/2019"); table.AddCell(new Phrase("Numer kolczyka", polskie_znaki)); table.AddCell(mainWindow.txtEarTagNumber.Text); table.AddCell(new Phrase("data urodzenia i wiek", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtDateBorn.Text + " wiek: " + howManyMonthsAnimalLive + "miesięcy", polskie_znaki)); table.AddCell(new Phrase("płeć", polskie_znaki)); table.AddCell(new Phrase(mainWindow.comboBox_GenderOfDeadAnimal.Text, polskie_znaki)); table.AddCell(new Phrase("Data i godzina padnięcia/zabicia", polskie_znaki)); table.AddCell(mainWindow.txtDateDead.Text + " " + mainWindow.txtHourOfDeadAnimal.Text); table.AddCell(new Phrase("Imię i nazwisko posiadacza zwierzęcia", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtName.Text + ' ' + mainWindow.txtSurname.Text, polskie_znaki)); table.AddCell(new Phrase("Adres gospodarstwa/nr siedziby stada", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtStreet.Text + ' ' + mainWindow.txtHouseNumber.Text + ' ' + mainWindow.txtLocalNumber.Text + ' ' + mainWindow.txtPostCode.Text + ' ' + mainWindow.txtPost.Text + '/' + mainWindow.txtFarmNumber.Text, polskie_znaki)); table.AddCell(new Phrase("miejscowość", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtCity.Text, polskie_znaki)); table.AddCell(new Phrase("powiat", polskie_znaki)); table.AddCell(new Phrase("olesno", polskie_znaki)); table.AddCell(new Phrase("województwo", polskie_znaki)); table.AddCell(new Phrase("opolskie", polskie_znaki)); table.AddCell(new Phrase("Imię i nazwisko", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtWhoReportingNewNotification.Text, polskie_znaki)); table.AddCell(new Phrase("Adres zam.", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtAddressPersonReporting.Text, polskie_znaki)); table.AddCell(new Phrase("Telefon", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtPhonePersonReporting.Text, polskie_znaki)); table.AddCell(new Phrase("Przyczyna padnięcia", polskie_znaki)); table.AddCell(new Phrase(mainWindow.comboBox_DeadDeterminedOrNot.Text, polskie_znaki)); table.AddCell(new Phrase("Prawdopodobna przyczyna padnięcia: ", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtWhyDead.Text, polskie_znaki)); PdfPCell cell5 = new PdfPCell(new Phrase("\nProszę o przesłanie próbek do badań w kierunku " + testType + " z adnotacją o potrzebie przesłania wyniku " + "badania faksem na nr 34 358 26 18 oraz drogą elektroniczną [email protected]. " + "Kosztami badań należy obciążyć budżet wojewódzkiego inspektoratu weterynarii " + comboBox_WIW.Text + " (WIW właściwy dla miejsca pobrania próbki do badania " + "w kierunku BSE).\n ", polskie_znaki)); cell5.Colspan = 2; cell5.Border = 0; cell5.HorizontalAlignment = 0; table.AddCell(cell5); table.AddCell(new Phrase("Potwierdzenie dotarcia zwłok do ZU: ", polskie_znaki)); table.AddCell(new Phrase("POTWIERDZAM\n\nNIE POTWIERDZAM\n\nData i godzina:", polskie_znaki)); table.AddCell(new Phrase("Potwierdzenie pobrania próbki na BSE: ", polskie_znaki)); table.AddCell(new Phrase("POBRANO NIE POBRANO**", polskie_znaki)); PdfPCell cell6 = new PdfPCell(new Phrase("\n**podać przyczyną nie pobrania próbki .........................................................\n" + "\n........................................................................................................................", polskie_znaki)); cell6.Colspan = 2; cell6.Border = 0; cell6.HorizontalAlignment = 0; table.AddCell(cell6); PdfPCell cell7 = new PdfPCell(new Phrase("Osoba wysyłająca awizo: \n " + mainWindow.comboBox_WhoGetGetNotification.Text, polskie_znaki)); cell7.Colspan = 2; cell7.Border = 0; cell7.HorizontalAlignment = 2; //0=Left, 1=Centre, 2=Right table.AddCell(cell7); PdfPCell cell8 = new PdfPCell(new Phrase("\n\n\n\n\n-właściwe podkreślić", polskie_znaki)); cell8.Colspan = 2; cell8.Border = 0; cell8.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right table.AddCell(cell8); document.Add(table); // zamknij dokument document.Close(); // zamknij writer writer.Close(); // zakmnij obsługiwane pliki fs.Close(); MessageBox.Show("Utworzono i zapisano załącznik nr 6."); }
private void btnPDF_Click(object sender, EventArgs e) { DataGridViewRow row = dgrid.Rows[indexRow]; int nrZlecenia = Convert.ToInt32(row.Cells[0].Value); string typZlecenia = "", status = "", opisUsterki = "", gwarancja = "", typUrzadzenia = "", marka = "", model = "", nrSeryjny = "", imei = "", procesor = "", pamiec = "", plytaGlowna = "", dyskTwardy = "", dyskSSD = "", kartaGraficzna = "", zasilacz = "", ekran = "", systemOperacyjny = "", rysy = "", plamy = "", uszkodzenia = "", uwagi = "", ekspertyza = "", system = "", podzespoly = "", pasty = "", testUrzadzenia = "", czyszczenie = "", testDysku = "", zauwazoneUsterki = ""; decimal cenaUsluga = 0, cenaCzesci = 0, cenaRazem = 0; string dataPrzyjecia = "", dataNaprawy = ""; // pobranie danych urządzenia try { if (polaczenie.State == ConnectionState.Closed) { polaczenie.Open(); } zapytanie = string.Format("select data_przyjecia, typ_zlecenia, status, cena_usluga, cena_czesci, cena_razem, data_naprawy, opis_usterki, gwarancja, typ_urzadzenia, marka, model, nr_seryjny, imei, procesor, pamiec, plyta_glowna, dysk_twardy, dysk_ssd, karta_graficzna, zasilacz, ekran, system_operacyjny, rysy, plamy, uszkodzenia, uwagi, ekspertyza, system, podzespoly, pasty, test_urzadzenia, czyszczenie, test_dysku, zauwazone_usterki FROM zlecenia, dane_urzadzenia, modele, czynnosci WHERE dane_urzadzenia.id_modelu = modele.id_modelu AND dane_urzadzenia.id_urzadzenia = zlecenia.id_urzadzenia AND czynnosci.id_zlecenia = zlecenia.id_zlecenia;"); komenda = new SqlCommand(zapytanie, polaczenie); czytnik = komenda.ExecuteReader(); if (czytnik.HasRows) { while (czytnik.Read()) { dataPrzyjecia = Convert.ToString(czytnik.GetDateTime(0)); typZlecenia = czytnik.GetString(1); status = czytnik.GetString(2); cenaUsluga = czytnik.GetDecimal(3); cenaCzesci = czytnik.GetDecimal(4); cenaRazem = czytnik.GetDecimal(5); dataNaprawy = Convert.ToString(czytnik.GetDateTime(6)); opisUsterki = czytnik.GetString(7); gwarancja = czytnik.GetString(8); typUrzadzenia = czytnik.GetString(9); marka = czytnik.GetString(10); model = czytnik.GetString(11); nrSeryjny = czytnik.GetString(12); imei = czytnik.GetString(13); procesor = czytnik.GetString(14); pamiec = czytnik.GetString(15); plytaGlowna = czytnik.GetString(16); dyskTwardy = czytnik.GetString(17); dyskSSD = czytnik.GetString(18); kartaGraficzna = czytnik.GetString(19); zasilacz = czytnik.GetString(20); ekran = czytnik.GetString(21); systemOperacyjny = czytnik.GetString(22); rysy = czytnik.GetString(23); plamy = czytnik.GetString(24); uszkodzenia = czytnik.GetString(25); uwagi = czytnik.GetString(26); ekspertyza = czytnik.GetString(27); system = czytnik.GetString(28); podzespoly = czytnik.GetString(29); pasty = czytnik.GetString(30); testUrzadzenia = czytnik.GetString(31); czyszczenie = czytnik.GetString(32); testDysku = czytnik.GetString(33); zauwazoneUsterki = czytnik.GetString(34); } } czytnik.Close(); } catch (Exception ex) { string byk = string.Format("Nie mogę pobrać danych.\n{0}", ex.Message); MessageBox.Show(byk, "Błąd pobierania danych", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { polaczenie.Close(); } var outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf"); using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None)) { using (var doc = new Document(PageSize.A4, 10f, 10f, 10f, 10f)) { using (var writer = PdfWriter.GetInstance(doc, fs)) { doc.Open(); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 16, iTextSharp.text.Font.NORMAL); iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(Properties.Resources.logo_duze, System.Drawing.Imaging.ImageFormat.Jpeg); logo.ScaleAbsolute(550f, 70f); logo.Alignment = Element.ALIGN_CENTER; var p = new Paragraph(new Chunk("RAPORT NAPRAWY", font)); p.Alignment = Element.ALIGN_CENTER; FontFactory.RegisterDirectory(@"C:\Windows\Fonts"); var p1 = new Paragraph(string.Format("\n1. Typ urządzenia: {0}\n2. Dane techniczne: (Szczegółowy opis w przypadku laptopów oraz desktopów)\n", typUrzadzenia), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 11)); p1.Alignment = Element.ALIGN_LEFT; p1.IndentationLeft = 20f; PdfPTable table1 = new PdfPTable(3); PdfPCell cell11 = new PdfPCell(new Phrase(string.Format("Procesor - {0}", procesor), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 10))); cell11.Border = 0; table1.AddCell(cell11); PdfPCell cell12 = new PdfPCell(new Phrase(string.Format("Pamięć - {0}", pamiec), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 10))); cell12.Border = 0; table1.AddCell(cell12); PdfPCell cell13 = new PdfPCell(new Phrase(string.Format("Płyta główna - {0}", plytaGlowna), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 10))); cell13.Border = 0; table1.AddCell(cell13); PdfPTable table2 = new PdfPTable(3); PdfPCell cell21 = new PdfPCell(new Phrase(string.Format("Dysk - {0}", dyskTwardy), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 10))); cell21.Border = 0; table2.AddCell(cell21); PdfPCell cell22 = new PdfPCell(new Phrase(string.Format("Dysk SSD - {0}", dyskSSD), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 10))); cell22.Border = 0; table2.AddCell(cell22); PdfPCell cell23 = new PdfPCell(new Phrase(string.Format("Karta graficzna - {0}", kartaGraficzna), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 10))); cell23.Border = 0; table2.AddCell(cell23); PdfPTable table3 = new PdfPTable(2); PdfPCell cell31 = new PdfPCell(new Phrase(string.Format("Zasilacz - {0}", zasilacz), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 10))); cell31.Border = 0; table3.AddCell(cell31); PdfPCell cell32 = new PdfPCell(new Phrase(string.Format("System operacyjny - {0}", systemOperacyjny), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 10))); cell32.Border = 0; table3.AddCell(cell32); var p2 = new Paragraph("3. Stan ogólny dostarczonego urządzenia:\n", FontFactory.GetFont("Arial", BaseFont.CP1250, true, 11)); p2.Alignment = Element.ALIGN_LEFT; p2.IndentationLeft = 20f; var p3 = new Paragraph(string.Format("Rysy na obudowie oraz matrycy: {0}\nPlamy na obudowie oraz matrycy: {1}\nUszkodzenia mechaniczne: {2}", rysy.ToUpper(), plamy.ToUpper(), uszkodzenia.ToUpper()), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 11)); p3.Alignment = Element.ALIGN_LEFT; p3.IndentationLeft = 40f; var p4 = new Paragraph(string.Format("4. Opis usterki przez klienta:\n {0}", opisUsterki), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 11)); p4.Alignment = Element.ALIGN_LEFT; p4.IndentationLeft = 20f; var p5 = new Paragraph(string.Format("5. Ekspertyza:\n {0}", ekspertyza), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 11)); p5.Alignment = Element.ALIGN_LEFT; p5.IndentationLeft = 20f; var p6 = new Paragraph(string.Format("6. Lista napraw:\n- Reinstalacja lub odzyskiwanie systemu operacyjnego do stanu początkowego: {0}\n- Wymiana podzespołów: {1}\n- Wymiana past termoprzewodzących: {2}\n- Test urządzenia: {3}\n- Dokładne czyszczenie urządzenia: {4}\n- Dokładny test dysku twardego: {5} - Jeżeli tak to kopia raportu dla klienta.\n- Zauważone usterki, które nie zostały usunięte na prośbę klienta sprzętu: {6}", system.ToUpper(), podzespoly, pasty.ToUpper(), testUrzadzenia.ToUpper(), czyszczenie.ToUpper(), testDysku.ToUpper(), zauwazoneUsterki), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 11)); p6.Alignment = Element.ALIGN_LEFT; p6.IndentationLeft = 20f; var p7 = new Paragraph(string.Format("\nCena za usługę: {0} zł Cena za części: {1} zł Razem: {2} zł\nData wykonania naprawy: {3}", Decimal.Round(cenaUsluga, 2), Decimal.Round(cenaCzesci, 2), Decimal.Round(cenaRazem, 2), Convert.ToDateTime(dataNaprawy).ToString("yyyy-MM-dd")), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 11)); p7.Alignment = Element.ALIGN_LEFT; p7.IndentationLeft = 20f; var p8 = new Paragraph(string.Format("\nZgodnie z raportem na wykonaną naprawę przysługuje gwarancja w okresie {0}. Gwarancja nie obejmuje nowych usterek spowodowanych złym użytkowaniem sprzętu, zalaniem urządzenia cieczami, usterek mechanicznych, rozbieraniu urządzenia przez niewkwalifikowane osoby, a także na inne usterki, które nie były naprawiane na życzenie klienta. Instalowanie oprogramowania niewiadomego pochodzenia, które może zawierać wirusy użytkownik robi na własną odpowiedzialność.", gwarancja), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 11)); p8.Alignment = Element.ALIGN_JUSTIFIED; p8.IndentationLeft = 20f; p8.IndentationRight = 20f; iTextSharp.text.Image JPG = iTextSharp.text.Image.GetInstance(Properties.Resources.logo, System.Drawing.Imaging.ImageFormat.Jpeg); JPG.ScalePercent(6f); PdfPTable table4 = new PdfPTable(2); PdfPCell cell41 = new PdfPCell(JPG); cell41.Border = 0; cell41.HorizontalAlignment = Element.ALIGN_RIGHT; cell41.VerticalAlignment = Element.ALIGN_BOTTOM; cell41.PaddingRight = 10f; table4.AddCell(cell41); PdfPCell cell42 = new PdfPCell(new Phrase(string.Format("\nPodpis i pieczęć serwisu\n\n\n.........................................", systemOperacyjny), FontFactory.GetFont("Arial", BaseFont.CP1250, true, 12))); cell42.Border = 0; cell42.HorizontalAlignment = Element.ALIGN_LEFT; table4.AddCell(cell42); doc.Add(logo); doc.Add(p); doc.Add(p1); doc.Add(table1); doc.Add(table2); doc.Add(table3); doc.Add(p2); doc.Add(p3); doc.Add(p4); doc.Add(p5); doc.Add(p6); doc.Add(p7); doc.Add(p8); doc.Add(table4); doc.Close(); // otwieranie PDF System.Diagnostics.Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Test.pdf"); } } } }
public void makeCollectionPlusLabel(string filepath) { Document document = new Document(); FileStream fs = new FileStream(filepath, FileMode.Create); PdfWriter writer = PdfWriter.GetInstance(document, fs); document.SetPageSize(new Rectangle(358, 418));//1/0.9 288, 437 document.Open(); document.NewPage(); iTextSharp.text.io.StreamUtil.AddToResourceSearch(Assembly.Load("iTextAsian")); iTextSharp.text.io.StreamUtil.AddToResourceSearch(Assembly.Load("iTextAsianCmaps")); BaseFont baseFT = BaseFont.CreateFont("C:/WINDOWS/Fonts/Arial.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); Font arial = FontFactory.GetFont("Arial"); //BaseFont baseFT = BaseFont.CreateFont(BaseFont.TIMES_ROMAN,BaseFont.CP1252, false); iTextSharp.text.Font font = new iTextSharp.text.Font(baseFT, 15); //大的table PdfPTable table = new PdfPTable(1); table.WidthPercentage = 100; table.TotalWidth = 286; //101mm //code128 client //Code128B co128 = new Code128B(); ////co128.ValueFont = new System.Drawing.Font("宋体", 20); //System.Drawing.Bitmap imgTemp = co128.GetCodeImage(this.ClientBarcodeNumber, Code128B.Encode.Code128A);//Code128S传入,不能有“|”??? //iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance((System.Drawing.Image)imgTemp, iTextSharp.text.BaseColor.WHITE); PdfPCell cell; //PdfPTable code128Table = new PdfPTable(1); ////code128Table.TotalWidth = 286; //////img.ScalePercent(70f); //img.ScaleAbsoluteHeight(28f);//10mm //img.ScaleAbsoluteWidth(193);//68mm //cell = new PdfPCell(img); //cell.BorderWidthBottom = 0; //cell.BorderWidthTop = 0; //cell.BorderWidthRight = 0; //cell.BorderWidthLeft = 0; //cell.Colspan = 1; //cell.HorizontalAlignment = Element.ALIGN_CENTER; //code128Table.AddCell(cell); //cell = new PdfPCell(new Phrase(this.ClientBarcodeNumber.ToUpper(), new Font(baseFT, 10))); //cell.BorderWidthTop = 0; //cell.BorderWidthBottom = 0; //cell.BorderWidthLeft = 0; //cell.BorderWidthRight = 0; //cell.HorizontalAlignment = Element.ALIGN_CENTER; //cell.PaddingTop = 2f; //cell.FixedHeight = 21f;//总高度8mm //code128Table.AddCell(cell); //cell = new PdfPCell(code128Table); ////cell.BorderWidthLeft = 0; ////cell.BorderWidthTop = 0; ////cell.BorderWidthBottom = 0; ////cell.BorderWidthRight = 0; //cell.PaddingTop = 15; //cell.FixedHeight = 70f;//总的高度为 mm //table.AddCell(cell); ////128 client二维码部分完成 //Console.WriteLine("128二维码部分完成"); //第二部分 clientName那一行 PdfPTable table2 = new PdfPTable(2); table2.SetWidths(new int[] { 70, 30 }); Phrase phrase = new Phrase(this.ClientName, new Font(baseFT, 15, Font.BOLD)); cell = new PdfPCell(phrase); cell.BorderWidthTop = 0; cell.BorderWidthBottom = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.PaddingTop = 8; cell.PaddingLeft = 5; table2.AddCell(cell); string path = AppDomain.CurrentDomain.BaseDirectory + "\\image\\images\\collect_plus_logo.png"; //Console.WriteLine(path); Image collect_plus_logo = Image.GetInstance(path); collect_plus_logo.ScaleAbsoluteHeight(30f); collect_plus_logo.ScaleAbsoluteWidth(75f); cell = new PdfPCell(collect_plus_logo); cell.BorderWidthTop = 0; cell.BorderWidthBottom = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.PaddingTop = 0; cell.PaddingBottom = 3; table2.AddCell(cell); table.AddCell(table2); PdfPTable table3 = new PdfPTable(2); table3.SetWidths(new int[] { 40, 60 }); // 设置各列宽度,单位是百分比 PdfPTable tableLeft = new PdfPTable(1); PdfPTable tableRight = new PdfPTable(1); Chunk chunk1 = new Chunk("Depot\n", new Font(baseFT, 10)); Chunk chunk2 = new Chunk(this.RoutDepotNumber + " " + this.RoutDepotName, new Font(baseFT, 15, Font.BOLD)); Chunk chunk3; Chunk chunk4; Chunk chunk5; Chunk chunk6; phrase = new Phrase(); phrase.Add(chunk1); phrase.Add(chunk2); cell = new PdfPCell(phrase); cell.PaddingBottom = 10; tableLeft.AddCell(cell); chunk1 = new Chunk("Label Date\n", new Font(baseFT, 10)); chunk2 = new Chunk(this.LabelDate, new Font(baseFT, 15, Font.BOLD)); phrase = new Phrase(); phrase.Add(chunk1); phrase.Add(chunk2); cell = new PdfPCell(phrase); cell.PaddingBottom = 5; tableLeft.AddCell(cell); chunk1 = new Chunk("Returns Reference\n", new Font(baseFT, 10)); chunk2 = new Chunk(this.ReturnsReference, new Font(baseFT, 15, Font.BOLD)); phrase = new Phrase(); phrase.Add(chunk1); phrase.Add(chunk2); cell = new PdfPCell(phrase); cell.PaddingBottom = 5; tableLeft.AddCell(cell); chunk1 = new Chunk("Lydia\n".ToUpper(), new Font(baseFT, 10)); chunk2 = new Chunk("The Old Bus Garage\n".ToUpper(), new Font(baseFT, 10)); chunk3 = new Chunk("Harborne Lane\n".ToUpper(), new Font(baseFT, 10)); chunk4 = new Chunk("Selly Oak\n".ToUpper(), new Font(baseFT, 10)); chunk5 = new Chunk("Birmingham\n".ToUpper(), new Font(baseFT, 10)); chunk6 = new Chunk("B29 6SN", new Font(baseFT, 20, Font.BOLD)); phrase = new Phrase(); phrase.Add(chunk1); phrase.Add(Chunk.NEWLINE.setLineHeight(3)); phrase.Add(chunk2); phrase.Add(Chunk.NEWLINE.setLineHeight(3)); phrase.Add(chunk3); phrase.Add(Chunk.NEWLINE.setLineHeight(3)); phrase.Add(chunk4); phrase.Add(Chunk.NEWLINE.setLineHeight(3)); phrase.Add(chunk5); phrase.Add(chunk6); cell = new PdfPCell(phrase); cell.PaddingTop = 10; cell.PaddingBottom = 10; tableRight.AddCell(cell); //去除边框 cell = new PdfPCell(tableLeft); cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthBottom = 0; cell.BorderWidthRight = 0; table3.AddCell(cell); cell = new PdfPCell(tableRight); cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthBottom = 0; cell.BorderWidthRight = 0; table3.AddCell(cell); cell = new PdfPCell(table3); cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthBottom = 0; cell.BorderWidthRight = 0; //第三大行完成 table.AddCell(cell); //第四行 Storekeeper Instruction PdfPTable table4 = new PdfPTable(1); chunk1 = new Chunk("Storekeeper Instruction\n", new Font(baseFT, 8, Font.BOLD)); chunk2 = new Chunk("GIVE TO THE DRIVER", new Font(baseFT, 15, Font.BOLD)); phrase = new Phrase(); phrase.Add(chunk1); phrase.Add(Chunk.NEWLINE.setLineHeight(5)); phrase.Add(chunk2); cell = new PdfPCell(phrase); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthBottom = 0; cell.BorderWidthRight = 0; cell.PaddingTop = 3; cell.PaddingBottom = 10; table4.AddCell(cell); table.AddCell(table4); //第五行,二维码部分 //第五行,头一行文字 PdfPTable table5 = new PdfPTable(1); phrase = new Phrase("COLLECTION+ BARCODE BELOW", new Font(baseFT, 12, Font.BOLD)); cell = new PdfPCell(phrase); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthBottom = 0; cell.BorderWidthRight = 0; cell.PaddingTop = 10; cell.PaddingBottom = 15; table5.AddCell(cell); //第五部分collectBarcode Code128B collectBarcode = new Code128B(); //co128.ValueFont = new System.Drawing.Font("宋体", 20); System.Drawing.Bitmap imgCollectBarcode = collectBarcode.GetCodeImage(this.BarcodeNumber, Code128B.Encode.Code128A);//Code128S传入,不能有“|”??? iTextSharp.text.Image imgcollectBarcode = iTextSharp.text.Image.GetInstance(imgCollectBarcode, iTextSharp.text.BaseColor.WHITE); imgcollectBarcode.ScaleAbsoluteHeight(77f); //27mm imgcollectBarcode.ScaleAbsoluteWidth(199f); //70.2mm cell = new PdfPCell(imgcollectBarcode); cell.BorderWidthBottom = 0; cell.BorderWidthTop = 0; cell.BorderWidthRight = 0; cell.BorderWidthLeft = 0; cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; table5.AddCell(cell); //第五部分CodeString this.BarcodeNumber = this.BarcodeNumber.Replace("0", "Ø"); phrase = new Phrase(this.BarcodeNumber, new Font(baseFT, 15, Font.BOLD));//"883KØØØØ7116AØ51" cell = new PdfPCell(phrase); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthBottom = 0; cell.BorderWidthRight = 0; cell.PaddingTop = 10; cell.PaddingBottom = 10; table5.AddCell(cell); table.AddCell(table5); document.Add(table); document.Close(); Console.WriteLine("全部完成"); }
public static void toPdf(string fileName, IReadOnlyList <string> input) { /* * //A4サイズを横向きで * Document pdfDocument = new Document(PageSize.A4.Rotate(), 0, 0, 0, 0); * * //出力先のファイル名 * FileStream fileStream = new FileStream(fileName, FileMode.Create); * PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, fileStream); * * //PDFドキュメントを開く * pdfDocument.Open(); * * foreach(string list in input) * { * pdfDocument.Add(new Paragraph(list)); * } * * //PDFドキュメントを閉じる * pdfDocument.Close(); */ //A4サイズを横向きで Document pdfDocument = new Document(PageSize.A4.Rotate(), 0, 0, 0, 0); //出力先のファイル名 FileStream fileStream = new FileStream(fileName, FileMode.Create); PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, fileStream); //PDFドキュメントを開く pdfDocument.Open(); //フォント名 string fontName = "MS ゴシック"; //フォントサイズ float fontSize = 20.0f; //フォントスタイル。 複合するときは、&で。 int fontStyle = iTextSharp.text.Font.BOLD;// &iTextSharp.text.Font.ITALIC; //フォントカラー BaseColor baseColor = BaseColor.BLACK; //Fontフォルダを指定 FontFactory.RegisterDirectory(Environment.SystemDirectory.Replace("system32", "fonts")); //フォントの設定 iTextSharp.text.Font font = FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, //横書き BaseFont.NOT_EMBEDDED, //フォントを組み込まない fontSize, fontStyle, baseColor); PdfContentByte pdfContentByte = pdfWriter.DirectContent; ColumnText columnText = new ColumnText(pdfContentByte); int rangeCounter = 0; //SetSimpleColumnで出力 foreach (string list in input) { columnText.SetSimpleColumn( new Phrase(list, font) , 50 // X1位置 , 50 // Y1位置 , 500 // X2位置 , 550 - rangeCounter * fontSize // Y2位置 , fontSize , Element.ALIGN_LEFT //ちなみに、SetSimpleColumnでは、ALIGN_MIDDLE(縦方向の中寄せ)は使えない ); //テキスト描画 columnText.Go(); rangeCounter++; } //PDFドキュメントを閉じる pdfDocument.Close(); }
private void getPDF() { System.Drawing.Font font = new System.Drawing.Font("Microsoft Sans Serif", 12); iTextSharp.text.pdf.BaseFont bfR, bfR1, bfRB; iTextSharp.text.BaseColor clrBlack = new iTextSharp.text.BaseColor(0, 0, 0); //MemoryStream ms = new MemoryStream(); string myFont = Environment.CurrentDirectory + "\\THSarabun.ttf"; string myFontB = Environment.CurrentDirectory + "\\THSarabun Bold.ttf"; String hn = "", name = "", doctor = "", fncd = "", birthday = "", dsDate = "", dsTime = "", an = ""; decimal total = 0; bfR = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bfR1 = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bfRB = BaseFont.CreateFont(myFontB, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); iTextSharp.text.Font fntHead = new iTextSharp.text.Font(bfR, 12, iTextSharp.text.Font.NORMAL, clrBlack); String[] aa = dsDate.Split(','); if (aa.Length > 1) { dsDate = aa[0]; an = aa[1]; } String[] bb = dsDate.Split('*'); if (bb.Length > 1) { dsDate = bb[0]; dsTime = bb[1]; } var logo = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\LOGO-BW-tran.jpg"); logo.SetAbsolutePosition(10, PageSize.A4.Height - 90); logo.ScaleAbsoluteHeight(70); logo.ScaleAbsoluteWidth(70); FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4, 36, 36, 36, 36); try { FileStream output = new FileStream(Environment.CurrentDirectory + "\\" + txtHn.Text.Trim() + ".pdf", FileMode.Create); PdfWriter writer = PdfWriter.GetInstance(doc, output); doc.Open(); //PdfContentByte cb = writer.DirectContent; //ColumnText ct = new ColumnText(cb); //ct.Alignment = Element.ALIGN_JUSTIFIED; //Paragraph heading = new Paragraph("Chapter 1", fntHead); //heading.Leading = 30f; //doc.Add(heading); //Image L = Image.GetInstance(imagepath + "/l.gif"); //logo.SetAbsolutePosition(doc.Left, doc.Top - 180); doc.Add(logo); //doc.Add(new Paragraph("Hello World", fntHead)); Chunk c; String foobar = "Foobar Film Festival"; //float width_helv = bfR.GetWidthPoint(foobar, 12); //c = new Chunk(foobar + ": " + width_helv, fntHead); //doc.Add(new Paragraph(c)); //if (dt.Rows.Count > 24) //{ // doc.NewPage(); // doc.Add(new Paragraph(string.Format("This is a page {0}", 2))); //} int i = 0, r = 0, row2 = 0, rowEnd = 24; //r = dt.Rows.Count; int next = r / 24; int linenumber = 800, colCenter = 200, fontSize1 = 14, fontSize2 = 14; PdfContentByte canvas = writer.DirectContent; canvas.BeginText(); canvas.SetFontAndSize(bfR, 12); canvas.ShowTextAligned(Element.ALIGN_LEFT, "โรงพยาบาล บางนา5 55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, linenumber, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, 780, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "BANGNA 5 GENERAL HOSPITAL 55 M.4 Theparuk Road, Bangplee, Samutprakan Thailand0", 100, linenumber - 20, 0); canvas.EndText(); linenumber = 720; canvas.BeginText(); canvas.SetFontAndSize(bfR, fontSize2); canvas.ShowTextAligned(Element.ALIGN_CENTER, "ใบรับรองแพทย์", PageSize.A4.Width / 2, linenumber + 20, 0); canvas.ShowTextAligned(Element.ALIGN_CENTER, "การตรวจสุขภาพแรงงานต่างด้าว", PageSize.A4.Width / 2, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_CENTER, "สถานที่ตรวจ โรงพยาบาลบางนา 5", PageSize.A4.Width / 2, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_CENTER, "วันที่ตรวจ " + dtpDate.Value.Day.ToString() + " " + bc.getMonth(dtpDate.Value.Month.ToString("00")) + " พ.ศ. " + (dtpDate.Value.Year + 543), PageSize.A4.Width / 2, linenumber -= 20, 0); canvas.EndText(); linenumber = 660; canvas.BeginText(); canvas.SetFontAndSize(bfRB, fontSize2); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "วันที่ตรวจ " + dtpDate.Value.Day.ToString() + " เดือน " + bc.cf.getMonth(dtpDate.Value.Month.ToString("00")) + " พ.ศ. " + (dtpDate.Value.Year + 543), 400, linenumber + 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ชื่อ ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................................................................................................ ", 75, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text.Trim(), 93, linenumber, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "เพศ [ ]ชาย [ ]หญิง สถานภาพ [ ]โสด [ ]สมรส [ ]อื่นๆ ", 300, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "เพศ ", 355, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ]ชาย [ ]หญิง ", 380, linenumber, 0); if (txtSex.Text.ToUpper().Equals("M")) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); } else { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 420, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); } canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "เลขที่บัตรประจำตัวบุคลผู้ไม่มีสัญชาติไทย ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR1, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".......................................................... ", 218, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtId.Text.Trim(), 221, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "เลข Passport ", 355, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "............................................................. ", 410, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPassport.Text.Trim(), 413, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "สัญชาติ ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................... ", 90, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, cboNation.Text.Trim(), 93, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "เชื้อชาติ ", 220, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................................ ", 253, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, cboRace.Text.Trim(), 253, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "สถานภาพ ", 385, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................... ", 425, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, cboMar.Text.Trim(), 428, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "วัน/เดือน/ปี เกิด ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................ ", 122, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, bc.datetoShow2(txtDOB.Text), 125, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "อายุ ", 220, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................. ", 240, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAge.Text + " ปี", 243, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ชื่อนายจ้าง (บริษัท) ", 320, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................... ", 395, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, cboCompany.Text, 418, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ที่อยู่ของนายจ้าง ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR1, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................................................................................................................................................................... ", 125, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddr1.Text, 128, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "....................................................................................................................................................................................................................... ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddr2.Text, 63, linenumber + 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ที่อยู่ต่างประเทศ ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................................................................................................................................................................... ", 125, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddress.Text, 128, linenumber, 0); linenumber -= 20; canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจสุขภาพ ", (PageSize.A4.Width / 2) - 30, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ความสูง ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".............. ", 93, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtHeight.Text, 96, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ชม. น้ำหนัก ", 125, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "................... ", 180, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtWeight.Text, 183, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "กก. ความดันโลหิต ", 225, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "..................... ", 303, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtBloodPressure.Text, 306, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "มม.ปรอท ชีพจร ", 350, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "................... ", 420, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPulse.Text, 423, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ครั้ง / นาที ", 465, linenumber, 0); linenumber -= 20; canvas.SetFontAndSize(bfRB, fontSize2); //canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text.Trim(), 153, linenumber + 2, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ปรากฏว่า ไม่เป็นผู้ทุพพลภาพ ไร้ความสามารถ จิตฟั่นเฟือน ไม่สมประกอบ และปราศจากโรคเหล่านี้ ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "และปราศจากโรคเหล่านี้ ", 60, linenumber -= 20, 0); //linenumber = 580; if (truestar.Equals("truestar")) { leftp = 60; canvas.ShowTextAligned(Element.ALIGN_LEFT, "1. โรคเรื้อนในระยะติดต่อหรือในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม (Leprosy) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ปกติ [ ] ผิดปกติ [ ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0); if (chk1Normal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0); } else if (chk1AbNormal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0); } else if (chk1Repeat.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0); } canvas.ShowTextAligned(Element.ALIGN_LEFT, "2. วัณโรคปอดในระยะติดต่อ (Active pulmonary tuberculosis) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ปกติ [ ] ผิดปกติ [ ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0); if (chk2Normal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0); } else if (chk2AbNormal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0); } else if (chk2Repeat.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0); } canvas.ShowTextAligned(Element.ALIGN_LEFT, "3. โรคติดยาเสพติดให้โทษ (Drug addiction) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ปกติ [ ] ผิดปกติ [ ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0); if (chk3Normal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0); } else if (chk3AbNormal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0); } else if (chk3Repeat.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0); } canvas.ShowTextAligned(Element.ALIGN_LEFT, "4. โรคพิษสุราเรื้อรัง (Chronic alcoholism) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ปกติ [ ] ผิดปกติ", 380, linenumber, 0); if (chk4Normal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0); } else if (chk4AbNormal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0); } //else if (chk4Repeat.Checked) //{ // canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0); //} canvas.ShowTextAligned(Element.ALIGN_LEFT, "5. โรคเท้าช้างในระยะที่ปรากฏอาการที่เป็นที่รังเกียจแก่สังคม (Filariasis) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ปกติ [ ] ผิดปกติ [ ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0); if (chk5Normal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0); } else if (chk5AbNormal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0); } else if (chk5Repeat.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0); } canvas.ShowTextAligned(Element.ALIGN_LEFT, "6. ซิฟิลิสในระยะที่ 3 (Syphilis Latent)", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ปกติ [ ] ผิดปกติ [ ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0); if (chk6Normal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0); } else if (chk6AbNormal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0); } else if (chk6Repeat.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0); } canvas.ShowTextAligned(Element.ALIGN_LEFT, "7. โรคจิตฟั่นเฟือนหรือปัญญาอ่อน (Schizophrenia or Mental Retardation)", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ปกติ [ ] ผิดปกติ", 380, linenumber, 0); if (chk7Normal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0); } else if (chk7AbNormal.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0); } //else if (chk7Repeat.Checked) //{ // canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0); //} } else { leftp = 150; canvas.ShowTextAligned(Element.ALIGN_LEFT, "1. โรคเรื้อนในระยะติดต่อหรือในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม (Leprosy) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "2. วัณโรคปอดในระยะติดต่อ (Active pulmonary tuberculosis) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "3. โรคติดยาเสพติดให้โทษ (Drug addiction) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "4. โรคพิษสุราเรื้อรัง (Chronic alcoholism) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "5. โรคเท้าช้างในระยะที่ปรากฏอาการที่เป็นที่รังเกียจแก่สังคม (Filariasis) ", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "6. ซิฟิลิสในระยะที่ 3 (Syphilis Latent)", leftp, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "7. โรคจิตฟั่นเฟือนหรือปัญญาอ่อน (Schizophrenia or Mental Retardation)", leftp, linenumber -= 20, 0); } canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "หมายเหตุ : สำหรับสตรี", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจตั้งครรภ์ [ ]ไม่พบการตั้งครรภ์ [ ]พบการตั้งครรภ์", 170, linenumber, 0); canvas.SetFontAndSize(bfRB, fontSize2); if (chkPregOn.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 252, linenumber, 0); } else if (chkPregOff.Checked) { canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 335, linenumber, 0); } //canvas.SetFontAndSize(bfR, fontSize1); //canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "สรุปผลการตรวจ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] สุขภาพสมบูรณ์ดี", 200, linenumber -= 20, 0); if (chk1.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); } canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ผ่านการตรวจสุขภาพ แต่ต้องติดตามผลการตรวจยืนยัน และให้การรักษา", 200, linenumber -= 20, 0); if (chk2.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); } canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] ไม่ผ่านเพราะ....................................................................", 200, linenumber -= 20, 0); if (chk3.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); } canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] สุขภาพไม่สมบูรณ์แข็งแรง ที่เป็นอุปสรรคต่อการทำงาน", 200, linenumber -= 20, 0); if (chk4.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); } canvas.ShowTextAligned(Element.ALIGN_LEFT, "[ ] เป็นโรคต้องห้ามมิให้ทำงาน (ตามประกาศกระทรวงสาธารณสุข)", 200, linenumber -= 20, 0); if (chk5.Checked) { canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); } canvas.EndText(); //canvas.BeginText(); //canvas.SaveState(); canvas.SetLineWidth(0.05f); canvas.MoveTo(80, 140); //vertical canvas.LineTo(80, 225); canvas.MoveTo(80, 140); //Hericental canvas.LineTo(150, 140); canvas.MoveTo(80, 225); //Hericental canvas.LineTo(150, 225); canvas.MoveTo(150, 140); //vertical canvas.LineTo(150, 225); //canvas.MoveTo(560, 640);//vertical //canvas.LineTo(560, 110); //canvas.Stroke(); //canvas.RestoreState(); canvas.BeginText(); linenumber -= 20; linenumber -= 20; canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผู้เข้ารับการตรวจ ................................................... ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "แพทย์ผู้ตรวจ ...................................................", colCenter + 180, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(.....................................................)", 120, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(.........................................................)", colCenter + 220, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorName.Text.Trim(), colCenter + 225, linenumber + 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ใบรับรองแพทย์ฉบับนี้ให้ใช้ได้ 60 วันนับแต่วันที่ตรวจร่างกาย", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "วันที่ .........................................................", colCenter + 200, linenumber, 0); //canvas.SetFontAndSize(bfRB, fontSize2); //canvas.ShowTextAligned(Element.ALIGN_LEFT, cboCompany.Text.Trim(), colCenter, linenumber + 5, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "ตรวจสมรรถภาพการทำงานของปอด ", 60, linenumber -= 20, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, txtLung.Text.Trim(), 160, linenumber, 0); //linenumber -= 5; //canvas.SetFontAndSize(bfR, fontSize1); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "บันทึกสัญญาณชีพ ", 60, linenumber -= 20, 0); //String aaaa = "H.Rate: ครั้ง/min BP: mmHg "; //if (!txtPulse.Text.Equals("")) //{ // //String[] aaa = txtPulse.Text.Split('/'); // aaaa = "H.Rate: " + txtPulse.Text + " ครั้ง/min R.Rate: " + txtBreath.Text + " ครั้ง/min BP: " + txtBloodPressure.Text + " mmHg "; //} //canvas.ShowTextAligned(Element.ALIGN_LEFT, "...............................................................................................", colCenter + 70, linenumber - 3, 0); //canvas.SetFontAndSize(bfRB, fontSize2); //canvas.ShowTextAligned(Element.ALIGN_LEFT, aaaa, colCenter + 70, linenumber + 2, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "WT: " + txtWeight.Text + " Kgs HT: " + txtHeight.Text + " Cms", colCenter + 70, (linenumber -= 20) + 2, 0); //canvas.SetFontAndSize(bfR, fontSize1); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "...............................................................................................", colCenter + 70, linenumber - 3, 0); //linenumber = 100; ////canvas.SetFontAndSize(bfR, 12); ////canvas.ShowTextAligned(Element.ALIGN_LEFT, "มีอายุการใช้งาน 3 เดือน (VALID FOR THREE MONTHS) ", 60, linenumber -= 20, 0); //canvas.SetFontAndSize(bfR, fontSize1); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "ลายมือชื่อ ....................................................... ", 370, linenumber - 3, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "Signature " + txtDoctorName.Text.Trim(), 370, linenumber, 0); ////canvas.SetFontAndSize(bfR, 12); ////canvas.ShowTextAligned(Element.ALIGN_LEFT, "ISO 9001:2000 ทุกหน่วยงาน ", 60, linenumber -= 20, 0); ////canvas.SetFontAndSize(bfR, fontSize1); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "(แพทย์ผู้ตรวจ) ", 420, linenumber, 0); canvas.EndText(); canvas.Stroke(); //canvas.RestoreState(); //pB1.Maximum = dt.Rows.Count; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { doc.Close(); Process p = new Process(); ProcessStartInfo s = new ProcessStartInfo(Environment.CurrentDirectory + "\\" + txtHn.Text.Trim() + ".pdf"); //s.Arguments = "/c dir *.cs"; p.StartInfo = s; //p.StartInfo.Arguments = "/c dir *.cs"; //p.StartInfo.UseShellExecute = false; //p.StartInfo.RedirectStandardOutput = true; p.Start(); //string output = p.StandardOutput.ReadToEnd(); //p.WaitForExit(); //Application.Exit(); } }
public void AddTextToPdfStamper(DataRow dataRow) { FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); //variables string pathin = txtTemplateUrl.Text; string pathout = $"{txtOutputFolderUrl.Text}\\{dataRow[0].ToString()}.pdf"; //create PdfReader object to read from the existing document using (PdfReader reader = new PdfReader(pathin)) //create PdfStamper object to write to get the pages from reader using (PdfStamper stamper = new PdfStamper(reader, new FileStream(pathout, FileMode.Create))) { //select two pages from the original document reader.SelectPages("1-2"); //gettins the page size in order to substract from the iTextSharp coordinates var pageSize = reader.GetPageSize(1); // PdfContentByte from stamper to add content to the pages over the original content PdfContentByte pbover = stamper.GetOverContent(1); //add content to the page using ColumnText var fontName = FontFactory.GetFont(txtFintName.Text, float.Parse(txtFontSize.Text)); fontName.Size = float.Parse(txtFontSize.Text); //setting up the X and Y coordinates of the document int x = int.Parse(txtXPosition.Text); int y = int.Parse(txtYPosition.Text); y = (int)(pageSize.Height - y); if (!string.IsNullOrEmpty(dataRow[0].ToString())) { ColumnText.ShowTextAligned(pbover, Element.ALIGN_CENTER, new Phrase(dataRow[0].ToString(), fontName), x, y, 0); } var fontDate = FontFactory.GetFont(txtFintName.Text, float.Parse(txtFontSizeDate.Text)); fontDate.Size = float.Parse(txtFontSizeDate.Text); //setting up the X and Y coordinates of the document x = int.Parse(txtDateXPostion.Text); y = int.Parse(txtDateYPosition.Text); y = (int)(pageSize.Height - y); if (!string.IsNullOrEmpty(dataRow[1].ToString())) { ColumnText.ShowTextAligned(pbover, Element.ALIGN_CENTER, new Phrase(dataRow[1].ToString(), fontDate), x, y, 0); } var fontNumbers = FontFactory.GetFont(txtFintName.Text, float.Parse(txtFontSizeNumbers.Text)); fontNumbers.Size = float.Parse(txtFontSizeNumbers.Text); //setting up the X and Y coordinates of the document x = int.Parse(txtXPositionSace.Text); y = int.Parse(txtYPositionSace.Text); y = (int)(pageSize.Height - y); if (!string.IsNullOrEmpty(dataRow[2].ToString())) { ColumnText.ShowTextAligned(pbover, Element.ALIGN_LEFT, new Phrase("SACE No: " + dataRow[2].ToString(), fontNumbers), x, y, 0); } fontNumbers = FontFactory.GetFont(txtFintName.Text, float.Parse(txtFontSizeNumbers.Text)); fontNumbers.Size = float.Parse(txtFontSizeNumbers.Text); //setting up the X and Y coordinates of the document x = int.Parse(txtXPosHPCSA.Text); y = int.Parse(txtYPosHPCSA.Text); y = (int)(pageSize.Height - y); if (!string.IsNullOrEmpty(dataRow[3].ToString())) { ColumnText.ShowTextAligned(pbover, Element.ALIGN_LEFT, new Phrase("HPCSA No: " + dataRow[3].ToString(), fontNumbers), x, y, 0); } } }
protected void btTatCa_Click(object sender, EventArgs e) { string sql = ""; sql += @"select * from(select ROW_NUMBER() OVER(ORDER BY ChiTietPhieuXuat.NgayXuatChiTiet asc)AS RowNumber,HangHoa.TenHangHoa,HangHoa.IDHangHoa,PhieuXuat.MaPhieuXuat,ChiTietPhieuXuat.SoLuong,ChiTietPhieuXuat.DonGiaXuat,ChiTietPhieuXuat.NgayXuatChiTiet from ChiTietPhieuXuat left join HangHoa on ChiTietPhieuXuat.IDHangHoa = HangHoa.IDHangHoa left join PhieuXuat on ChiTietPhieuXuat.IDPhieuXuat = PhieuXuat.IDPhieuXuat where '1'='1'"; if (txtMaPhieu.Value.Trim() != "") { sql += " and PhieuXuat.MaPhieuXuat like N'%" + txtMaPhieu.Value.Trim() + "%'"; } // sql += "group by HangHoa.MaHangHoa,HangHoa.TenHangHoa,ChiTietPhieuXuat.NgayXuatChiTiet,ChiTietPhieuNhap.NgayNhapChiTiet,ChiTietPhieuXuat.IDChiTietPhieuXuat,HangHoa.IDHangHoa "; sql += " ) as tb1"; DataTable table = Connect.GetTable(sql); string HTMLContent = ""; //HTMLContent += "<table border='1'>"; DataTable NoiToi = Connect.GetTable("select top 1 KhachHang.TenKhachHang,PhongBan.TenPhongBan,CuaHang.TenCuaHang,CuaHang.DiaChi,PhongBan.DiaChiPhongBan,KhachHang.DiaChi as 'DiaChiKH' from ChiTietPhieuXuat left join KhachHang on ChiTietPhieuXuat.IDKhachHang = KhachHang.IDKhachHang left join PhongBan on ChiTietPhieuXuat.IDPhongBan = PhongBan.IDPhongBan left join CuaHang on ChiTietPhieuXuat.IDCuaHang = CuaHang.IDCuaHang where IDPhieuXuat = '" + StaticData.getFieldCoDau("PhieuXuat", "IDPhieuXuat", "MaPhieuXuat", txtMaPhieu.Value.Trim()) + "'"); string NoiGiao = ""; string DiaChi = ""; string NoiNhan = ""; if (NoiToi.Rows.Count > 0) { NoiGiao = NoiToi.Rows[0]["TenCuaHang"].ToString(); if (NoiToi.Rows.Count > 0) { NoiGiao = NoiToi.Rows[0]["TenCuaHang"].ToString(); if (NoiToi.Rows[0]["DiaChi"].ToString().Trim() != "") { DiaChi = NoiToi.Rows[0]["DiaChi"].ToString(); } else { if (NoiToi.Rows[0]["DiaChiPhongBan"].ToString().Trim() != "") { DiaChi = NoiToi.Rows[0]["DiaChiPhongBan"].ToString(); } else { DiaChi = NoiToi.Rows[0]["DiaChiKH"].ToString(); } } NoiNhan = NoiToi.Rows[0]["TenKhachHang"].ToString() + "_" + NoiToi.Rows[0]["TenPhongBan"].ToString(); } NoiNhan = NoiToi.Rows[0]["TenKhachHang"].ToString() + "_" + NoiToi.Rows[0]["TenPhongBan"].ToString(); } HTMLContent += @" <html><body encoding=" + BaseFont.IDENTITY_H + " style='font-family:Arial;font-size:10px;'>"; HTMLContent += @" <table style='border-color:#d4d4d4;border-collapse: collapse;' BORDERCOLOR='#d4d4d4' width='100%'> <tr> <td border='1' width='10%' ><img src='http://vienlien.lamphanmem.com/images/vienlien.png' width='30' height = '30'></td> <td> </td> <td> </td> <td style='text-align: left;' border='1' width='42%'><div><b>CÔNG TY CỔ PHẦN VIỄN LIÊN</b><div></td> <td style='text-align: center;' border='1' width='43%'><b>CỘNG HÒA XÃ HỘI CHỦ NGHĨA ViỆT NAM <b></td> </tr> </table> <br /> <table> <tr> <td style='font-size:15px;'>Số 32 Đường số 8 nhà ở Khu Z756, Phường 12, Q.10, Tp.Hồ Chí Minh</td> <td colspan='5' style='text-align: center;'><div>Độc lập - Tự do - Hạnh phúc </div></td> </tr> <tr> <td> </td> <td style='height:27px;width:306px;'><b><i><u>Tel</u></i></b> : 028 3620 8997 - <b><i><u>Fax</u></i></b> : 028 3620 8997</td> <td colspan='5' > </td> </tr> <tr> <td style='text-align: right;' >Số:</td> <td>" + txtMaPhieu.Value.Trim() + @"</td> <td> </td> <td colspan='4' style='text-align: right;'><i>Tp,HCM Ngày tháng năm </i></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td > </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td style='text-align: center; padding:15px 0px 15px 0px;' colspan='7' ><h2><b>BIÊN BẢN NGHIỆM THU & BÀN GIAO HÀNG HÓA</b></h2></td> </tr> <tr> <td> </td> <td colspan='5' ><h4><b>Bên giao : CÔNG TY CỔ PHẦN ViỄN LIÊN</b></h4></td> <td> </td> </tr> <tr> <td> </td> <td colspan='5'><h5><b>Bên nhận :" + NoiNhan + @"</b></h5></td> <td> </td> </tr> <tr> <td> </td><td colspan='5'>Địa chỉ giao hàng: " + DiaChi + @"</td> <td> </td> </tr> <tr> <td> </td> <td colspan='5'>Nơi nhận: " + NoiGiao + @"</td> <td> </td> </tr> <tr> <td colspan='5'><i>Cùng tiến hành kiểm tra chất lượng và số lượng của những mặt hàng sau :</i></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td > </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <th style='border-color:black'>STT</th> <th style='border-color:black'>DANH MỤC HÀNG HÓA</th> <th style='border-color:black'>ĐVT</th> <th style='border-color:black'>SỐ LƯỢNG</th> <th colspan='3' style='text-align: center;border-color:black;'>GHI CHÚ</th> </tr> "; for (int i = 0; i < table.Rows.Count; i++) { HTMLContent += " <tr >"; HTMLContent += " <td style='border-right-color: black'>" + (((Page - 1) * PageSize2) + i + 1).ToString() + "</td>"; HTMLContent += " <td style='border-right-color: black'>" + table.Rows[i]["TenHangHoa"].ToString() + "</td>"; // HTMLContent += " <td>" + DateTime.Parse(table.Rows[i]["NgayXuatChiTiet"].ToString()).ToString("dd/MM/yyyy") + "</td>"; // string IDMauSac = StaticData.getField("HangHoa", "IDMauSac", "IDHangHoa", table.Rows[i]["IDHangHoa"].ToString()); // string MauSac = StaticData.getField("MauSac", "TenMauSac", "IDMauSac", IDMauSac); // HTMLContent += " <td>" + MauSac + "</td>"; string IDDonViTinh = StaticData.getField("HangHoa", "IDDonViTinh", "IDHangHoa", table.Rows[i]["IDHangHoa"].ToString()); string DonViTinh = StaticData.getField("DonViTinh", "TenDonViTinh", "IDDonViTinh", IDDonViTinh); HTMLContent += " <td style='border-right-color: black'>" + DonViTinh + "</td>"; double a = double.Parse(table.Rows[i]["SoLuong"].ToString()); HTMLContent += " <td style='border-right-color: black'>" + string.Format("{0:N0}", (a)).Replace(",", ".") + "</td><td colspan='3' style='border-right-color: black'> </td> "; // DataTable gc = Connect.GetTable("select GhiChu from ChiTietPhieuXuat where IDChiTietPhieuXuat=" + table.Rows[i]["IDChiTietPhieuXuat"].ToString() + ""); HTMLContent += " </tr>"; } HTMLContent += @" <tr> <td> </td> <td> </td> <td> </td> <td > </td> <td> </td> <td> </td> </tr> <tr> <td colspan='2' style='text-align: left;'><b>ĐẠI DIỆN BÊN NHẬN HÀNG</b></td> <td> </td> <td colspan='4' style='text-align: center;'><b>ĐẠI DIỆN BÊN GIAO HÀNG</b></td> </tr> <tr> <td style='text-align: left;' colspan='2'> Người nhận hàng</td> <td> </td> <td style='text-align: center;' colspan='4'>Người giao hàng</td> </tr> </table> </body></html>"; string FileName = "BienBanGiaoHangHai"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); Response.AppendHeader("Content-Type", "application/pdf"); Response.AppendHeader("Content-disposition", "attachment; filename=" + FileName + ".pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); stringWrite.WriteLine(HTMLContent); HtmlTextWriter hw = new HtmlTextWriter(stringWrite); StringReader sr = new StringReader(stringWrite.ToString()); Document pdfDoc = new Document(PageSize.A4, 20f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter wi = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); //string fontpath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts) + "\\ARIALUNI.TTF"; // "ARIALUNI.TTF" file copied from fonts folder and placed in the folder string fontpath = "http://vienlien.lamphanmem.com/Fonts/ARIALUNI.TTF"; // "ARIALUNI.TTF" file copied from fonts folder and placed in the folder BaseFont bf = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); FontFactory.RegisterDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), true); FontFactory.Register(fontpath, "Arial Unicode MS"); //string path = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/ArialUni.TFF"); //iTextSharp.text.Font fnt = new iTextSharp.text.Font(); //FontFactory.Register(path, "Arial Unicode MS"); //fnt = FontFactory.GetFont("Arial Unicode MS", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10, Font.NORMAL); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); /* Response.AppendHeader("content-disposition", "attachment;filename=BienBanGiaoHangHai.xls"); * Response.Charset = ""; * Response.Cache.SetCacheability(HttpCacheability.NoCache); * Response.ContentType = "application/vnd.ms-excel"; * this.EnableViewState = false; * Response.Write(HTMLContent); * Response.End();*/ }
private void CreateAttachmentNr7(string officialPositionWhoGetNewNotification, string numberLastNotification, int howManyMonthsAnimalLive, string savePath) //tworzymy załącznik numer 7 { System.IO.FileStream fs = new FileStream(savePath + numberLastNotification + "-" + mainWindow.txtFarmNumber.Text + "-zal7-" + savingDateTime + ".pdf", FileMode.Create); // tworzymy instancje klasy dokumentu pdf z wymiarem A4 Document document = new Document(PageSize.A4, 25, 25, 30, 30); // klasa writer używająca dokument i strumienia w konstruktorze PdfWriter writer = PdfWriter.GetInstance(document, fs); // otwórz dokument document.Open(); // dodajemy zawartość FontFactory.RegisterDirectory("C:WINDOWSFonts"); //dodajemy polskie znaki var polskie_znaki = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Phrase("Rejestr zgłoszeń padłego bydła - załącznik 7\n ", polskie_znaki)); cell.Colspan = 2; cell.Border = 0; cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right table.AddCell(cell); table.AddCell(new Phrase("Numer dokumentu", polskie_znaki)); table.AddCell("1608/" + numberLastNotification + "/2019"); table.AddCell(new Phrase("Data i godzina przyjęcia zgłoszenia", polskie_znaki)); table.AddCell(mainWindow.txtDateAndTimeNewNotificationOfAnimalDead.Text); table.AddCell(new Phrase("Powiatowy Inspektorat Weterynarii w ", polskie_znaki)); table.AddCell(new Phrase("Oleśnie", polskie_znaki)); PdfPCell cell2 = new PdfPCell(new Phrase("\nOsoba zgłaszająca", polskie_znaki)); cell2.Colspan = 2; cell2.Border = 0; cell2.HorizontalAlignment = 0; table.AddCell(cell2); table.AddCell(new Phrase("Imię i nazwisko", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtWhoReportingNewNotification.Text, polskie_znaki)); table.AddCell(new Phrase("Adres zam.", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtAddressPersonReporting.Text, polskie_znaki)); table.AddCell(new Phrase("Telefon", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtPhonePersonReporting.Text, polskie_znaki)); PdfPCell cell3 = new PdfPCell(new Phrase("\nOsoba przyjmująca zgłoszenie", polskie_znaki)); cell3.Colspan = 2; cell3.Border = 0; cell3.HorizontalAlignment = 0; table.AddCell(cell3); table.AddCell(new Phrase("Imię i nazwisko", polskie_znaki)); table.AddCell(new Phrase(mainWindow.comboBox_WhoGetGetNotification.Text, polskie_znaki)); table.AddCell(new Phrase("Stanowisko służbowe", polskie_znaki)); table.AddCell(new Phrase(officialPositionWhoGetNewNotification, polskie_znaki)); PdfPCell cell4 = new PdfPCell(new Phrase("\nMiejsce padnięcia zwierzęcia – adres gospodarstwa", polskie_znaki)); cell4.Colspan = 2; cell4.Border = 0; cell4.HorizontalAlignment = 0; table.AddCell(cell4); table.AddCell(new Phrase("Imię i nazwisko posiadacza zwierzęcia", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtName.Text + ' ' + mainWindow.txtSurname.Text, polskie_znaki)); table.AddCell(new Phrase("Adres gospodarstwa/nr siedziby stada", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtStreet.Text + ' ' + mainWindow.txtHouseNumber.Text + ' ' + mainWindow.txtLocalNumber.Text + ' ' + mainWindow.txtPostCode.Text + ' ' + mainWindow.txtPost.Text + '/' + mainWindow.txtFarmNumber.Text, polskie_znaki)); table.AddCell(new Phrase("miejscowość", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtCity.Text, polskie_znaki)); table.AddCell(new Phrase("powiat", polskie_znaki)); table.AddCell(new Phrase("olesno", polskie_znaki)); table.AddCell(new Phrase("województwo", polskie_znaki)); table.AddCell(new Phrase("opolskie", polskie_znaki)); PdfPCell cell5 = new PdfPCell(new Phrase("\nOpis gospodarstwa", polskie_znaki)); cell5.Colspan = 2; cell5.Border = 0; cell5.HorizontalAlignment = 0; table.AddCell(cell5); table.AddCell(new Phrase("Rodzaj produkcji", polskie_znaki)); table.AddCell(new Phrase(mainWindow.comboBox_TypeOfFarm.Text, polskie_znaki)); table.AddCell(new Phrase("Liczba sztuk", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtHowManyAnimalsInFarm.Text, polskie_znaki)); PdfPCell cell6 = new PdfPCell(new Phrase("\nIdentyfikacja padłego zwierzęcia", polskie_znaki)); cell6.Colspan = 2; cell6.Border = 0; cell6.HorizontalAlignment = 0; table.AddCell(cell6); table.AddCell(new Phrase("nr kolczyka zwierzęcia", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtFarmNumber.Text, polskie_znaki)); table.AddCell(new Phrase("data urodzenia i wiek", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtDateBorn.Text + " wiek: " + howManyMonthsAnimalLive + "miesięcy", polskie_znaki)); table.AddCell(new Phrase("płeć", polskie_znaki)); table.AddCell(new Phrase(mainWindow.comboBox_GenderOfDeadAnimal.Text, polskie_znaki)); table.AddCell(new Phrase("Data i godzina padnięcia", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtDateDead.Text + ' ' + mainWindow.txtHourOfDeadAnimal.Text, polskie_znaki)); table.AddCell(new Phrase("Przyczyna padnięcia", polskie_znaki)); table.AddCell(new Phrase(mainWindow.comboBox_DeadDeterminedOrNot.Text, polskie_znaki)); table.AddCell(new Phrase("Podać prawdopodobną przyczynę padnięcia", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtWhyDead.Text, polskie_znaki)); table.AddCell(new Phrase("Dodatkowe uwagi", polskie_znaki)); table.AddCell(new Phrase(mainWindow.txtComment.Text, polskie_znaki)); PdfPCell cell7 = new PdfPCell(new Phrase("Osoba przyjmująca zgłoszenie: \n " + mainWindow.comboBox_WhoGetGetNotification.Text, polskie_znaki)); cell7.Colspan = 2; cell7.Border = 0; cell7.HorizontalAlignment = 2; //0=Left, 1=Centre, 2=Right table.AddCell(cell7); document.Add(table); // zamknij dokument document.Close(); // zamknij writer writer.Close(); // zakmnij obsługiwane pliki fs.Close(); MessageBox.Show("Utworzono i zapisano załącznik nr 7."); }
/// <summary> /// Tworzy plik PDF o podanej nazwie w konstruktorze /// </summary> /// <param name="view">ListView z którego ma pobrać dane</param> public void createPDF(ListView view) { PdfPTable mainRaport = new PdfPTable(view.Columns.Count); mainRaport.DefaultCell.Padding = 5; mainRaport.WidthPercentage = 100; mainRaport.HorizontalAlignment = Element.ALIGN_LEFT; mainRaport.DefaultCell.BorderWidth = 1; FontFactory.RegisterDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Fonts)); Font fontHeader = FontFactory.GetFont("microsoft sans serif", BaseFont.IDENTITY_H, true, 12, Font.BOLD); Font fontText = FontFactory.GetFont("microsoft sans serif", BaseFont.IDENTITY_H, true, 10); Font header = FontFactory.GetFont("microsoft sans serif", BaseFont.IDENTITY_H, true, 32); //Adding Header row foreach (ColumnHeader column in view.Columns) { PdfPCell cell = new PdfPCell(new Phrase(this.FormatujNazweKolumny(column.Text), fontHeader)); mainRaport.AddCell(cell); } //Adding DataRow foreach (ListViewItem itemRow in view.Items) { for (int i = 0; i < itemRow.SubItems.Count; i++) { mainRaport.AddCell(new PdfPCell(new Phrase(itemRow.SubItems[i].Text, fontText))); } } using (Document pdfDoc = new Document(PageSize.A4)) { //Strona tytułowa PdfPTable frontPage = new PdfPTable(1); DateTime dateTime = DateTime.Now; frontPage.WidthPercentage = 100; var tempCell = new PdfPCell(new Paragraph(String.Format("Wygenerowano dnia {0:dd/MM/yyyy} o godzinie {0:H:m:s}", dateTime), fontText)); tempCell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; tempCell.Border = PdfPCell.NO_BORDER; frontPage.AddCell(tempCell); tempCell = new PdfPCell(new Paragraph("Raport wygenerowany dla " + nazwaRaportu, header)); tempCell.MinimumHeight = (pdfDoc.PageSize.Height - (pdfDoc.BottomMargin + pdfDoc.TopMargin)) - 30; tempCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; tempCell.Border = PdfPCell.NO_BORDER; tempCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; frontPage.AddCell(tempCell); try { string nazwaPliku = String.Format("{0}_{1:dd_MM_yyyy}.pdf", nazwaRaportu, DateTime.Now); Console.WriteLine(nazwaPliku); using (FileStream stream = new FileStream(nazwaPliku, FileMode.Create)) { PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); pdfDoc.Add(frontPage); pdfDoc.NewPage(); pdfDoc.Add(mainRaport); pdfDoc.Close(); stream.Close(); } } catch (IOException) { MessageBox.Show("Zamknij najpierw plik pdf."); } } }
public IPdfReportData CreatePersianFontsListToPdfReport() { return(new PdfReport().DocumentPreferences(doc => { doc.RunDirection(PdfRunDirection.RightToLeft); doc.Orientation(PageOrientation.Portrait); doc.PageSize(PdfPageSize.A4); doc.DocumentMetadata(new DocumentMetadata { Author = "Vahid", Application = "PdfRpt", Keywords = "Test", Subject = "Test Rpt", Title = "Test" }); doc.Compression(new CompressionSettings { EnableCompression = true, EnableFullCompression = true }); }) .DefaultFonts(fonts => { fonts.Path(System.IO.Path.Combine(TestUtils.GetBaseDir(), "fonts", "irsans.ttf"), TestUtils.GetVerdanaFontPath()); fonts.Size(9); fonts.Color(System.Drawing.Color.Black); }) .PagesFooter(footer => { footer.DefaultFooter(DateTime.Now.ToString("MM/dd/yyyy")); }) .PagesHeader(header => { header.CacheHeader(cache: true); // It's a default setting to improve the performance. header.DefaultHeader(defaultHeader => { defaultHeader.ImagePath(TestUtils.GetImagePath("01.png")); defaultHeader.Message("Installed 'B ' fonts list"); }); }) .MainTableTemplate(template => { template.BasicTemplate(BasicTemplate.ClassicTemplate); }) .MainTablePreferences(table => { table.ColumnsWidthsType(TableColumnWidthType.Relative); }) .MainTableDataSource(dataSource => { var listOfRows = new List <FontSample>(); // Register all the fonts of a directory var fontsDir = System.IO.Path.Combine(TestUtils.GetBaseDir(), "fonts"); FontFactory.RegisterDirectory(fontsDir); // Enumerate the current set of system fonts foreach (string fontName in FontFactory.RegisteredFonts) { if (!fontName.ToLowerInvariant().StartsWith("b ")) { continue; } listOfRows.Add(new FontSample { FontName = fontName, EnglishTextSample = "Sample Text 1,2,3", PersianTextSample = "نمونه متن 1,2,3" }); } dataSource.StronglyTypedList <FontSample>(listOfRows); }) .MainTableColumns(columns => { columns.AddColumn(column => { column.PropertyName("rowNo"); column.IsRowNumber(true); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(0); column.Width(1); column.HeaderCell("#"); }); columns.AddColumn(column => { column.PropertyName <FontSample>(x => x.FontName); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(1); column.Width(2); column.HeaderCell("Font name"); }); columns.AddColumn(column => { column.PropertyName <FontSample>(x => x.EnglishTextSample); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(2); column.Width(3); column.HeaderCell("Sample Text"); column.ColumnItemsTemplate(t => t.CustomTemplate(new FontsListCellTemplate(20))); }); columns.AddColumn(column => { column.PropertyName <FontSample>(x => x.PersianTextSample); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(3); column.Width(3); column.HeaderCell("نمونه متن"); column.ColumnItemsTemplate(t => t.CustomTemplate(new FontsListCellTemplate(20))); }); }) .MainTableEvents(events => { events.DataSourceIsEmpty(message: "There is no data available to display."); }) .Generate(data => data.AsPdfFile(TestUtils.GetOutputFileName()))); }
private void getPDF() { System.Drawing.Font font = new System.Drawing.Font("Microsoft Sans Serif", 12); iTextSharp.text.pdf.BaseFont bfR, bfR1, bfRB; iTextSharp.text.BaseColor clrBlack = new iTextSharp.text.BaseColor(0, 0, 0); //MemoryStream ms = new MemoryStream(); string myFont = Environment.CurrentDirectory + "\\THSarabun.ttf"; string myFontB = Environment.CurrentDirectory + "\\THSarabun Bold.ttf"; String hn = "", name = "", doctor = "", fncd = "", birthday = "", dsDate = "", dsTime = "", an = ""; decimal total = 0; bfR = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bfR1 = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bfRB = BaseFont.CreateFont(myFontB, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); iTextSharp.text.Font fntHead = new iTextSharp.text.Font(bfR, 12, iTextSharp.text.Font.NORMAL, clrBlack); String[] aa = dsDate.Split(','); if (aa.Length > 1) { dsDate = aa[0]; an = aa[1]; } String[] bb = dsDate.Split('*'); if (bb.Length > 1) { dsDate = bb[0]; dsTime = bb[1]; } var logo = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\LOGO-BW-tran.jpg"); logo.SetAbsolutePosition(30, PageSize.A4.Height - 90); logo.ScaleAbsoluteHeight(70); logo.ScaleAbsoluteWidth(70); FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4, 36, 36, 36, 36); try { FileStream output = new FileStream(Environment.CurrentDirectory + "\\" + hn + ".pdf", FileMode.Create); PdfWriter writer = PdfWriter.GetInstance(doc, output); doc.Open(); //PdfContentByte cb = writer.DirectContent; //ColumnText ct = new ColumnText(cb); //ct.Alignment = Element.ALIGN_JUSTIFIED; //Paragraph heading = new Paragraph("Chapter 1", fntHead); //heading.Leading = 30f; //doc.Add(heading); //Image L = Image.GetInstance(imagepath + "/l.gif"); //logo.SetAbsolutePosition(doc.Left, doc.Top - 180); doc.Add(logo); //doc.Add(new Paragraph("Hello World", fntHead)); Chunk c; String foobar = "Foobar Film Festival"; //float width_helv = bfR.GetWidthPoint(foobar, 12); //c = new Chunk(foobar + ": " + width_helv, fntHead); //doc.Add(new Paragraph(c)); //if (dt.Rows.Count > 24) //{ // doc.NewPage(); // doc.Add(new Paragraph(string.Format("This is a page {0}", 2))); //} int i = 0, r = 0, row2 = 0, rowEnd = 24; //r = dt.Rows.Count; int next = r / 24; int linenumber = 800, colCenter = 200, fontSize1 = 14, fontSize2 = 14; PdfContentByte canvas = writer.DirectContent; //canvas.SaveState(); //canvas.SetLineWidth(0.05f); //canvas.MoveTo(400, 806); //canvas.LineTo(400, 626); //canvas.MoveTo(508.7f, 806); //canvas.LineTo(508.7f, 626); //canvas.MoveTo(280, 788); //canvas.LineTo(520, 788); //canvas.MoveTo(280, 752); //canvas.LineTo(520, 752); //canvas.MoveTo(280, 716); //canvas.LineTo(520, 716); //canvas.MoveTo(280, 680); //canvas.LineTo(520, 680); //canvas.MoveTo(280, 644); //canvas.LineTo(520, 644); //canvas.Stroke(); //canvas.RestoreState(); // Adding text with PdfContentByte.showTextAligned() canvas.BeginText(); canvas.SetFontAndSize(bfR, 12); canvas.ShowTextAligned(Element.ALIGN_LEFT, "โรงพยาบาล บางนา5 55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, linenumber, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, 780, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "BANGNA 5 GENERAL HOSPITAL 55 M.4 Theparuk Road, Bangplee, Samutprakan Thailand0", 100, linenumber - 20, 0); canvas.EndText(); linenumber = 720; canvas.BeginText(); canvas.SetFontAndSize(bfR, fontSize2); canvas.ShowTextAligned(Element.ALIGN_CENTER, "ใบรับรองแพทย์", PageSize.A4.Width / 2, linenumber + 20, 0); canvas.ShowTextAligned(Element.ALIGN_CENTER, "MEDICAL CERTIFICATE", PageSize.A4.Width / 2, linenumber, 0); canvas.EndText(); linenumber = 680; canvas.BeginText(); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "วันที่ตรวจ " + dtpDate.Value.Day.ToString() + " เดือน " + bc.getMonth(dtpDate.Value.Month.ToString("00")) + " พ.ศ. " + (dtpDate.Value.Year + 543), 375, linenumber + 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ข้าพเจ้า ", 80, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".......................................................................................................................................................................................", 110, linenumber - 5, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorName.Text.Trim(), 113, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "แพทย์ปริญญาใบอนุญาตประกอบวิชาชีพเวชกรรม เลขที่ ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................................................................. ", 270, linenumber - 3, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorId.Text.Trim(), 273, linenumber, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ได้ทำการตรวจร่างกาย ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................................................................................................................................... ", 150, linenumber - 5, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text.Trim(), 153, linenumber + 2, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ปรากฏว่า ไม่เป็นผู้ทุพพลภาพ ไร้ความสามารถ จิตฟั่นเฟือน ไม่สมประกอบ ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "และปราศจากโรคเหล่านี้ ", 60, linenumber -= 20, 0); linenumber = 580; canvas.ShowTextAligned(Element.ALIGN_LEFT, "1. โรคเรื้อนในระยะติดต่อหรือในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม (Leprosy) ", 150, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "2. วัณโรคปอดในระยะติดต่อ (Active pulmonary tuberculosis) ", 150, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "3. โรคติดยาเสพติดให้โทษ (Drug addiction) ", 150, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "4. โรคพิษสุราเรื้อรัง (Chronic alcoholism) ", 150, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "5. โรคเท้าช้างในระยะที่ปรากฏอาการที่เป็นที่รังเกียจแก่สังคม (Filariasis) ", 150, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "6. ซิฟิลิสในระยะที่ 2 (Syphilis Secondary)", 150, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "7. โรคจิตฟั่นเฟือนหรือปัญญาอ่อน (Schizophrenia or Mental Retardation)", 150, linenumber -= 20, 0); linenumber -= 20; canvas.ShowTextAligned(Element.ALIGN_LEFT, "เห็นว่า ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "............................................................................................................................................................................................", 100, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, cboResult.Text.Trim(), colCenter, linenumber + 5, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "ตรวจสมรรถภาพการทำงานของปอด ", 60, linenumber -= 20, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, txtLung.Text.Trim(), 160, linenumber, 0); canvas.SetFontAndSize(bfR, fontSize1); if (!txtXRay.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ X-Ray ปอด ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtXRay.Text, colCenter + 70, linenumber, 0); } if (!txtCBC.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ CBC ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtCBC.Text, colCenter + 70, linenumber, 0); } if (!txtAmp.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจหาสารเสพติดในปัสสาวะ (Amphetamine) ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAmp.Text, colCenter + 70, linenumber, 0); } if (!txtPrag.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ Pragnancy ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPrag.Text, colCenter + 70, linenumber, 0); } if (!txtHbsAg.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ Hbs Ag ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtHbsAg.Text, colCenter + 70, linenumber, 0); } if (!txtUA.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ UA ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtUA.Text, colCenter + 70, linenumber, 0); } if (!txtHIV.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ Anti HIV ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtHIV.Text, colCenter + 70, linenumber, 0); } if (!txtEye.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ วัดสายตา ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtEye.Text, colCenter + 70, linenumber, 0); } if (!txtEar.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ การได้ยิน ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtEar.Text, colCenter + 70, linenumber, 0); } if (!txtVDRL.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ VDRL ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtVDRL.Text, colCenter + 70, linenumber, 0); } if (!txtBloodG.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ กรุ๊ปเลือด ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtBloodG.Text, colCenter + 70, linenumber, 0); } if (!txtFBS.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจหาน้ำตาลในเลือด (FBS) ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtFBS.Text, colCenter + 70, linenumber, 0); } if (!txt1.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ อุจจาระ ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txt1.Text, colCenter + 70, linenumber, 0); } if (!txtLead.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ Lead ", 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtLead.Text, colCenter + 70, linenumber, 0); } linenumber -= 5; canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "บันทึกสัญญาณชีพ ", 60, linenumber -= 20, 0); String aaaa = "H.Rate: ครั้ง/min BP: mmHg "; if (!txtPulse.Text.Equals("")) { //String[] aaa = txtPulse.Text.Split('/'); aaaa = "H.Rate: " + txtPulse.Text + " ครั้ง/min R.Rate: " + txtBreath.Text + " ครั้ง/min BP: " + txtBloodPressure.Text + " mmHg "; } canvas.ShowTextAligned(Element.ALIGN_LEFT, "..................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, aaaa, colCenter + 70, linenumber + 2, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, "WT: " + txtWeight.Text + " Kgs HT: " + txtHeight.Text + " Cms", colCenter + 70, (linenumber -= 20) + 2, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); if (!txtT1.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, cboL1.Text.Trim(), 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtT1.Text, colCenter + 70, linenumber + 1, 0); } if (!txtT2.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtL2.Text.Trim(), 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtT2.Text, colCenter + 70, linenumber + 1, 0); } if (!txtT3.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtL3.Text.Trim(), 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtT3.Text, colCenter + 70, linenumber + 1, 0); } if (!txtT4.Text.Equals("")) { canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtL4.Text.Trim(), 60, linenumber -= 20, 0); canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0); canvas.SetFontAndSize(bfRB, fontSize2); canvas.ShowTextAligned(Element.ALIGN_LEFT, txtT4.Text, colCenter + 70, linenumber + 1, 0); } linenumber = 100; canvas.SetFontAndSize(bfR, 12); canvas.ShowTextAligned(Element.ALIGN_LEFT, "มีอายุการใช้งาน 3 เดือน (VALID FOR THREE MONTHS) ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ลายมือชื่อ ....................................................... ", 370, linenumber - 3, 0); canvas.SetFontAndSize(bfR, 12); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผ่านการรับรองมาตรฐาน ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "Signature " + txtDoctorName.Text.Trim(), 370, linenumber, 0); canvas.SetFontAndSize(bfR, 12); canvas.ShowTextAligned(Element.ALIGN_LEFT, "ISO 9001:2000 ทุกหน่วยงาน ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "(แพทย์ผู้ตรวจ) ", 420, linenumber, 0); canvas.SetFontAndSize(bfR, 12); canvas.ShowTextAligned(Element.ALIGN_LEFT, "FM-NUR-001/3 (แก้ไขครั้งที่ 00 15/02/53) ", 60, linenumber -= 20, 0); canvas.SetFontAndSize(bfR, fontSize1); canvas.ShowTextAligned(Element.ALIGN_LEFT, "Attending physician ", 420, linenumber, 0); canvas.EndText(); //canvas.BeginText(); //canvas.SetFontAndSize(bfR, 16); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "วัน/เวลา", 50, 620, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "รายการ", 250, 620, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "จำนวน", 405, 620, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "ราคา", 460, 620, 0); //canvas.ShowTextAligned(Element.ALIGN_LEFT, "รวมราคา", 510, 620, 0); ////canvas.ShowTextAlignedKerned(Element.ALIGN_LEFT, "ชื่อแพทย์ผู้รักษา "+ 60, 660, 644, 0); ////canvas.ShowTextAlignedKerned(Element.ALIGN_LEFT, "ชื่อแพทย์ผู้รักษา " + 60, 640, 644, 0); //canvas.EndText(); //canvas.MoveTo(520, 640);//vertical Amount //canvas.LineTo(520, 110); canvas.Stroke(); canvas.RestoreState(); //pB1.Maximum = dt.Rows.Count; } catch (Exception ex) { //Log(ex.Message); } finally { doc.Close(); Process p = new Process(); ProcessStartInfo s = new ProcessStartInfo(Environment.CurrentDirectory + "\\" + hn + ".pdf"); //s.Arguments = "/c dir *.cs"; p.StartInfo = s; //p.StartInfo.Arguments = "/c dir *.cs"; //p.StartInfo.UseShellExecute = false; //p.StartInfo.RedirectStandardOutput = true; p.Start(); //string output = p.StandardOutput.ReadToEnd(); //p.WaitForExit(); //Application.Exit(); } }
protected void btTatCa_Click(object sender, EventArgs e) { DataTable Muc = Connect.GetTable("select distinct Muc from HangHoa order by Muc desc"); string sql = ""; sql += @"select * from(select ROW_NUMBER() OVER(ORDER BY ChiTietPhieuXuat.NgayXuatChiTiet asc)AS RowNumber,HangHoa.Muc,HangHoa.IDHangHoa,ChiTietPhieuXuat.NgayXuatChiTiet,ChiTietPhieuXuat.IDChiTietPhieuXuat,HangHoa.MaHangHoa,HangHoa.TenHangHoa,ChiTietPhieuXuat.SoLuong,ChiTietPhieuXuat.DonGiaXuat,PhieuXuat.MaPhieuXuat from HangHoa,ChiTietPhieuXuat,PhieuXuat where HangHoa.IDHangHoa = ChiTietPhieuXuat.IDHangHoa and ChiTietPhieuXuat.IDPhieuXuat = PhieuXuat.IDPhieuXuat"; if (txtNgayDauKy.Value.Trim() != "") { sql += " and ChiTietPhieuXuat.NgayXuatChiTiet >='" + StaticData.ConvertDDMMtoMMDD(txtNgayDauKy.Value.Trim()) + " 00:00:00'"; } if (txtNgayCuoiKy.Value.Trim() != "") { sql += " and ChiTietPhieuXuat.NgayXuatChiTiet <='" + StaticData.ConvertDDMMtoMMDD(txtNgayCuoiKy.Value.Trim()) + " 00:00:00'"; } if (txtTuPhieu.Value.Trim() != "") { sql += " and PhieuXuat.MaPhieuXuat >= N'" + txtTuPhieu.Value.Trim() + "'"; } if (txtDenPhieu.Value.Trim() != "") { sql += " and PhieuXuat.MaPhieuXuat <= N'" + txtDenPhieu.Value.Trim() + "'"; } // sql += "group by HangHoa.MaHangHoa,HangHoa.TenHangHoa,ChiTietPhieuXuat.NgayXuatChiTiet,ChiTietPhieuNhap.NgayNhapChiTiet,ChiTietPhieuXuat.IDChiTietPhieuXuat,HangHoa.IDHangHoa "; sql += " ) as tb1"; DataTable table = Connect.GetTable(sql); string HTMLContent = "<html><body encoding=" + BaseFont.IDENTITY_H + " style='font-family:Arial;font-size:10;'>"; DataTable NoiToi = Connect.GetTable("select top 1 KhachHang.TenKhachHang,PhongBan.TenPhongBan,CuaHang.TenCuaHang,CuaHang.DiaChi,PhongBan.DiaChiPhongBan,KhachHang.DiaChi as 'DiaChiKH',CuaHang.SoDienThoai,CuaHang.NguoiLienLac from ChiTietPhieuXuat left join KhachHang on ChiTietPhieuXuat.IDKhachHang = KhachHang.IDKhachHang left join PhongBan on ChiTietPhieuXuat.IDPhongBan = PhongBan.IDPhongBan left join CuaHang on ChiTietPhieuXuat.IDCuaHang = CuaHang.IDCuaHang where IDPhieuXuat = '" + StaticData.getField("PhieuXuat", "IDPhieuXuat", "MaPhieuXuat", txtTuPhieu.Value.Trim()) + "'"); string NoiGiao = ""; string DiaChi = ""; string NoiNhan = ""; string BenNhan = ""; if (NoiToi.Rows.Count > 0) { if (NoiToi.Rows[0]["TenKhachHang"].ToString().Trim() != "") { if (NoiToi.Rows[0]["TenPhongBan"].ToString().Trim() != "") { if (NoiToi.Rows[0]["TenCuaHang"].ToString().Trim() != "") { BenNhan = NoiToi.Rows[0]["TenKhachHang"].ToString().Trim() + "_" + NoiToi.Rows[0]["TenPhongBan"].ToString().Trim(); NoiNhan = "Chị/Anh " + NoiToi.Rows[0]["NguoiLienLac"].ToString().Trim() + " + Số điện thoại: " + NoiToi.Rows[0]["SoDienThoai"].ToString().Trim(); } else { BenNhan = NoiToi.Rows[0]["TenKhachHang"].ToString().Trim(); NoiNhan = NoiToi.Rows[0]["TenPhongBan"].ToString().Trim(); } } else { BenNhan = NoiToi.Rows[0]["TenKhachHang"].ToString().Trim(); } } DiaChi = NoiToi.Rows[0]["DiaChiKH"].ToString(); } double TongSoLuong = 0; HTMLContent += @" <div> <table border='0'> <tr> <td style='text-align: right;'><img src='http://vienlien.lamphanmem.com/images/vienlien.png' width='35' height='45' /></td> <td colspan='5'><br /><b>CÔNG TY CỔ PHẦN VIỄN LIÊN</b><br /><i>Số 32 Đường số 8 nhà ở Khu Z756, Phường 12, Q.10, Tp.Hồ Chí Minh</i></td> <td style='text-align: center;' colspan='5'><b>CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM</b><br />Độc lập - Tự do - Hạnh phúc</td> </tr> </table> <table border='0'> <tr> <td > </td> <td colspan='5'><b><i><u>Tel</u></i></b> : 028 3620 8997 - <b><i><u>Fax</u></i></b> : 028 3620 8997</td> <td style='text-align: center;' colspan='5'>**********</td> </tr> </table> <table border='0'> <tr> <td style='text-align: right;'>Số:</td> <td colspan='5'>" + txtTuPhieu.Value.Trim() + "-" + txtDenPhieu.Value.Trim() + @"</td> <td colspan='5' style='text-align: center;'><i>Tp,HCM Ngày tháng năm</i></td> </tr> </table> <table border='0'> <tr> <td style='text-align: center;'><h1><b>BIÊN BẢN GIAO HÀNG</b></h1></td> </tr> </table> <table border='0'> <tr> <td ></td> <td style='text-align: left;' colspan='5'><b>Bên giao : CÔNG TY CỔ PHẦN VIỄN LIÊN</b></td> <td > </td> </tr> </table> <table border='0'> <tr> <td> </td> <td colspan='5'><h4><b>Bên nhận : " + BenNhan + @"</b></h4></td> <td> </td> </tr> <tr> <td> </td> <td colspan='5'>Nơi giao: " + NoiNhan + @"</td> <td> </td> </tr> <tr> <td> </td> <td colspan='5'>Địa chỉ: " + DiaChi + @"</td> <td> </td> </tr> <tr> <td colspan='5' style='text-align: right;'><b>Cùng tiến hành kiểm tra chất lượng và số lượng của những mặt hàng sau :</b></td> <td> </td> <td> </td> </tr> </table> </div> </div> <table border='1'> <tr> <td style='text-align: center;'>STT</td> <td style='text-align: center;'>DANH MỤC VPP</td> <td style='text-align: center;'>ĐVT</td> <td style='text-align: center;'>SỐ LƯỢNG</td> <td style='text-align: center;'> ĐƠN GIÁ</td> <td style='text-align: center;'>THÀNH TIỀN</td> <td style='text-align: center;'>GHI CHÚ</td> </tr>"; double TongCong = 0; for (int j = 0; j < Muc.Rows.Count; j++) { int stt = 0; int xet = 0; for (int i = 0; i < table.Rows.Count; i++) { if (Muc.Rows[j]["Muc"].ToString().Trim().CompareTo(table.Rows[i]["Muc"].ToString().Trim()) == 0) { xet += 1; } } if (xet > 0) { HTMLContent += "<tr><td style='text-align: left;' colspan='7' ><b>" + Muc.Rows[j]["Muc"].ToString() + "</b></td></tr>"; for (int i = 0; i < table.Rows.Count; i++) { if (Muc.Rows[j]["Muc"].ToString().Trim().CompareTo(table.Rows[i]["Muc"].ToString().Trim()) == 0) { stt += 1; HTMLContent += " <tr >"; HTMLContent += " <td style='text-align: center;'>" + stt.ToString() + "</td>"; HTMLContent += " <td >" + table.Rows[i]["TenHangHoa"].ToString() + "</td>"; HTMLContent += " <td style='text-align: center;'>" + StaticData.getField("DonViTinh", "TenDonViTinh", "IDDonViTinh", StaticData.getField("HangHoa", "IDDonViTinh", "IDHangHoa", table.Rows[i]["IDHangHoa"].ToString())) + "</td>"; double a = double.Parse(table.Rows[i]["SoLuong"].ToString()); HTMLContent += " <td style='text-align: center;'>" + string.Format("{0:N0}", (a)).Replace(",", ".") + "</td>"; double a1 = double.Parse(table.Rows[i]["DonGiaXuat"].ToString()); HTMLContent += " <td style='text-align: center;'>" + string.Format("{0:N0}", (a1)).Replace(",", ".") + "</td>"; TongSoLuong += a; double Ton = a * a1; TongCong += Ton; HTMLContent += " <td style='text-align: center;'>" + string.Format("{0:N0}", (Ton)).Replace(",", ".") + "</td>"; // DataTable gc = Connect.GetTable("select GhiChu from ChiTietPhieuXuat where IDChiTietPhieuXuat=" + table.Rows[i]["IDChiTietPhieuXuat"].ToString() + ""); HTMLContent += " <td > </td>"; HTMLContent += " </tr>"; } } } } HTMLContent += @" <tr> <td > </td> <td style='text-align: left;'>CỘNG:</td> <td > </td> <td style='text-align: center;'>" + string.Format("{0:N0}", (TongSoLuong)).Replace(",", ".") + @"</td> <td > </td> <td style='text-align: center;'>" + string.Format("{0:N0}", (TongCong)).Replace(",", ".") + @"</td> <td > </td> </tr> <tr> <td> </td> <td style='text-align: left;'>VAT:</td> <td> </td> <td > </td> <td> </td> <td style='text-align: center;'>" + string.Format("{0:N0}", ((TongCong * 10 / 100))).Replace(",", ".") + @"</td> <td> </td> </tr> <tr> <td> </td> <td style='text-align: left;'>TỔNG CỘNG:</td> <td> </td> <td > </td> <td> </td> <td style='text-align: center;'><b>" + string.Format("{0:N0}", ((TongCong + (TongCong * 10 / 100)))).Replace(",", ".") + @"</b></td> <td> </td> </tr> <tr> <td> </td> <td style='text-align: left;'>BẰNG CHỮ:</td> <td colspan='5' style='text-align: right;'><i>" + StaticData.ConvertDecimalToString(decimal.Parse((TongCong + (TongCong * 10 / 100)).ToString().Trim())) + @"</i></td> </tr> </table> <table border='0'> <tr> <td style='text-align: center;'><b>ĐẠI DIỆN BÊN NHẬN HÀNG</b></td> <td style='text-align: center;' ></td> <td style='text-align: center;'><b>ĐẠI DIỆN BÊN GIAO HÀNG</b></td> </tr> </table> <table border='0'> <tr> <td style='text-align: center;' ><i>Xác nhận trưởng đơn vị</i></td> <td style='text-align: center;' ><i>Người giao hàng</i></td> <td style='text-align: center;' ><i>Người giao hàng</i></td> </tr> </table> </body></html>"; //var strBody = new StringBuilder(); //strBody.Append("<html " + // "xmlns:o='urn:schemas-microsoft-com:office:office' " + // "xmlns:w='urn:schemas-microsoft-com:office:word'" + // "xmlns='http://www.w3.org/TR/REC-html40'>" + // "<head><title>Time</title>"); //// The setting specifies document's view after it is downloaded as Print //// instead of the default Web Layout //strBody.Append("<!--[if gte mso 9]>" + // "<xml>" + // "<w:WordDocument>" + // "<w:View>Print</w:View>" + // "<w:Zoom>100</w:Zoom>" + // "<w:DoNotOptimizeForBrowser/>" + // "</w:WordDocument>" + // "</xml>" + // "<![endif]-->"); //strBody.Append("<style>" + // "<!-- /* Style Definitions */" + // "@page Section1" + // " {size:8.5in 10.0in; " + // " margin:0.8in 0.7in ; " + // " mso-header-margin:.1in; " + // " mso-footer-margin:.5in; mso-paper-source:0;}" + // " div.Section1" + // " {page:Section1;}" + // "-->" + // "</style></head>"); //strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" + // "<div class=Section1>"); //strBody.Append(HTMLContent); ////strBody.Append("</div></body></html>"); //string TenFile = DateTime.Now.Ticks.ToString(); //string strPath2 = Request.PhysicalApplicationPath + @"Files\"; //string strPath = Request.PhysicalApplicationPath + @"Files\" + TenFile + ".doc"; //FileStream fStream = File.Create(strPath); //fStream.Close(); //StreamWriter sWriter = new StreamWriter(strPath, false, Encoding.UTF8); //sWriter.Write(strBody); //sWriter.Close(); // Response.Write(strPath); /* Document doc = new Document(); * * doc.LoadFromFile(@"" + strPath); * * doc.SaveToFile(@"" + strPath2 + "636404763499472227.PDF", FileFormat.PDF); * * System.Diagnostics.Process.Start(@"" + strPath2 + "636404763499472227.PDF");*/ //var wordApp = new Microsoft.Office.Interop.Word.Application(); //var wordDocument = wordApp.Documents.Open(@"" + strPath); //string downloadsPath = KnownFolders.GetPath(KnownFolders.KnownFolder.Desktop); //string ten = @"BBTH" + DateTime.Now.ToString() + ".PDF"; //wordDocument.ExportAsFixedFormat(@"" + downloadsPath + @"\" + ten.Replace(" ", "").Replace("/", "").Replace(":", ""), Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF); //// wordDocument.ExportAsFixedFormat(ten, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF); //wordDocument.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges, // Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat, // false); //Close document //wordApp.Quit(); ////Response.Write(ten.Replace(" ", "").Replace("/", "").Replace(":", "")); //if (File.Exists(@"" + strPath)) //{ // File.Delete(@"" + strPath); //} //Response.Write("<script>alert('Đã xuất file pdf ra " + downloadsPath.Replace("\\","\\\\") + "');</script>"); string FileName = "BienBanTongHop"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); Response.AppendHeader("Content-Type", "application/pdf"); Response.AppendHeader("Content-disposition", "attachment; filename=" + FileName + ".pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); stringWrite.WriteLine(HTMLContent); HtmlTextWriter hw = new HtmlTextWriter(stringWrite); StringReader sr = new StringReader(stringWrite.ToString()); Document pdfDoc = new Document(PageSize.A4, 20f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter wi = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); //string fontpath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts) + "\\ARIALUNI.TTF"; // "ARIALUNI.TTF" file copied from fonts folder and placed in the folder string fontpath = "http://vienlien.lamphanmem.com/Fonts/ARIALUNI.TTF"; // "ARIALUNI.TTF" file copied from fonts folder and placed in the folder BaseFont bf = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); FontFactory.RegisterDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), true); FontFactory.Register(fontpath, "Arial Unicode MS"); //string path = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/ArialUni.TFF"); //iTextSharp.text.Font fnt = new iTextSharp.text.Font(); //FontFactory.Register(path, "Arial Unicode MS"); //fnt = FontFactory.GetFont("Arial Unicode MS", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10, Font.NORMAL); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); /* Response.AppendHeader("content-disposition", "attachment;filename=BienBanTongHop.xls"); * Response.Charset = ""; * Response.Cache.SetCacheability(HttpCacheability.NoCache); * Response.ContentType = "application/vnd.ms-excel"; * this.EnableViewState = false; * Response.Write(HTMLContent); * Response.End();*/ }
// create pdf with order public void CreatePdfAttachmentWithOrder(int orderId) { var orderExist = _myContex.Orders.Find(orderId); var orderExistDetailList = _myContex.OrderDetails.Where(x => x.OrderId == orderId).ToList(); FontFactory.RegisterDirectory("C:WINDOWSFonts"); //add polish signs var titleFont18 = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED, 18, Font.BOLD); var titleFont14 = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED, 14, Font.BOLD); var textFont = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED, 12); Font link = FontFactory.GetFont("Arial", 12, Font.UNDERLINE); FileStream fs = new FileStream("PDF/Zamowienie" + orderId + ".pdf", FileMode.Create); Document orderPdf = new Document(PageSize.A4); PdfWriter writer = PdfWriter.GetInstance(orderPdf, fs); orderPdf.Open(); Anchor orderLink = new Anchor("Link do panelu klienta http://www.reptihurt.pl/index \n", link); orderPdf.Add(new Paragraph(orderLink)); String line = "Zamówienie nr " + orderId; orderPdf.Add(new Paragraph(line + "\n\n", titleFont14)); //orderLink.Reference = "http://www.reptihurt.pl/zamowienia/index"; PdfPTable table = new PdfPTable(2); table.AddCell(new Phrase("Numer dokumentu", textFont)); table.AddCell(orderId.ToString()); table.AddCell(new Phrase("Data i godzina przyjęcia zamówienia", textFont)); table.AddCell(orderExist.DateOrder.ToString()); table.AddCell(new Phrase("Wartość zamówienia brutto", textFont)); table.AddCell(new Phrase(orderExist.ValueOrder.ToString() + "zł", textFont)); table.AddCell(new Phrase("Uwagi do zamówienia", textFont)); table.AddCell(new Phrase(orderExist.OrderMessage, textFont)); PdfPTable table2 = new PdfPTable(3); table2.SetWidths(new int[] { 7, 1, 1 }); PdfPCell cell2 = new PdfPCell(new Phrase("\n\nZawartość zamówienia:\n", titleFont14)); cell2.Colspan = 3; cell2.Border = 0; cell2.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right table2.AddCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase("Nazwa", textFont)); cell3.HorizontalAlignment = 1; table2.AddCell(cell3); PdfPCell cell4 = new PdfPCell(new Phrase("Ilość", textFont)); cell3.HorizontalAlignment = 1; table2.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase("Cena", textFont)); cell3.HorizontalAlignment = 1; table2.AddCell(cell5); foreach (var orderDetail in orderExistDetailList) { table2.AddCell(new Phrase(orderDetail.ProductName, textFont)); table2.AddCell(new Phrase(orderDetail.Quantity.ToString(), textFont)); table2.AddCell(new Phrase(orderDetail.Price + "zł", textFont)); } orderPdf.Add(table); orderPdf.Add(table2); orderPdf.Close(); writer.Close(); fs.Close(); }
private void btIn_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Bạn có muốn xuất tạo file báo cáo", "Thông báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { var redListTextFont = FontFactory.RegisterDirectory(Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts"); var _bold = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10f, iTextSharp.text.Font.BOLD, BaseColor.BLACK); var _bold1 = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10f, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); PdfPTable pdfTable = new PdfPTable(gdvHoaDon.ColumnCount); pdfTable.DefaultCell.Padding = 3; pdfTable.WidthPercentage = 30; pdfTable.HorizontalAlignment = Element.ALIGN_CENTER; pdfTable.DefaultCell.BorderWidth = 1; pdfTable.TotalWidth = 500f; pdfTable.LockedWidth = true; float[] widths = new float[] { 100f, 100f, 100f, 100f, 100f }; pdfTable.SetWidths(widths); //Adding Header row foreach (DataGridViewColumn column in gdvHoaDon.Columns) { PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, _bold)); cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240); pdfTable.AddCell(cell); } //Adding DataRow foreach (DataGridViewRow row in gdvHoaDon.Rows) { foreach (DataGridViewCell cell in row.Cells) { if (!String.IsNullOrEmpty(Convert.ToString(cell.Value))) { pdfTable.AddCell(new Phrase(cell.Value.ToString(), _bold1)); } } } //Exporting to PDF string folderPath = @"C:\Users\huy\Desktop\Report\"; string x = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ""; string tenfile = x + "ReportThongNguonChi.pdf"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } using (FileStream stream = new FileStream(folderPath + tenfile, FileMode.Create)) { Document pdfDoc = new Document(PageSize.A3, 100f, 100f, 100f, 0); PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); var FontColour = new BaseColor(255, 0, 0); var _bold2 = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 20f, iTextSharp.text.Font.NORMAL, BaseColor.BLUE); Paragraph docTitle = new Paragraph("Thống kê nguồn chi " + "\n", _bold2); Paragraph docTitle4 = new Paragraph("Nhà xuất bản : " + lbTen.Text + "\n" + "Mã NXB :" + lbMa.Text + "\n", _bold2); Paragraph docTitle1 = new Paragraph("Từ tháng : " + cmbStartMonth.Text + " Năm " + cmbStartYear.Text + "\n", _bold2); Paragraph docTitle2 = new Paragraph("đến tháng : " + cmbEndMonth.Text + " Năm " + cmbEndYear.Text + "\n", _bold2); Paragraph docTitle3 = new Paragraph("Tổng tiền chi : " + lbTongTienChi.Text + "\n", _bold2); docTitle.Alignment = Element.ALIGN_LEFT; docTitle4.Alignment = Element.ALIGN_LEFT; docTitle1.Alignment = Element.ALIGN_LEFT; docTitle2.Alignment = Element.ALIGN_LEFT; docTitle3.Alignment = Element.ALIGN_LEFT; pdfDoc.Add(docTitle); pdfDoc.Add(docTitle4); pdfDoc.Add(docTitle1); pdfDoc.Add(docTitle2); pdfDoc.Add(docTitle3); pdfDoc.Add(new Paragraph("\n")); pdfDoc.Add(new Paragraph("\n")); pdfDoc.Add(pdfTable); pdfDoc.Close(); stream.Close(); MessageBox.Show("Đã tạo file thành công , Tên file là : " + tenfile); } } else if (dialogResult == DialogResult.No) { return; } }
/// <summary> /// HTML导出PDF /// </summary> /// <param name="myGridView">表格GridView的HTML</param> /// <param name="filepath">filename文件名</param> public static void ExportToPdf(string myGridViewHtml, string filename) { try { //System.Web.HttpContext.Current.Response.ContentType = "application/pdf"; //System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=ExportPdf.pdf"); //System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); Document document = new Document(PageSize.A3, 20f, 20f, 20f, 20f); StyleSheet style = new StyleSheet(); style.LoadTagStyle("body", "face", "SIMHEI"); style.LoadTagStyle("body", "encoding", "Identity-H"); style.LoadTagStyle("body", "leading", "12,0"); FontFactory.RegisterDirectory("c:\\Windows\\Fonts"); FontSelector selector = new FontSelector(); string zhch = filename.Substring(filename.Length - 21, 4); BaseFont baseFont = BaseFont.CreateFont( "C:\\WINDOWS\\FONTS\\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); if (filename.Substring(filename.Length - 21, 4) == "工况明细") { //selector.AddFont(FontFactory.GetFont("Gulim", BaseFont.IDENTITY_H, false, 1)); selector.AddFont(new Font(baseFont, 2)); } else if (filename.Substring(filename.Length - 21, 4) == "方量分析") { //selector.AddFont(FontFactory.GetFont("Gulim", BaseFont.IDENTITY_H, false, 5)); selector.AddFont(new Font(baseFont, 5)); } else { //selector.AddFont(FontFactory.GetFont("Gulim", BaseFont.IDENTITY_H, false, 5)); selector.AddFont(new Font(baseFont, 5)); } Paragraph para = new Paragraph(selector.Process("")); HTMLWorker worker = new HTMLWorker(document); StringReader stringReader = new StringReader(myGridViewHtml); HeaderFooter footer = new HeaderFooter(new Phrase("page "), true); footer.Alignment = Element.ALIGN_RIGHT; footer.Border = Rectangle.NO_BORDER; document.Footer = footer; PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create)); document.Open(); System.Collections.ArrayList p = HTMLWorker.ParseToList(stringReader, style); for (int k = 0; k < p.Count; k++) { para.Add((IElement)p[k]); } document.Add(para); document.Close(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(Path.GetFileName(filename).Trim()) + "\""); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.WriteFile(filename); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Close(); } catch (DocumentException de) { System.Web.HttpContext.Current.Response.Write(de.ToString()); } if (File.Exists(filename)) { File.Delete(filename); } HttpContext.Current.Response.End(); }