Place BarCode in existing PDF file


I would like to know if it is possible to place a Barcode on an existing PDF form.
Perhaps there may be a sample code, please let me know.

Here is my project:

  1. I have several fillable PDF forms files in my folder
  2. i need to open one at the time and place a BarCode (whichs represents the account# and state)
  3. then save the PDF.

My Environment: Windows 10, Eclipse 2019, for Java

Thank you very much in advance.


Your requirement can be easily fulfilled using Aspose.Barcode and Aspose.PDF as follows:

  1. Generate barcode using Aspose.Barcode as per your requirement and save it as an image.
  2. Open the existing PDF using Aspose.PDF
  3. Place the image in the existing PDF and save the file

You may please give a try to the sample code in the above mentioned articles and share your feedback.


Hello Aspose tech,
Can you please provide a link of code snippet, On how to add a barcode to an existing PDF file, previously you provided a link but i could not use it, i need to create the barcode on the fly in memory then insert into an existing PDF file, i look everywhere in aspose but can not find any sample. please help.
thank you in advance,


I have created below code snippet which is combination from suggested documents. Let us know your feedback.

ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
BarCodeGenerator barCodeGenerator = new BarCodeGenerator(EncodeTypes.GS_1_CODE_128);
String fileFolder = "D:\\barcode\\";
String filename = "GS_1_CODE_128.png";
SetBarCodeGenerator(barCodeGenerator, 0, 1f, 0f, 0f, false);
{, BarCodeImageFormat.PNG);
catch (Exception ex)

byte[] bytes = imageStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
Document pdfDocument = new Document(fileFolder + "Test.pdf");
// create image stamp
ImageStamp imageStamp = new ImageStamp(inputStream);
// add stamp to particular page
// save output document + "Stamp_output.pdf");

private static void SetBarCodeGenerator(BarCodeGenerator barCodeGenerator, float width, float height, float left, float right, boolean setWidth)

    if (setWidth)


Hello Ahsandiq,
I tried the sample code you provided it is great however, label (letters below the bar-code) are very small.
can you please let me know how can i increase the size of this caption. (see attached sample)
thank you very much,

bc212_StampOutput.pdf (372.3 KB)


You may please visit the following article where caption can be configured by setting the font. Please give it a try in your scenario and share the feedback.

Manage the Barcode Caption