| 
 | 
 
  
 
 
  
 
 
โค้ด VB.NET ในการนำข้อมูลจาก TextBox Control แปลงเป็นไฟล์ PDF ด้วย Syncfusion ...  
 
ดาวน์โหลด Syncfusion Community Free Edition ได้ที่นี่ ... 
 
มาดูโค้ดฉบับเต็มกันเถอะ ...  
- Imports Syncfusion.Pdf
 
 - Imports Syncfusion.Pdf.Graphics
 
  
- Public Class frmTextboxToPDF
 
 -     Dim strPathPDF As String = MyPath(Application.StartupPath) & "PDF"
 
  
-     Private Sub frmTextboxToPDF_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
 
 -         Me.TextBoxExt1.Text = _
 
 -             "ผู้ชายคนหนึ่งที่รักและหลงใหลในภาษาเบสิค เพราะมันตอบโจทย์ให้กับลูกค้าได้หมด" & vbCrLf & _
 
 -             "และสามารถทำเงินมาเลี้ยงดูลูกเมียได้ แล้วยังจะมาสงสัยในความเก่งของตัวแปลภาษา" & vbCrLf & _
 
 -             "และคนใช้ภาษาโปรแกรมกันไปทำไม ... อินดี้ฟรีแลนซ์สายทำมะ"
 
 -         If (Not System.IO.Directory.Exists(strPathPDF)) Then System.IO.Directory.CreateDirectory(strPathPDF)
 
 -         Call CreatePDF()
 
 -     End Sub
 
  
-     Private Sub CreatePDF()
 
 -         Dim document = New PdfDocument()
 
 -         '// Set viewer preferences for the reader 
 
 -         document.ViewerPreferences.HideMenubar = True
 
 -         document.ViewerPreferences.HideWindowUI = True
 
 -         document.ViewerPreferences.HideToolbar = True
 
 -         document.ViewerPreferences.FitWindow = True
 
 -         document.ViewerPreferences.PageLayout = PdfPageLayout.SinglePage
 
 -         document.PageSettings.Orientation = PdfPageOrientation.Portrait
 
 -         document.PageSettings.Margins.All = 0
 
  
-         '// Set page size
 
 -         Dim pageSize = New SizeF(500, 310)
 
 -         document.PageSettings.Width = pageSize.Width
 
 -         document.PageSettings.Height = pageSize.Height
 
  
-         '// Initialize font and brush
 
 -         '/ Add a page.
 
 -         Dim page As PdfPage = document.Pages.Add()
 
 -         '/ Create PDF graphics for the page.
 
 -         Dim graphics As PdfGraphics = page.Graphics
 
 -         '/ Create a solid brush.
 
 -         Dim brush As PdfBrush = New PdfSolidBrush(Color.Black)
 
 -         '/ Set the font.
 
 -         Dim font As PdfFont = New PdfTrueTypeFont(New Font("Arial Unicode MS", 16), 13, True)
 
 -         '/ Draw the text.
 
 -         graphics.DrawString(Me.TextBoxExt1.Text, font, brush, New PointF(20, 20))
 
  
-         '/ Save the document.
 
 -         Dim pdfFile As String = strPathPDF & "sample.pdf"
 
 -         document.Save(pdfFile)
 
 -         document.Close(True)
 
 -         '// Show PDF File in PdfViewerControl.
 
 -         Me.PdfViewerControl1.Load(strPathPDF & "sample.pdf", "")
 
 -     End Sub
 
  
-     Private Sub btnPreview_Click(sender As System.Object, e As System.EventArgs) Handles btnPreview.Click
 
 -         Call CreatePDF()
 
 -     End Sub
 
  
-     Private Sub frmTextboxToPDF_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
 
 -         Me.Dispose()
 
 -         GC.SuppressFinalize(Me)
 
 -         End
 
 -     End Sub
 
  
-     Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
 
 -         Me.Close()
 
 -     End Sub
 
  
- #Region "FUNCTION"
 
 -     Function MyPath(ByVal AppPath As String) As String
 
 -         '/ MessageBox.Show(AppPath);
 
 -         AppPath = AppPath.ToLower()
 
 -         '/ Return Value
 
 -         MyPath = AppPath.Replace("\bin\debug", "").Replace("\bin\release", "").Replace("\bin\x86\debug", "").Replace("\bin\x86\release", "")
 
 -         '// If not found folder then put the \ (BackSlash) at the end.
 
 -         If Microsoft.VisualBasic.Right(MyPath, 1) <> Chr(92) Then MyPath = MyPath & Chr(92)
 
 -     End Function
 
 - #End Region
 
 - End Class
 
  คัดลอกไปที่คลิปบอร์ด 
 
ดาวน์โหลดโค้ดต้นฉบับ VB.NET (2010) ได้ที่นี่ ...  
 |   
ขออภัย! โพสต์นี้มีไฟล์แนบหรือรูปภาพที่ไม่ได้รับอนุญาตให้คุณเข้าถึง
คุณจำเป็นต้อง ลงชื่อเข้าใช้ เพื่อดาวน์โหลดหรือดูไฟล์แนบนี้ คุณยังไม่มีบัญชีใช่ไหม? ลงทะเบียน  
 
x
 
 
 
 
 |