Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created August 14, 2021 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/3f07e4f0b5facbd3ff0c50efab29d840 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/3f07e4f0b5facbd3ff0c50efab29d840 to your computer and use it in GitHub Desktop.
Generate Barcode using Java - Add Barcodes to Documents and Images using Java Signature API
// Generate and apply barcodes to documents (DOC, DOCX, PDF, PPT, XLS, XLSX, ...) in Java
Signature signature = new Signature("path/document.pdf");
// Create barcode option with barcode text
BarcodeSignOptions options = new BarcodeSignOptions("<00-0-0000-0> 2021-08");
options.setEncodeType(BarcodeTypes.Code128);
// Barcode Alignment and Appearance
options.setLeft(205);
options.setTop(170);
options.setHeight(50);
options.setWidth(200);
options.setForeColor(Color.BLUE);
options.setCodeTextAlignment(CodeTextAlignment.Below);
// Attach barcode with the document
signature.sign(outputFilePath, options);
// // Generate and apply barcodes to Images (JPG, PNG, BMP, ...) in Java
Signature signature = new Signature("path/image.jpg");
// Create barcode option with barcode text
BarcodeSignOptions options = new BarcodeSignOptions("<00-0-0000-0> 2021-08");
options.setEncodeType(BarcodeTypes.Code128);
// Barcode Alignment and Appearance
options.setLeft(100);
options.setTop(100);
options.setHeight(50);
options.setWidth(200);
options.setForeColor(Color.BLUE);
options.setCodeTextAlignment(CodeTextAlignment.Above);
// Attach barcode with the image
signature.sign(outputFilePath, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment