Leadtools.Services.Barcode.ServiceContracts Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
Write Method
See Also  Example
Leadtools.Services.Barcode.ServiceContracts Namespace > IBarcodeService Interface : Write Method



request
A DataContractAttribute containing the data that will be used by this Write operation.
request
A DataContractAttribute containing the data that will be used by this Write operation.
Writes linear, PDF417, MicroPDF417, Data Matrix, and QR barcode symbols over the image.

Syntax

Visual Basic (Declaration) 
<OperationContractAttribute("Write")>
<FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   HasProtectionLevel=False)>
Overridable Function Write( _
   ByVal request As WriteRequest _
) As WriteResponse
Visual Basic (Usage)Copy Code
Dim instance As IBarcodeService
Dim request As WriteRequest
Dim value As WriteResponse
 
value = instance.Write(request)
C# 
[OperationContractAttribute("Write")]
[FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   HasProtectionLevel=false)]
virtual WriteResponse Write( 
   WriteRequest request
)
C++/CLI 
[OperationContractAttribute("Write")]
[FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   HasProtectionLevel=false)]
virtual WriteResponse Write( 
   WriteRequest request
) 

Parameters

request
A DataContractAttribute containing the data that will be used by this Write operation.

Return Value

A DataContractAttribute containing the document data resulting from the Write operation.

Example

Visual BasicCopy Code
Private Function ConvertFromStringArray(ByVal data As String()) As Byte()
   If data Is Nothing OrElse data.Length = 0 Then
      Return Nothing
   End If

   Dim list As New List(Of Byte())
   Dim ascii As ASCIIEncoding = New ASCIIEncoding()

   Dim length As Integer = 0
   Dim i As Integer = 0
   Do While i < data.Length
      Dim bytes As Byte() = ascii.GetBytes(data(i))
      list.Add(bytes)
      length += bytes.Length
      length += 1
      i += 1
   Loop

   Dim ret As Byte() = New Byte(length - 1) {}
   Dim index As Integer = 0
   i = 0
   Do While i < list.Count
      Dim bytes As Byte() = list(i)
      bytes.CopyTo(ret, index)
      index += bytes.Length + 1
      i += 1
   Loop

   Return ret
End Function


