A barcode or bar code is a way of presenting data in a visual, machine-readable form. Generally speaking, barcode is an image of a rectangular form that consists of parallel black lines and white spaces of different widths.
Barcodes are used in various areas where quick identification is necessary - as part of the purchase process in retail stores, in warehouses to track inventory, and on invoices to assist in accounting, among many other uses.
Barcodes allow storing of product-related data like manufacturing and expiry dates, manufacturer name, country of origin, and product price. There are plenty of barcode types nowadays because different companies use different combinations of numbers and bars in their barcodes depending on their needs. From the document signature perspective, Barcode may contain different characters (letters, digits, or symbols) and may have various lengths and sizes depending on the type and settings to keep signature information, title, subject, or short encrypted data.
How to eSign Document with Barcode Signature
GroupDocs.Signature for Python via .NET supports a wide range of Barcode types that can be used to create electronic signatures within the documents. Please refer to the BarcodeTypes description to get the full list of supported barcodes.
To specify different options for Barcode signature GroupDocs.Signature for Python via .NET provides BarcodeSignOptions class. The main fields are:
encode_type - specifies the Barcode type (AustralianPost, Codabar, EAN13, OPC, etc.);
Here are the steps to eSign a document with the Barcode signature using GroupDocs.Signature for Python via .NET API:
Create a new instance of Signature class and pass the source document path as a constructor parameter.
Instantiate the BarcodeSignOptions object according to your requirements and specify the Barcode type by setting the encode_type property with one of the predefined supported types. Set the text property value.
This example shows how to sign a PDF document with a Barcode signature using Python:
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportBarcodeSignOptionsfromgroupdocs.signature.domainimportBarcodeTypesdefsign_with_barcode_signature():withSignature("sample.pdf")assignature:# Create barcode signature options with the text to encodeoptions=BarcodeSignOptions("John Smith")# Set the barcode typeoptions.encode_type=BarcodeTypes.CODE128# Set barcode position and sizeoptions.left=100options.top=400options.width=300options.height=100# Sign the document and save the resultresult=signature.sign("signed_barcode.pdf",options)print(f"Signed with {len(result.succeeded)} barcode signature(s)")if__name__=="__main__":sign_with_barcode_signature()
sample.pdf is the sample file used in this example. Click here to download it.
You can customize the barcode signature further with additional options: alignment and margins, bar color, the position of the encoded text, inner margins, background, border and transparency:
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportBarcodeSignOptionsfromgroupdocs.signature.domainimport(Background,BarcodeTypes,Border,CodeTextAlignment,DashStyle,HorizontalAlignment,Padding,VerticalAlignment)fromgroupdocs.pydrawingimportColordefsign_with_barcode_signature_advanced():withSignature("sample.pdf")assignature:# Pass the text and the barcode type to the constructoroptions=BarcodeSignOptions("JohnSmith",BarcodeTypes.CODE128)# Put the barcode in the bottom right corner of the pageoptions.width=220options.height=80options.horizontal_alignment=HorizontalAlignment.RIGHToptions.vertical_alignment=VerticalAlignment.BOTTOMoptions.margin=Padding(right=40,bottom=60)# Bar color, encoded text below the bars, space inside the borderoptions.fore_color=Color.dark_blueoptions.code_text_alignment=CodeTextAlignment.BELOWoptions.inner_margins=Padding(5)# Background, border and transparencybackground=Background()background.color=Color.light_yellowoptions.background=backgroundborder=Border()border.color=Color.dark_blueborder.dash_style=DashStyle.DASHborder.weight=2border.visible=Trueoptions.border=borderoptions.transparency=0.2result=signature.sign("signed_barcode_advanced.pdf",options)print(f"Signed with {len(result.succeeded)} barcode signature(s)")if__name__=="__main__":sign_with_barcode_signature_advanced()
sample.pdf is the sample file used in this example. Click here to download it.
GroupDocs.Signature supports various barcode types. Each type accepts its own set of characters and lengths, so pick the text to match the type. This example signs a document with four barcodes of different types in one call:
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportBarcodeSignOptionsfromgroupdocs.signature.domainimportBarcodeTypesdefsign_with_different_barcode_types():barcodes=[(BarcodeTypes.EAN13,"123456789012"),# 12 digits, check digit added(BarcodeTypes.CODE39,"JOHN SMITH"),# upper-case letters, digits(BarcodeTypes.CODE128,"John Smith"),# any ASCII text(BarcodeTypes.PDF417,"John Smith, approved"),# 2D barcode for longer text]# One sign options object per barcode, placed one below anotheroptions_list=[]forindex,(encode_type,text)inenumerate(barcodes):options=BarcodeSignOptions(text,encode_type)options.left=100options.top=340+index*100options.width=240options.height=80options_list.append(options)withSignature("sample.pdf")assignature:result=signature.sign("signed_barcode_types.pdf",options_list)forbarcodeinresult.succeeded:print(f"{barcode.encode_type.type_name}: {barcode.text}")if__name__=="__main__":sign_with_different_barcode_types()
sample.pdf is the sample file used in this example. Click here to download it.
This guide demonstrates how to use GroupDocs.Signature for Python via .NET to add barcode-based signatures to documents. It covers creating, configuring, and applying barcode signatures with support for various barcode types and customization options. For further exploration, refer to related guides on document information and advanced signing techniques.
More Resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: