Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > สอบถามเรื่องการออก PDF โดยไม่ใช้ Crystal Report โดยใช้ library PdfSharp



 

สอบถามเรื่องการออก PDF โดยไม่ใช้ Crystal Report โดยใช้ library PdfSharp

 



Topic : 084187



โพสกระทู้ ( 14 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook



พอดีไปเจอจาก ตรงนี้ https://www.thaicreate.com/asp.net/c-sharp-asp.net-and-pdf.html
ใช้ Library ตัวเดียวกับผมพอดี พอดีผมมีข้อสงสัยอยู่คือ ตอนนี้ผมส่งข้อมูล มาเป็น datatable ที่มีความยาว เกิน 1 หน้าแน่นอน
ใครพอจะมีเทคเนคแนะนำการลูปแสดงผลได้บ้างไหมครับ เช่น หน้า 1 แสดง head เอกสารด้วย และ loop ข้อมูลออกมาแสดงได้แค่ 15 row
พอขึ้นหน้าใหม่ ไม่ต้องแสดง head และ loop ข้อมูลออกมาแสดงต่อจากเอกสารเดิม ไปเรื่อยๆ จนจบ

code ผมประมานนี้ครับ
Code (C#)
public static bool GenAuditReport(string pDepotCode, string pMUVCode, DataTable dt) {
			try {

				PdfDocument document = new PdfDocument();
				document.Info.Title = "True";

				// Create an empty page
				PdfPage page = document.AddPage();

				// Get an XGraphics object for drawing
				XGraphics gfx = XGraphics.FromPdfPage(page);

				PrivateFontCollection pRegularFont = new PrivateFontCollection();
				pRegularFont.AddFontFile(Environment.fontRegularFilePath);
				System.Drawing.FontFamily RegularFontfamily = pRegularFont.Families[0];

				PrivateFontCollection pBoldFont = new PrivateFontCollection();
				pBoldFont.AddFontFile(Environment.fontBoldFilePath);
				System.Drawing.FontFamily BoldFontfamily = pBoldFont.Families[0];

				XFont font = new XFont(RegularFontfamily, 14, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode));
				XFont fontHeader = new XFont(BoldFontfamily, 20, XFontStyle.Bold, new XPdfFontOptions(PdfFontEncoding.Unicode));
				XFont fontHeaderAddress = new XFont(BoldFontfamily, 16, XFontStyle.Bold, new XPdfFontOptions(PdfFontEncoding.Unicode));
				XFont fontHeaderTable = new XFont(BoldFontfamily, 14, XFontStyle.Bold, new XPdfFontOptions(PdfFontEncoding.Unicode));
				XFont fontRemark = new XFont(RegularFontfamily, 14, XFontStyle.Bold | XFontStyle.Underline, new XPdfFontOptions(PdfFontEncoding.Unicode));

				XPen solidLine = new XPen(XColors.Black, 1);
				solidLine.DashStyle = XDashStyle.Solid;

				XPen dotLine = new XPen(XColors.Black, 0.5);
				dotLine.DashStyle = XDashStyle.Dot;

				XPen solidLine2 = new XPen(XColors.Black, 0.5);
				solidLine2.DashStyle = XDashStyle.Solid;

				System.IFormatProvider format = new System.Globalization.CultureInfo("en-US", true);

				// Render หัว
				gfx.DrawString("รายงานการตรวจนับสินค้า รวม Serial วันที่  " + DateTime.Now.ToString("dd MMM yyyy HH:mm:ss", format)
																	, fontHeader, XBrushes.Black, new XRect(0, 0, page.Width, 100), XStringFormats.Center);

				gfx.DrawString("Depot : " + pDepotCode + " MUV Code : " + pMUVCode , fontHeader, XBrushes.Black, new XRect(0, 30, page.Width, 100), XStringFormats.Center);
				
				//เส้นตาราง (แนวนอน)
				gfx.DrawLine(solidLine2, 65, 320, 545, 320);
				gfx.DrawLine(solidLine2, 65, 345, 545, 345);

				// Render หัวตาราง
				gfx.DrawString("No.", fontHeaderTable, XBrushes.Black, 70, 325, XStringFormats.TopLeft);
				gfx.DrawString("Material Code", fontHeaderTable, XBrushes.Black, 95, 325, XStringFormats.TopLeft);
				gfx.DrawString("Material Name", fontHeaderTable, XBrushes.Black, 255, 325, XStringFormats.TopLeft);
				gfx.DrawString("Serial", fontHeaderTable, XBrushes.Black, 430, 325, XStringFormats.TopLeft);
				gfx.DrawString("สถานะ", fontHeaderTable, XBrushes.Black, 510, 325, XStringFormats.TopLeft);

                int intLine = 350;
                int i;
                for (i = 0; i <= 15 -1 ; i++) {
                    gfx.DrawString((i + 1).ToString(), font, XBrushes.Black, 75, intLine, XStringFormats.TopLeft);

                    //ถ้าเป็นสินค้า Bundle แสดง BundleName
                    //DataTable dtBundle = new BundlesList().openByBundleCode(dt.Rows[i]["BundleCode"].ToString());
                    if (dt.Rows.Count > 0) {
                        if (dt.Rows[i]["isFound"].ToString().Equals("Y")) {
                            gfx.DrawString(dt.Rows[i]["MaterialCode"].ToString(), font, XBrushes.Black, 117, intLine, XStringFormats.TopLeft);
                            gfx.DrawString(dt.Rows[i]["MaterialName"].ToString(), font, XBrushes.Black, 170, intLine, XStringFormats.TopLeft);
                            gfx.DrawString(dt.Rows[i]["SerialNo"].ToString(), font, XBrushes.Black, 400, intLine, XStringFormats.TopLeft);
                            gfx.DrawString("พบ", font, XBrushes.Black, 500, intLine, XStringFormats.TopLeft);
                        } else {
                            gfx.DrawString(dt.Rows[i]["MaterialCode"].ToString(), font, XBrushes.Red, 117, intLine, XStringFormats.TopLeft);
                            gfx.DrawString(dt.Rows[i]["MaterialName"].ToString(), font, XBrushes.Red, 170, intLine, XStringFormats.TopLeft);
                            gfx.DrawString(dt.Rows[i]["SerialNo"].ToString(), font, XBrushes.Red, 400, intLine, XStringFormats.TopLeft);
                            gfx.DrawString("ไม่พบ", font, XBrushes.Red, 500, intLine, XStringFormats.TopLeft);
                        }
                    } 
                    //else {
                    //    gfx.DrawString("-", font, XBrushes.Black, 127, intLine, XStringFormats.TopLeft);
                    //    gfx.DrawString(dt.Rows[i]["MaterialName"].ToString(), font, XBrushes.Black, 170, intLine, XStringFormats.TopLeft);
                    //}
                    //gfx.DrawString(dt.Rows[i]["SerialNo"].ToString(), font, XBrushes.Black, 395, intLine, XStringFormats.TopLeft);
                    //XStringFormat formatRight = new XStringFormat();
                    //formatRight.Alignment = XStringAlignment.Far;
                    //formatRight.LineAlignment = XLineAlignment.Far;
                    //gfx.DrawString(String.Format("{0:#,##0.00}", CATConvert.ToDecimal(dt.Rows[i]["Price"])), font, XBrushes.Black, 537, intLine + 16, formatRight);
                    intLine = intLine + 25;
                    if (i != dt.Rows.Count - 1)
                        gfx.DrawLine(dotLine, 65, intLine - 5, 545, intLine - 5);
                    else
                        gfx.DrawLine(solidLine2, 65, intLine - 5, 545, intLine - 5);
                }

				//เส้นตาราง (แนวตั้ง)
				gfx.DrawLine(solidLine2, 65, 320, 65, intLine - 5);
				gfx.DrawLine(solidLine2, 90, 320, 90, intLine - 5);
				gfx.DrawLine(solidLine2, 165, 320, 165, intLine - 5);
				gfx.DrawLine(solidLine2, 390, 320, 390, intLine - 5);
				gfx.DrawLine(solidLine2, 495, 320, 495, intLine - 5);
				gfx.DrawLine(solidLine2, 545, 320, 545, intLine - 5);


                // Save the document...
				string fileName =  "Audit_" + DateTime.Now.Ticks + ".pdf";

				deletePreviousPDF();
				document.Save(Environment.applicationPath + "/" + fileName);
				Process.Start(Environment.applicationPath + "/" + fileName);
				return true;
			} catch (Exception e) {
				return false;
			}
		}




Tag : .NET, Ms SQL Server 2008, Win (Windows App), C#, Windows







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-09-18 13:31:22 By : hamutaru View : 1434 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ผมแนะนำได้แค่ว่าถ้าขึ้นหน้า 2 คุณก็อาจจะเรียก function ที่ไม่ต้องสร้าง header ครับ

ลองดู






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-19 10:50:27 By : mr.win
 


 

No. 2



โพสกระทู้ ( 14 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook

ตอนนี้ทำได้ล่ะครับไว้จะมาเขียนเป็นบทความแชร์อีกที ขอบคุงจ้า ^^


ประวัติการแก้ไข
2012-09-21 10:01:33
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-21 10:01:07 By : hamutaru
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เยี่ยมครับ เอามาโพสไว้ในนี้ก็ได้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-21 10:16:41 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเรื่องการออก PDF โดยไม่ใช้ Crystal Report โดยใช้ library PdfSharp
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่