How to: Create Barcode
To create a barcode in a snap document, do the following:
- Call the IRichEditDocumentServer.LoadDocumentTemplate method to load the document template and open it for modification by calling the SubDocument.BeginUpdateCharacters method.
- Create a new SnapBarCode object by calling the ISnapFieldOwner.CreateSnBarCode method with the barcode placement position passed as a parameter.
- Call the ISnapFieldOwner.ParseField to convert the barcode field to a Snap Field. Note that if this step is skipped, you won’t be able to modify the barcode.
- Call the SnapEntity.BeginUpdate method to open the barcode for modification.
- Specify the desired barcode settings, such as orientation (SnapBarCode.Orientation), module (SnapBarCode.Module), and alignment (SnapBarCode.Alignment), etc.
- Finalize the modification by calling the SnapEntity.EndUpdate method.
- Call the FieldCollection.Update method to update the document fields.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/snap-document-server-api-t429162
server.LoadDocumentTemplate("Template.snx")
server.Document.BeginUpdate()
Dim barcode As SnapBarCode = server.Document.CreateSnBarCode(server.Document.Range.Start)
server.Document.ParseField(barcode.Field)
barcode.BeginUpdate()
barcode.DataFieldName = "EAN13"
barcode.Module = 10
barcode.Orientation = DevExpress.XtraPrinting.BarCode.BarCodeOrientation.Normal
barcode.AutoModule = True
barcode.ShowData = False
barcode.EndUpdate()
barcode.Field.Update()