com.aspose.barcode.generation

Class BarcodeGenerator

  • java.lang.Object
    • com.aspose.barcode.generation.BarcodeGenerator


  • public final class BarcodeGenerator
    extends java.lang.Object

    BarcodeGenerator for backend barcode images generation.

    supported symbologies: 1D: Codabar, Code11, Code128, Code39Standard, Code39Extended Code93Standard, Code93Extended, EAN13, EAN8, Interleaved2of5, MSI, Standard2of5, UPCA, UPCE, ISBN, GS1Code128, Postnet, Planet EAN14, SCC14, SSCC18, ITF14, SingaporePost ... 2D: Aztec, DataMatrix, PDf417, QR code ...


      This sample shows how to create and save a barcode image.
      
             BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.CODE_128);
             generator.setCodeText("123ABC");
             generator.save("code128.png");
            
    • Constructor Detail

      • BarcodeGenerator

        public BarcodeGenerator(BaseEncodeType type)

        Creates an instance of BarcodeGenerator.

        Parameters:
        type - Barcode symbology type. Use EncodeTypes class to setup a symbology.
      • BarcodeGenerator

        public BarcodeGenerator(BaseEncodeType type,
                                java.lang.String codeText)

        Creates an instance of BarcodeGenerator.

        Parameters:
        type - Barcode symbology type. Use EncodeTypes class to setup a symbology.
        codeText - Text to be encoded.
    • Method Detail

      • getBarcodeType

        public BaseEncodeType getBarcodeType()

        Barcode symbology type.

      • setBarcodeType

        public void setBarcodeType(BaseEncodeType value)

        Barcode symbology type.

      • getCodeText

        public java.lang.String getCodeText()

        Text to be encoded.

      • setCodeText

        public void setCodeText(java.lang.String value)

        Text to be encoded.

      • generateBarCodeImage

        public Bitmap generateBarCodeImage()

        Generate the barcode image under current settings.


          This sample shows how to create and save a barcode image.
          
                 BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.CODE_128);
                 File outputFile = new File("test.png");
                 OutputStream os = new FileOutputStream(outputFile);
                 Bitmap generatedBitmap = generator.generateBarCodeImage();
                 generatedBitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
                 os.flush();
                 os.close();
                
        Returns:
        Barcode image. See Bitmap.
      • save

        public void save(java.io.OutputStream stream,
                         BarCodeImageFormat format)
                  throws java.io.IOException

        Save BarCodeImage to stream in specific format.

        Throws:
        java.io.IOException
      • save

        public void save(java.lang.String filename,
                         BarCodeImageFormat format)
                  throws java.io.IOException

        Save barcode image to specific file in specific format.

        Parameters:
        filename - Path to save to.
        format - Specifies the file format of the output image.
        Throws:
        java.io.IOException
      • save

        public void save(java.lang.String filename)
                  throws java.io.IOException

        Save barcode image to specific file.

        Parameters:
        filename - Path to save to.
        Throws:
        java.io.IOException
      • exportToXml

        public boolean exportToXml(java.lang.String xmlFile)

        Exports BarCode properties to the xml-file specified

        Parameters:
        xmlFile - The name of the file
        Returns:
        Whether or not export completed successfully.

        Returns <b>True</b> in case of success; <b>False</b> Otherwise

      • exportToXml

        public boolean exportToXml(java.io.OutputStream xml)
                            throws java.io.IOException
        Exports BarCode properties to the xml-stream specified
        Parameters:
        xml - The xml-stream
        Returns:
        Whether or not export completed successfully. Returns True in case of success; False Otherwise
        Throws:
        java.io.IOException
      • importFromXml

        public static BarcodeGenerator importFromXml(java.lang.String xmlFile)

        Imports BarCode properties from the xml-file specified and creates BarcodeGenerator instance.

        Parameters:
        xmlFile - The name of the file
        Returns:
        BarcodeGenerator instance
      • importFromXml

        public static BarcodeGenerator importFromXml(java.io.InputStream xml)
        Imports BarCode properties from the xml-stream specified and creates BarcodeGenerator instance.
        Parameters:
        xml - The xml-stream
        Returns:
        BarcodeGenerator instance
      • dispose

        public void dispose()

        Clean up any resources being used.