Imports ThoughtWorks.QRCode.Codec
Imports ThoughtWorks.QRCode.Codec.Data
Imports ThoughtWorks.QRCode.Codec.Util
......
Private Sub print_qr()
Dim reportDoc As New ReportDocument
Dim rpt_ds As DataSet = GetDS("")
If rpt_ds.Tables(0) Is Nothing Then
lblDBErrorMessage.Text = "No Data!"
Exit Sub
End If
If rpt_ds.Tables(0).Rows.Count <= 0 Then
lblDBErrorMessage.Text = "No Data!"
Exit Sub
End If
reportDoc.Load(Server.MapPath("./rpt/QRC_print.rpt"))
reportDoc.SetDataSource(rpt_ds)
'印到PDF -------------
Dim objFile As New DiskFileDestinationOptions
reportDoc.ExportOptions.DestinationOptions = objFile
objFile.DiskFileName = Server.MapPath("./printemp/QRC_print.pdf")
With reportDoc.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = objFile
End With
reportDoc.Export()
Dim xlsurl As String = "./printemp/QRC_print.pdf"
Response.Redirect(xlsurl)
Exit Sub
'OR 直接列印 ---------------
Try
reportDoc.PrintOptions.PrinterName = strpath
reportDoc.PrintToPrinter(1, True, 0, 0)
'Response.Redirect(strRturnTo)
Catch
lblDBErrorMessage.Text = "找不到指定的印表機!"
End Try
End Sub
Function GetDS(ByVal vd_no) As DataSet
Dim strSQL As String
Dim ds As DS_QRC = New DS_QRC
......
Dim data As String = "Your TEXT here"
Dim v_copy As Integer = 1 ' 列印份數
Dim qrCodeEncoder As QRCodeEncoder = New QRCodeEncoder
qrCodeEncoder.QRCodeEncodeMode = qrCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC
qrCodeEncoder.QRCodeScale = 6
qrCodeEncoder.QRCodeVersion = 2
qrCodeEncoder.QRCodeErrorCorrect = qrCodeEncoder.ERROR_CORRECTION.L
Dim image As Image
image = qrCodeEncoder.Encode(data)
Dim ms As MemoryStream = New MemoryStream
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim ImageSize As Integer = ms.Length
Dim ImageContent() As Byte = ms.GetBuffer
ms.Close()
image.Dispose()
Dim j As Integer
For j = 1 To v_copy
MyNewRow = ds.Tables("T_QRCode").NewRow
MyNewRow("QR_pno") = v_sname
MyNewRow("QR_sno1") = v_ss
MyNewRow("QR_sno2") = v_ee
MyNewRow("QR_img") = ImageContent
MyNewRow("QR_supname") = v_supname
MyNewRow("QR_mno") = v_mno
If ii = v_boxs Then
MyNewRow("QR_qty") = v_pqtyp
Else
MyNewRow("QR_qty") = v_pqty
End If
ds.Tables("T_QRCode").Rows.Add(MyNewRow)
Next
......
Return ds
End Function
註:
ThoughtWorks.QRCode.dll - ThoughtWorks QRCode .NET Library is download available from CodeProject.com.