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

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

[VB.NET] การพิมพ์บาร์โค้ดทั้ง 1 มิติและ 2 มิติ แสดงผลในเอกสาร PDF ด้วย Syncfusion

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

311

กระทู้

502

โพสต์

6060

เครดิต

ผู้ดูแลระบบ

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

Rank: 9Rank: 9Rank: 9

เครดิต
6060

การพิมพ์บาร์โค้ดทั้ง 1 มิติ (บาร์โค้ดแบบแท่ง) และ 2 มิติ (QR Code) แสดงผลในเอกสาร PDF ด้วย Syncfusion ...





มาดูโค้ดกันเถอะ ...
  1. '// Add References ...
  2. '// Syncfusion.Pdf.Base.dll
  3. '// Syncfusion.PdfViewer.Windows.dll
  4. '// Syncfusion.Shared.Base.dll

  5. Imports System.Drawing
  6. Imports Syncfusion.Pdf
  7. Imports Syncfusion.Pdf.Barcode
  8. Imports Syncfusion.Pdf.Graphics

  9. Public Class frmBarcodePDF

  10.     Private Sub frmBarcodePDF_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  11.         Dim strPathPDF As String = MyPath(Application.StartupPath)
  12.         '// Create a new PDF document.
  13.         Dim document As New PdfDocument()
  14.         '// Adding new page to PDF document.
  15.         Dim page As PdfPage = document.Pages.Add()

  16.         Dim HeaderFont As PdfFont = New PdfTrueTypeFont(New Font("Helvetica", 18, FontStyle.Bold))
  17.         '/ Create PDF graphics for the page.
  18.         Dim graphics As PdfGraphics = page.Graphics
  19.         '/ Draw the text.
  20.         graphics.DrawString("Print barcode to pdf document using Syncfusion.", HeaderFont, PdfBrushes.Black, New PointF(20, 10))

  21.         ' / --------------------------------------------------------------------------------
  22.         '// Drawing Code128B barcode.
  23.         ' / --------------------------------------------------------------------------------
  24.         Dim barcode As New PdfCode128BBarcode ' PdfCode39Barcode()
  25.         With barcode
  26.             '// Set height of the barcode.
  27.             .BarHeight = 45
  28.             '// Setting text of the barcode.
  29.             .Text = "3720750441"
  30.             '// Draw string
  31.             page.Graphics.DrawString("Code128B", New PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold), PdfBrushes.Black, New PointF(20, 50))
  32.             '// Printing barcode on to the PDF.
  33.             .Draw(page, New PointF(50, 70))
  34.         End With
  35.         ' / --------------------------------------------------------------------------------
  36.         '// Drawing QR Barcode.
  37.         ' / --------------------------------------------------------------------------------
  38.         Dim qrBarcode As New PdfQRBarcode()
  39.         With qrBarcode
  40.             '// Set Error Correction Level.
  41.             .ErrorCorrectionLevel = PdfErrorCorrectionLevel.High
  42.             '// Set XDimension.
  43.             .XDimension = 3
  44.             .Text = "สวัสดีครับผม" '"http://www.g2gsoft.com"
  45.             '// Draw string.
  46.             page.Graphics.DrawString("QR Barcode", New PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold), PdfBrushes.Black, New PointF(20, 160))
  47.             '// Printing barcode on to the PDF.
  48.             .Draw(page, New PointF(50, 170))
  49.         End With

  50.         ' / --------------------------------------------------------------------------------
  51.         '// Save the document.
  52.         document.Save(strPathPDF & "Barcode.pdf")
  53.         '// Close the document
  54.         document.Close(True)
  55.         '// This will open the PDF file so, the result will be seen in default PDF viewer.
  56.         '// Process.Start(strPathPDF & "Barcode.pdf")
  57.         Me.PdfViewerControl1.Load(strPathPDF & "Barcode.pdf", "")

  58.     End Sub

  59.     Private Sub frmBarcodePDF_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
  60.         Me.Dispose()
  61.         GC.SuppressFinalize(Me)
  62.         Application.Exit()
  63.     End Sub

  64. #Region "FUNCTION"
  65.     ' / --------------------------------------------------------------------------------
  66.     ' / Get my project path
  67.     ' / AppPath = C:\My Project\bin\debug
  68.     ' / Replace "\bin\debug" with ""
  69.     ' / Return : C:\My Project\
  70.     Function MyPath(ByVal AppPath As String) As String
  71.         '/ MessageBox.Show(AppPath);
  72.         AppPath = AppPath.ToLower()
  73.         '/ Return Value
  74.         MyPath = AppPath.Replace("\bin\debug", "").Replace("\bin\release", "").Replace("\bin\x86\debug", "")
  75.         '// If not found folder then put the \ (BackSlash) at the end.
  76.         If Microsoft.VisualBasic.Right(MyPath, 1) <> Chr(92) Then MyPath = MyPath & Chr(92)
  77.     End Function
  78. #End Region
  79. End Class
คัดลอกไปที่คลิปบอร์ด



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

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

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

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

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

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

GMT+7, 2024-4-30 01:18 , Processed in 0.141749 second(s), 4 queries , File On.

Powered by Discuz! X3.4, Rev.62

Copyright © 2001-2020 Tencent Cloud.

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