|  | 
 
| การพิมพ์บาร์โค้ดทั้ง 1 มิติ (บาร์โค้ดแบบแท่ง) และ 2 มิติ (QR Code) แสดงผลในเอกสาร PDF ด้วย Syncfusion ... 
 
 
  
 
 มาดูโค้ดกันเถอะ ...
 
 คัดลอกไปที่คลิปบอร์ด'// Add References ...
'// Syncfusion.Pdf.Base.dll
'// Syncfusion.PdfViewer.Windows.dll
'// Syncfusion.Shared.Base.dll
Imports System.Drawing
Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Barcode
Imports Syncfusion.Pdf.Graphics
Public Class frmBarcodePDF
    Private Sub frmBarcodePDF_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim strPathPDF As String = MyPath(Application.StartupPath)
        '// Create a new PDF document.
        Dim document As New PdfDocument()
        '// Adding new page to PDF document.
        Dim page As PdfPage = document.Pages.Add()
        Dim HeaderFont As PdfFont = New PdfTrueTypeFont(New Font("Helvetica", 18, FontStyle.Bold))
        '/ Create PDF graphics for the page.
        Dim graphics As PdfGraphics = page.Graphics
        '/ Draw the text.
        graphics.DrawString("Print barcode to pdf document using Syncfusion.", HeaderFont, PdfBrushes.Black, New PointF(20, 10))
        ' / --------------------------------------------------------------------------------
        '// Drawing Code128B barcode.
        ' / --------------------------------------------------------------------------------
        Dim barcode As New PdfCode128BBarcode ' PdfCode39Barcode()
        With barcode
            '// Set height of the barcode. 
            .BarHeight = 45
            '// Setting text of the barcode.
            .Text = "3720750441"
            '// Draw string
            page.Graphics.DrawString("Code128B", New PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold), PdfBrushes.Black, New PointF(20, 50))
            '// Printing barcode on to the PDF.
            .Draw(page, New PointF(50, 70))
        End With
        ' / --------------------------------------------------------------------------------
        '// Drawing QR Barcode.
        ' / --------------------------------------------------------------------------------
        Dim qrBarcode As New PdfQRBarcode()
        With qrBarcode
            '// Set Error Correction Level.
            .ErrorCorrectionLevel = PdfErrorCorrectionLevel.High
            '// Set XDimension.
            .XDimension = 3
            .Text = "สวัสดีครับผม" '"http://www.g2gsoft.com"
            '// Draw string.
            page.Graphics.DrawString("QR Barcode", New PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold), PdfBrushes.Black, New PointF(20, 160))
            '// Printing barcode on to the PDF.
            .Draw(page, New PointF(50, 170))
        End With
        ' / --------------------------------------------------------------------------------
        '// Save the document.
        document.Save(strPathPDF & "Barcode.pdf")
        '// Close the document
        document.Close(True)
        '// This will open the PDF file so, the result will be seen in default PDF viewer.
        '// Process.Start(strPathPDF & "Barcode.pdf")
        Me.PdfViewerControl1.Load(strPathPDF & "Barcode.pdf", "")
    End Sub
    Private Sub frmBarcodePDF_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Me.Dispose()
        GC.SuppressFinalize(Me)
        Application.Exit()
    End Sub
#Region "FUNCTION"
    ' / --------------------------------------------------------------------------------
    ' / Get my project path
    ' / AppPath = C:\My Project\bin\debug
    ' / Replace "\bin\debug" with ""
    ' / Return : C:\My Project\
    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", "")
        '// 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
 
 ดาวน์โหลดโค้ดต้นฉบับ Visual Basic .NET (2010) ได้ที่นี่ ...
 
 | 
 
xขออภัย! โพสต์นี้มีไฟล์แนบหรือรูปภาพที่ไม่ได้รับอนุญาตให้คุณเข้าถึงคุณจำเป็นต้อง ลงชื่อเข้าใช้ เพื่อดาวน์โหลดหรือดูไฟล์แนบนี้ คุณยังไม่มีบัญชีใช่ไหม? ลงทะเบียน  |