Public Sub WriteExample()
   Dim client As BarcodeServiceClient = New BarcodeServiceClient()

   Dim sourceBinaryData As RawBinaryData = New RawBinaryData()
   sourceBinaryData.Data = File.ReadAllBytes(LeadtoolsExamples.Common.ImagesPath.Path & "barcode1.tif")

   Dim convertOptions As RasterConvertOptions = New RasterConvertOptions()
   convertOptions.Source = sourceBinaryData
   convertOptions.Destination = Nothing
   convertOptions.Format = RasterImageFormat.RasPdf
   convertOptions.FirstPage = 1
   convertOptions.LastPage = 1
   convertOptions.BitsPerPixel = 24
   convertOptions.QualityFactor = 2

   Dim rc As LeadRectangle = New LeadRectangle()
   rc.X = 100
   rc.Y = 0
   rc.Width = 0
   rc.Height = 0

   Dim barcodeText As String()
   barcodeText = New String(0) {}

   Dim matrixData As BarcodeData = New BarcodeData()
   matrixData.Location = rc
   barcodeText(0) = "Data Matrix Default Size"
   matrixData.Data = ConvertFromStringArray(barcodeText)

   Dim postData As BarcodeData = New BarcodeData()
   rc.X = 50
   rc.Y = 50
   rc.Width = 300
   rc.Height = 200
   postData.Location = rc
   barcodeText(0) = "12345678901"
   postData.Data = ConvertFromStringArray(barcodeText)

   Dim standardData As BarcodeData = New BarcodeData()
   rc.X = 360
   rc.Y = 50
   rc.Width = 300
   rc.Height = 250
   standardData.Location = rc
   barcodeText(0) = "012345678901"
   standardData.Data = ConvertFromStringArray(barcodeText)

   Dim patchData As BarcodeData = New BarcodeData()
   rc.X = 660
   rc.Y = 50
   rc.Width = 200
   rc.Height = 450
   patchData.Location = rc
   barcodeText(0) = "1100"
   patchData.Data = ConvertFromStringArray(barcodeText)

   Dim stackedData As BarcodeData = New BarcodeData()
   rc.X = 860
   rc.Y = 50
   rc.Width = 300
   rc.Height = 450
   patchData.Location = rc
   stackedData.Location = rc
   barcodeText(0) = "1234567890123"
   stackedData.Data = ConvertFromStringArray(barcodeText)

   Dim pdf417Data As BarcodeData = New BarcodeData()
   rc.X = 50
   rc.Y = 400
   rc.Width = 0
   rc.Height = 0
   pdf417Data.Location = rc
   barcodeText(0) = "Pdf417"
   pdf417Data.Data = ConvertFromStringArray(barcodeText)

   Dim microPdf417Data As BarcodeData = New BarcodeData()
   rc.X = 200
   rc.Y = 600
   rc.Width = 0
   rc.Height = 0
   microPdf417Data.Location = rc
   barcodeText(0) = "Micro Pdf417"
   microPdf417Data.Data = ConvertFromStringArray(barcodeText)

   Dim qrData As BarcodeData = New BarcodeData()
   rc.X = 200
   rc.Y = 400
   rc.Width = 0
   rc.Height = 0
   qrData.Location = rc
   barcodeText(0) = "QR Code Model 2 AutoSize"
   qrData.Data = ConvertFromStringArray(barcodeText)

   Dim barColor As BarcodeColor = New BarcodeColor()
   barColor.BarColor = "Black"
   barColor.SpaceColor = "White"

   Dim bar1d As Barcode1d = New Barcode1d()
   bar1d.OutShowText = True

   Dim barPDF As BarcodeWritePdf = New BarcodeWritePdf()
   barPDF.AspectHeight = 0
   barPDF.AspectWidth = 0
   barPDF.Columns = 0
   barPDF.Rows = 0
   barPDF.EccLevel = BarcodePdf417EccLevelFlags.UsePercent
   barPDF.EccPercentage = 50
   barPDF.Justify = BarcodeJustifyFlags.Right
   barPDF.Module = 21
   barPDF.ModAspectRatio = 4

   Dim barDM As BarcodeWriteDatamatrix = New BarcodeWriteDatamatrix()

   barDM.Justify = BarcodeJustifyFlags.Right
   barDM.FileIdHigh = 0
   barDM.FileIdLow = 0
   barDM.GroupNumber = 0
   barDM.GroupTotal = 0
   barDM.XModule = 0

   Dim barQR As BarcodeWriteQr = New BarcodeWriteQr()

   Dim options As WriteOptions = New WriteOptions()
   Dim dataMatrix As WriteBarcode2DDataMatrix = New WriteBarcode2DDataMatrix()
   dataMatrix.Type = WriteBarcode2DDataMatrixType.DatamatrixDefault
   dataMatrix.Data = matrixData

   options.Add(dataMatrix)

   Dim standard As WriteBarcode1dStandard = New WriteBarcode1dStandard()
   standard.Type = WriteBarcodeStandardFlags.Ean13
   standard.Data = standardData

   options.Add(standard)

   Dim post As WriteBarcode1dPost = New WriteBarcode1dPost()
   post.Type = WriteBarcode1dPostType.Planet
   post.Data = postData

   options.Add(post)

   Dim patch As WriteBarcode1dPatch = New WriteBarcode1dPatch()
   patch.Type = WriteBarcode1dPatchType.Patchcode
   patch.Data = patchData

   options.Add(patch)

   Dim stacked As WriteBarcode1dStacked = New WriteBarcode1dStacked()
   stacked.Type = WriteBarcode1dStackedType.Rss14Stacked
   stacked.Data = stackedData

   options.Add(stacked)

   Dim pdf417 As WriteBarcode2DPdf417 = New WriteBarcode2DPdf417()
   pdf417.Type = WriteBarcode2DPdf417Type.Pdf417
   pdf417.Data = pdf417Data

   options.Add(pdf417)

   Dim microPdf417 As WriteBarcode2DMicroPdf417 = New WriteBarcode2DMicroPdf417()
   microPdf417.Type = WriteBarcode2DMicroPdf417Type.MicroPdf417
   microPdf417.Data = microPdf417Data

   options.Add(microPdf417)

   Dim qr As WriteBarcode2DQr = New WriteBarcode2DQr()
   qr.Type = WriteBarcode2DQrType.Default
   qr.Data = qrData

   options.Add(qr)

   Dim request As WriteRequest = New WriteRequest()

   request.Code1d = bar1d
   request.CodeColor = barColor
   request.CodeDatamatrix = barDM
   request.CodePdf = barPDF
   request.CodeQr = barQR
   request.ConvertOptions = convertOptions
   request.TypeFlags = BarcodeMajorTypeFlags.BarcodesDatamatrixWrite
   request.Unit = BarcodeUnit.ScanlinesPerPixels
   request.WriteFlags = BarcodeWriteFlags.UseColors Or BarcodeWriteFlags.Transparent Or BarcodeWriteFlags.InitializationReader Or BarcodeWriteFlags.DisableCompression
   request.WriteOptions = options

   Dim response As WriteResponse = client.Write(request)

   If Not response.Destination Is Nothing Then
      If TypeOf response.Destination Is RawBinaryData Then
         File.WriteAllBytes(LeadtoolsExamples.Common.ImagesPath.Path & "Write_Barcode.Pdf", (TryCast(response.Destination, RawBinaryData)).Data)
      End If
   End If

   client.Close()
