ชุมชนคนรักภาษาเบสิค - Visual Basic Community

 ลืมรหัสผ่าน
 ลงทะเบียน
ค้นหา
ดู: 204|ตอบกลับ: 0

[VB.NET] การนำข้อมูลจาก TextBox Control แปลงเป็นไฟล์ PDF ด้วย Syncfusion

[คัดลอกลิงก์]

319

กระทู้

511

โพสต์

6436

เครดิต

ผู้ดูแลระบบ

ทองก้อน ทับทิมกรอบ

Rank: 9Rank: 9Rank: 9

เครดิต
6436







โค้ด VB.NET ในการนำข้อมูลจาก TextBox Control แปลงเป็นไฟล์ PDF ด้วย Syncfusion ...

ดาวน์โหลด Syncfusion Community Free Edition ได้ที่นี่ ...

มาดูโค้ดฉบับเต็มกันเถอะ ...
  1. Imports Syncfusion.Pdf
  2. Imports Syncfusion.Pdf.Graphics

  3. Public Class frmTextboxToPDF
  4.     Dim strPathPDF As String = MyPath(Application.StartupPath) & "PDF"

  5.     Private Sub frmTextboxToPDF_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  6.         Me.TextBoxExt1.Text = _
  7.             "ผู้ชายคนหนึ่งที่รักและหลงใหลในภาษาเบสิค เพราะมันตอบโจทย์ให้กับลูกค้าได้หมด" & vbCrLf & _
  8.             "และสามารถทำเงินมาเลี้ยงดูลูกเมียได้ แล้วยังจะมาสงสัยในความเก่งของตัวแปลภาษา" & vbCrLf & _
  9.             "และคนใช้ภาษาโปรแกรมกันไปทำไม ... อินดี้ฟรีแลนซ์สายทำมะ"
  10.         If (Not System.IO.Directory.Exists(strPathPDF)) Then System.IO.Directory.CreateDirectory(strPathPDF)
  11.         Call CreatePDF()
  12.     End Sub

  13.     Private Sub CreatePDF()
  14.         Dim document = New PdfDocument()
  15.         '// Set viewer preferences for the reader
  16.         document.ViewerPreferences.HideMenubar = True
  17.         document.ViewerPreferences.HideWindowUI = True
  18.         document.ViewerPreferences.HideToolbar = True
  19.         document.ViewerPreferences.FitWindow = True
  20.         document.ViewerPreferences.PageLayout = PdfPageLayout.SinglePage
  21.         document.PageSettings.Orientation = PdfPageOrientation.Portrait
  22.         document.PageSettings.Margins.All = 0

  23.         '// Set page size
  24.         Dim pageSize = New SizeF(500, 310)
  25.         document.PageSettings.Width = pageSize.Width
  26.         document.PageSettings.Height = pageSize.Height

  27.         '// Initialize font and brush
  28.         '/ Add a page.
  29.         Dim page As PdfPage = document.Pages.Add()
  30.         '/ Create PDF graphics for the page.
  31.         Dim graphics As PdfGraphics = page.Graphics
  32.         '/ Create a solid brush.
  33.         Dim brush As PdfBrush = New PdfSolidBrush(Color.Black)
  34.         '/ Set the font.
  35.         Dim font As PdfFont = New PdfTrueTypeFont(New Font("Arial Unicode MS", 16), 13, True)
  36.         '/ Draw the text.
  37.         graphics.DrawString(Me.TextBoxExt1.Text, font, brush, New PointF(20, 20))

  38.         '/ Save the document.
  39.         Dim pdfFile As String = strPathPDF & "sample.pdf"
  40.         document.Save(pdfFile)
  41.         document.Close(True)
  42.         '// Show PDF File in PdfViewerControl.
  43.         Me.PdfViewerControl1.Load(strPathPDF & "sample.pdf", "")
  44.     End Sub

  45.     Private Sub btnPreview_Click(sender As System.Object, e As System.EventArgs) Handles btnPreview.Click
  46.         Call CreatePDF()
  47.     End Sub

  48.     Private Sub frmTextboxToPDF_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
  49.         Me.Dispose()
  50.         GC.SuppressFinalize(Me)
  51.         End
  52.     End Sub

  53.     Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
  54.         Me.Close()
  55.     End Sub

  56. #Region "FUNCTION"
  57.     Function MyPath(ByVal AppPath As String) As String
  58.         '/ MessageBox.Show(AppPath);
  59.         AppPath = AppPath.ToLower()
  60.         '/ Return Value
  61.         MyPath = AppPath.Replace("\bin\debug", "").Replace("\bin\release", "").Replace("\bin\x86\debug", "").Replace("\bin\x86\release", "")
  62.         '// If not found folder then put the \ (BackSlash) at the end.
  63.         If Microsoft.VisualBasic.Right(MyPath, 1) <> Chr(92) Then MyPath = MyPath & Chr(92)
  64.     End Function
  65. #End Region
  66. End Class
คัดลอกไปที่คลิปบอร์ด


ดาวน์โหลดโค้ดต้นฉบับ VB.NET (2010) ได้ที่นี่ ...

ขออภัย! โพสต์นี้มีไฟล์แนบหรือรูปภาพที่ไม่ได้รับอนุญาตให้คุณเข้าถึง

คุณจำเป็นต้อง ลงชื่อเข้าใช้ เพื่อดาวน์โหลดหรือดูไฟล์แนบนี้ คุณยังไม่มีบัญชีใช่ไหม? ลงทะเบียน

x
สิ่งที่ดีกว่าการให้ คือการให้แบบไม่มีที่สิ้นสุด
ขออภัย! คุณไม่ได้รับสิทธิ์ในการดำเนินการในส่วนนี้ กรุณาเลือกอย่างใดอย่างหนึ่ง ลงชื่อเข้าใช้ | ลงทะเบียน

รายละเอียดเครดิต

ข้อความล้วน|อุปกรณ์พกพา|ประวัติการแบน|G2GNet.com  

GMT+7, 2024-9-21 10:12 , Processed in 0.120561 second(s), 5 queries , File On.

Powered by Discuz! X3.4, Rev.62

Copyright © 2001-2020 Tencent Cloud.

ตอบกระทู้ ขึ้นไปด้านบน ไปที่หน้ารายการกระทู้