Class BarcodePDF417

java.lang.Object
com.itextpdf.barcodes.Barcode2D
com.itextpdf.barcodes.BarcodePDF417

public class BarcodePDF417 extends Barcode2D
PDF417 is a stacked linear barcode format used in a variety of applications such as transport, identification cards, and inventory management. "PDF" stands for Portable Data File. The "417" signifies that each pattern in the code consists of 4 bars and spaces in a pattern that is 17 units (modules) long. It is defined in ISO 15438.
  • Field Details

  • Constructor Details

    • BarcodePDF417

      public BarcodePDF417()
      Creates a new BarcodePDF417 with the default settings.
  • Method Details

    • setMacroSegmentId

      public void setMacroSegmentId (int id)
      Sets the segment id for macro PDF417 encoding
      Parameters:
      id - the id (starting at 0)
      See Also:
    • setMacroSegmentCount

      public void setMacroSegmentCount (int cnt)
      Sets the segment count for macro PDF417 encoding
      Parameters:
      cnt - the number of macro segments
      See Also:
    • setMacroFileId

      public void setMacroFileId (String id)
      Sets the File ID for macro PDF417 encoding
      Parameters:
      id - the file id
    • setDefaultParameters

      public void setDefaultParameters()
      Set the default settings that correspond to PDF417_USE_ASPECT_RATIO and PDF417_AUTO_ERROR_LEVEL.
    • getBarcodeSize

      public Rectangle getBarcodeSize()
      Gets the maximum area that the barcode and the text, if any, will occupy. The lower left corner is always (0, 0).
      Specified by:
      getBarcodeSize in class Barcode2D
      Returns:
      the size the barcode occupies.
    • placeBarcode

      public Rectangle placeBarcode (PdfCanvas canvas, Color foreground)
      Places the barcode in a PdfCanvas. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.
      Specified by:
      placeBarcode in class Barcode2D
      Parameters:
      canvas - the PdfCanvas where the barcode will be placed
      foreground - the foreground color. It can be null
      Returns:
      the dimensions the barcode occupies
    • placeBarcode

      public Rectangle placeBarcode (PdfCanvas canvas, Color foreground, float moduleWidth, float moduleHeight)
      Places the barcode in a PdfCanvas.
      Parameters:
      canvas - the PdfCanvas where the barcode will be placed
      foreground - the Color of the bars of the barcode
      moduleWidth - the width of the thinnest bar
      moduleHeight - the height of the bars
      Returns:
      the dimensions the barcode occupies
    • paintCode

      public void paintCode()
      Paints the barcode. If no exception was thrown a valid barcode is available.
    • createFormXObject

      public PdfFormXObject createFormXObject (Color foreground, PdfDocument document)
      Creates a PdfFormXObject with the barcode.
      Specified by:
      createFormXObject in class Barcode2D
      Parameters:
      foreground - the color of the pixels. It can be null
      document - The document
      Returns:
      the XObject.
    • createFormXObject

      public PdfFormXObject createFormXObject (Color foreground, float moduleWidth, float moduleHeight, PdfDocument document)
      Creates a PdfFormXObject with the barcode with given module width and module height.
      Parameters:
      foreground - The color of the pixels. It can be null
      moduleWidth - The width of the pixels.
      moduleHeight - The height of the pixels.
      document - The document
      Returns:
      the XObject.
    • createAwtImage

      public Image createAwtImage (Color foreground, Color background)
      Creates a java.awt.Image.
      Parameters:
      foreground - the color of the bars
      background - the color of the background
      Returns:
      the image
    • getOutBits

      public byte[] getOutBits()
      Gets the raw image bits of the barcode. The image will have to be scaled in the Y direction by yHeight.
      Returns:
      The raw barcode image
    • getBitColumns

      public int getBitColumns()
      Gets the number of X pixels of outBits.
      Returns:
      the number of X pixels of outBits
    • getCodeRows

      public int getCodeRows()
      Gets the number of Y pixels of outBits. It is also the number of rows in the barcode.
      Returns:
      the number of Y pixels of outBits
    • setCodeRows

      public void setCodeRows (int codeRows)
      Sets the number of barcode rows. This number may be changed to keep the barcode valid.
      Parameters:
      codeRows - the number of barcode rows
    • getCodeColumns

      public int getCodeColumns()
      Gets the number of barcode data columns.
      Returns:
      he number of barcode data columns
    • setCodeColumns

      public void setCodeColumns (int codeColumns)
      Sets the number of barcode data columns. This number may be changed to keep the barcode valid.
      Parameters:
      codeColumns - the number of barcode data columns
    • getCodewords

      public int[] getCodewords()
      Gets the codeword array. This array is always 928 elements long. It can be written to if the option PDF417_USE_RAW_CODEWORDS is set.
      Returns:
      the codeword array
    • getLenCodewords

      public int getLenCodewords()
      Gets the length of the codewords.
      Returns:
      the length of the codewords
    • setLenCodewords

      public void setLenCodewords (int lenCodewords)
      Sets the length of the codewords.
      Parameters:
      lenCodewords - the length of the codewords
    • getErrorLevel

      public int getErrorLevel()
      Gets the error level correction used for the barcode. It may different from the previously set value.
      Returns:
      the error level correction used for the barcode
    • setErrorLevel

      public void setErrorLevel (int errorLevel)
      Sets the error level correction for the barcode.
      Parameters:
      errorLevel - the error level correction for the barcode
    • getCode

      public byte[] getCode()
      Gets the bytes that form the barcode. This bytes should be interpreted in the codepage Cp437.
      Returns:
      the bytes that form the barcode
    • setCode

      public void setCode (byte[] code)
      Sets the bytes that form the barcode. This bytes should be interpreted in the codepage Cp437.
      Parameters:
      code - the bytes that form the barcode
    • setCode

      public void setCode (String text)
      Sets the code that will form the barcode. This text is converted to bytes using the encoding Cp437.
      Parameters:
      text - the text that will form the barcode
    • getOptions

      public int getOptions()
      Gets the options to generate the barcode.
      Returns:
      the options to generate the barcode
    • setOptions

      public void setOptions (int options)
      Sets the options to generate the barcode. This can be all the PDF417_* constants.
      Parameters:
      options - the options to generate the barcode
    • getAspectRatio

      public float getAspectRatio()
      Gets the barcode aspect ratio.
      Returns:
      the barcode aspect ratio
    • setAspectRatio

      public void setAspectRatio (float aspectRatio)
      Sets the barcode aspect ratio. A ratio or 0.5 will make the barcode width twice as large as the height.
      Parameters:
      aspectRatio - the barcode aspect ratio
    • getYHeight

      public float getYHeight()
      Gets the Y pixel height relative to X.
      Returns:
      the Y pixel height relative to X
    • setYHeight

      public void setYHeight (float yHeight)
      Sets the Y pixel height relative to X. It is usually 3.
      Parameters:
      yHeight - the Y pixel height relative to X
    • outCodeword17

      protected void outCodeword17 (int codeword)
      Adds the code word to the correct code word to the 17th bit.
      Parameters:
      codeword - the code word
    • outCodeword18

      protected void outCodeword18 (int codeword)
      Adds the code word to the correct code word to the 18th bit.
      Parameters:
      codeword - the code word
    • outCodeword

      protected void outCodeword (int codeword)
      Utility method that adds a codeword to the barcode.
      Parameters:
      codeword - the codeword to add
    • outStopPattern

      protected void outStopPattern()
      Adds the stop pattern to the output.
    • outStartPattern

      protected void outStartPattern()
      Adds the start pattern to the output.
    • outPaintCode

      protected void outPaintCode()
      Adds the barcode to the output bits.
    • calculateErrorCorrection

      protected void calculateErrorCorrection (int dest)
      Calculates the error correction codewords.
      Parameters:
      dest - length of the code words
    • textCompaction

      protected void textCompaction (int start, int length)
      Compacts the codewords.
      Parameters:
      start - the start position
      length - the length
    • basicNumberCompaction

      protected void basicNumberCompaction (int start, int length)
      Compacts the codewords.
      Parameters:
      start - the start position
      length - the length
    • getTextTypeAndValue

      protected int getTextTypeAndValue (int maxLength, int idx)
      Gets the text type and value.
      Parameters:
      maxLength - the maximum length
      idx - the index
      Returns:
      the text type and value
    • checkSegmentType

      protected boolean checkSegmentType (BarcodePDF417.Segment segment, char type)
      Checks whether the segment is of a certain type.
      Parameters:
      segment - the segment to check
      type - the type to check against
      Returns:
      true if the segment is of the specified type
    • getSegmentLength

      protected int getSegmentLength (BarcodePDF417.Segment segment)
      Calculates the length of the given segment
      Parameters:
      segment - the segment to check
      Returns:
      the length of the segment
    • numberCompaction

      protected void numberCompaction (int start, int length)
      Compacts the code words.
      Parameters:
      start - the start position
      length - the length
    • byteCompaction6

      protected void byteCompaction6 (int start)
      Compacts the code words
      Parameters:
      start - the start position
    • assemble

      protected void assemble()
      Assembles the data of the code words.
    • maxPossibleErrorLevel

      protected static int maxPossibleErrorLevel (int remain)
      Calculates the highest error level that can be used for the remaining number of data codewords.
      Parameters:
      remain - the number of data codewords
      Returns:
      the highest error level that can be used
    • dumpList

      protected void dumpList()
      Prints the segments to standard output.
    • getMaxSquare

      protected int getMaxSquare()
      Calculates the max square that can contain the barcode. And sets the codeColumns and codeRows variables.
      Returns:
      the max square that can contain the barcode