End Sub
C#Copy Code
byte[] ConvertFromStringArray(string[] data) 

   if (data == null || data.Length == 0) 
      return null; 
 
   List<byte[]> list = new List<byte[]>(); 
   ASCIIEncoding ascii = new ASCIIEncoding(); 
 
   int length = 0; 
   for (int i = 0; i < data.Length; i++) 
   { 
      byte[] bytes = ascii.GetBytes(data[i]); 
      list.Add(bytes); 
      length += bytes.Length; 
      length++; 
   } 
 
   byte[] ret = new byte[length]; 
   int index = 0; 
   for (int i = 0; i < list.Count; i++) 
   { 
      byte[] bytes = list[i]; 
      bytes.CopyTo(ret, index); 
      index += bytes.Length + 1; 
   } 
 
   return ret; 

 
 
public void WriteExample() 

   BarcodeServiceClient client = new BarcodeServiceClient(); 
 
   RawBinaryData sourceBinaryData = new RawBinaryData(); 
   sourceBinaryData.Data = File.ReadAllBytes(LeadtoolsExamples.Common.ImagesPath.Path + "barcode1.tif"); 
 
   RasterConvertOptions convertOptions = new RasterConvertOptions(); 
   convertOptions.Source = sourceBinaryData; 
   convertOptions.Destination = null; 
   convertOptions.Format = RasterImageFormat.RasPdf; 
   convertOptions.FirstPage = 1; 
   convertOptions.LastPage = 1; 
   convertOptions.BitsPerPixel = 24; 
   convertOptions.QualityFactor = 2; 
 
   LeadRectangle rc = new LeadRectangle(); 
   rc.X = 100; 
   rc.Y = 0; 
   rc.Width = 0; 
   rc.Height = 0; 
 
   string[] barcodeText; 
   barcodeText = new string[1]; 
 
   BarcodeData matrixData = new BarcodeData(); 
   matrixData.Location = rc; 
   barcodeText[0] = "Data Matrix Default Size"; 
   matrixData.Data = ConvertFromStringArray(barcodeText); 
 
   BarcodeData postData = new BarcodeData(); 
   rc.X = 50; 
   rc.Y = 50; 
   rc.Width = 300; 
   rc.Height = 200; 
   postData.Location = rc; 
   barcodeText[0] = "12345678901"; 
   postData.Data = ConvertFromStringArray(barcodeText); 
 
   BarcodeData standardData = new BarcodeData(); 
   rc.X = 360; 
   rc.Y = 50; 
   rc.Width = 300; 
   rc.Height = 250; 
   standardData.Location = rc; 
   barcodeText[0] = "012345678901"; 
   standardData.Data = ConvertFromStringArray(barcodeText); 
 
   BarcodeData patchData = new BarcodeData(); 
   rc.X = 660; 
   rc.Y = 50; 
   rc.Width = 200; 
   rc.Height = 450; 
   patchData.Location = rc; 
   barcodeText[0] = "1100"; 
   patchData.Data = ConvertFromStringArray(barcodeText); 
 
   BarcodeData stackedData = new BarcodeData(); 
   rc.X = 860; 
   rc.Y = 50; 
   rc.Width = 300; 
   rc.Height = 450; 
   patchData.Location = rc; 
   stackedData.Location = rc; 
   barcodeText[0] = "1234567890123"; 
   stackedData.Data = ConvertFromStringArray(barcodeText); 
 
   BarcodeData pdf417Data = new BarcodeData(); 
   rc.X = 50; 
   rc.Y = 400; 
   rc.Width = 0; 
   rc.Height = 0; 
   pdf417Data.Location = rc; 
   barcodeText[0] = "Pdf417"; 
   pdf417Data.Data = ConvertFromStringArray(barcodeText); 
 
   BarcodeData qrData = new BarcodeData(); 
   rc.X = 200; 
   rc.Y = 400; 
   rc.Width = 0; 
   rc.Height = 0; 
   qrData.Location = rc; 
   barcodeText[0] = "QR Code Model 2 AutoSize"; 
   qrData.Data = ConvertFromStringArray(barcodeText); 
 
   BarcodeData microPdf417Data = new BarcodeData(); 
   rc.X = 200; 
   rc.Y = 600; 
   rc.Width = 0; 
   rc.Height = 0; 
   microPdf417Data.Location = rc; 
   barcodeText[0] = "Micro Pdf417"; 
   microPdf417Data.Data = ConvertFromStringArray(barcodeText); 
 
   BarcodeColor barColor = new BarcodeColor(); 
   barColor.BarColor = "Black"; 
   barColor.SpaceColor = "White"; 
 
   Barcode1d bar1d = new Barcode1d(); 
   bar1d.OutShowText = true; 
 
   BarcodeWritePdf barPDF = new BarcodeWritePdf(); 
   barPDF.AspectHeight = 0; 
   barPDF.AspectWidth = 0; 
   barPDF.Columns = 0; 
   barPDF.Rows = 0; 
   barPDF.EccLevel = BarcodePdf417EccLevelFlags.UsePercent; 
   barPDF.EccPercentage = 50; 
   barPDF.Justify = BarcodeJustifyFlags.Right; 
   barPDF.Module = 21; 
   barPDF.ModAspectRatio = 4; 
 
   BarcodeWriteDatamatrix barDM = new BarcodeWriteDatamatrix(); 
 
   barDM.Justify = BarcodeJustifyFlags.Right; 
   barDM.FileIdHigh = 0; 
   barDM.FileIdLow = 0; 
   barDM.GroupNumber = 0; 
   barDM.GroupTotal = 0; 
   barDM.XModule = 0; 
 
   BarcodeWriteQr barQR = new BarcodeWriteQr(); 
 
   WriteOptions options = new WriteOptions(); 
   WriteBarcode2DDataMatrix dataMatrix = new WriteBarcode2DDataMatrix(); 
   dataMatrix.Type = WriteBarcode2DDataMatrixType.DatamatrixDefault; 
   dataMatrix.Data = matrixData; 
 
   options.Add(dataMatrix); 
 
   WriteBarcode1dStandard standard = new WriteBarcode1dStandard(); 
   standard.Type = WriteBarcodeStandardFlags.Ean13; 
   standard.Data = standardData; 
 
   options.Add(standard); 
 
   WriteBarcode1dPost post = new WriteBarcode1dPost(); 
   post.Type = WriteBarcode1dPostType.Planet; 
   post.Data = postData; 
 
   options.Add(post); 
 
   WriteBarcode1dPatch patch = new WriteBarcode1dPatch(); 
   patch.Type = WriteBarcode1dPatchType.Patchcode; 
   patch.Data = patchData; 
 
   options.Add(patch); 
 
   WriteBarcode1dStacked stacked = new WriteBarcode1dStacked(); 
   stacked.Type = WriteBarcode1dStackedType.Rss14Stacked; 
   stacked.Data = stackedData; 
 
   options.Add(stacked); 
 
   WriteBarcode2DPdf417 pdf417 = new WriteBarcode2DPdf417(); 
   pdf417.Type = WriteBarcode2DPdf417Type.Pdf417; 
   pdf417.Data = pdf417Data; 
 
   options.Add(pdf417); 
 
   WriteBarcode2DMicroPdf417 microPdf417 = new WriteBarcode2DMicroPdf417(); 
   microPdf417.Type = WriteBarcode2DMicroPdf417Type.MicroPdf417; 
   microPdf417.Data = microPdf417Data; 
 
   options.Add(microPdf417); 
 
   WriteBarcode2DQr qr = new WriteBarcode2DQr(); 
   qr.Type = WriteBarcode2DQrType.Default; 
   qr.Data = qrData; 
 
   options.Add(qr); 
 
   WriteRequest request = new WriteRequest(); 
 
   request.Code1d = bar1d; 
   request.CodeColor = barColor; 
   request.CodeDatamatrix = barDM; 
   request.CodePdf = barPDF; 
   request.CodeQr = barQR; 
   request.ConvertOptions = convertOptions; 
   request.TypeFlags = BarcodeMajorTypeFlags.BarcodesDatamatrixWrite; 
   request.Unit = BarcodeUnit.ScanlinesPerPixels; 
   request.WriteFlags = BarcodeWriteFlags.UseColors | BarcodeWriteFlags.Transparent | BarcodeWriteFlags.InitializationReader | BarcodeWriteFlags.DisableCompression; 
   request.WriteOptions = options; 
 
   WriteResponse response = client.Write(request); 
 
   if (response.Destination != null) 
   { 
      if (response.Destination is RawBinaryData) 
      { 
         File.WriteAllBytes(LeadtoolsExamples.Common.ImagesPath.Path + "Write_Barcode.Pdf", (response.Destination as RawBinaryData).Data); 
      } 
   } 
 
   client.Close(); 
}

Remarks

This operation supports all image formats currently supported by LEADTOOLS.

You must pass a valid image to this operation. If you do not pass a valid image, the operation will throw an exception.

The Write operation will write the barcode symbol over the image using the rectangle defined by the Leadtools.Services.Barcode.DataContracts.BarcodeData.Location property.

However, if the bitmap has a region, this operation will write the barcode using the region boundaries. If the region is non-rectangular, the barcode will be written to the rectangle bounding the region and subsequently clipped to the given region. This might cause the resulting barcode to be unreadable.

If you set the Leadtools.Services.Barcode.DataContracts.WriteRequest.WriteFlags property to Leadtools.Services.Barcode.DataContracts.BarcodeWriteFlags.UseColors, then this operation will use the Leadtools.Services.Barcode.DataContracts.WriteRequest.CodeColor property. Otherwise the operation will ignore it and use the default colors (black for bars and white for spaces).

The Leadtools.Services.Barcode.DataContracts.BarcodeReadFlags.UseColors enumeration value does not apply to 1 bit per pixel images.

The Leadtools.Services.Barcode.DataContracts.BarcodeWriteFlags.UseColors and Leadtools.Services.Barcode.DataContracts.BarcodeWriteFlags.Transparent values are used with all barcode types.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

Applications developed with LEADTOOLS WCF components require runtime licenses. Server licensing is required for applications on a server. For more information, refer to: Imaging Pro/Document/Medical Features