TestBoxField.AddBarcode

Question:




I’m using the trial version of Aspose PDF. I found the method “AddBarcode”. I’m trying to use that to enter a barcode into an existing form field. However, when I use it to enter a value (let’s say mytextfield.AddBarcode(“123456”)) it enters that value 123456 into the textbox and sets it to read only, but it does NOT convert the text to a barcode.



  • Do I need to also have the barcode library installed to use this?

  • Could this be a limitation of the trial software?




    Thanks,
    Jeremy

Hi Jeremy,


Thanks for using our API’s.

I have tested the scenario using Aspose.Pdf for .NET 10.3.0 where I have used following code snippet and as per my observations, the BarCode appears in form field. For your reference, I have also attached the resultant file generated over my end.

[C#]

//open
document
<o:p></o:p>

Document pdfDocument = new Document();

pdfDocument.Pages.Add();

//create a field

TextBoxField textBoxField = new TextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 200, 300, 300));

textBoxField.AddBarcode("123456");

textBoxField.PartialName = "textbox1";

//textBoxField.Border = new Border(

Border border = new Border(textBoxField);

border.Width = 5;

border.Dash = new Dash(1, 1);

textBoxField.Border = border;

//add field to the document

pdfDocument.Form.Add(textBoxField, 1);

//pdfDocument.Flatten();

//save modified PDF

pdfDocument.Save("c:/pdftest/BarCodeAdded_output.pdf");

Great, thanks for your reply.


A few points:

1) Did you attach the file?

2) Based on your reply, it sounds like I SHOULD be able to generate a barcode using that method without purchasing the Barcode software. Is that correct?

3) I’m using this for a slightly different purpose. I’m basically trying to “fill out” an existing form, not create a new one. So what I’m doing looks like this:

Document pdfDocument = new Document(dataDir + “Form123.pdf”);
TextBoxField textBoxField = pdfDocument.Form.Fields[3] as TextBoxField;
textBoxField.AddBarcode(“123456”);
pdfDocument.Save(dataDir + “CompletedForm.pdf”);

Is the code above a valid usage for the AddBarcode method? For me it simply fills in the Field with “123456” and then sets it to read-only.

Thanks,
Jeremy
  1. Did you attach the file?
    Hi Jeremy,

The resultant file is attached with my previous post. Please take a look.

  1. Based on your reply, it sounds like I SHOULD be able to generate a barcode using that method without purchasing the Barcode software. Is that correct?

We have Aspose.BarCode which is specific for BarCode creation and manipulation, so in order to generate BarCode, please try using this API and then add resultant BarCode as Stamp object to PDF file or add it as image to filed inside PDF document. For more details, please visit

  • [Barcode Image Basic Features](http://www.aspose.com/docs/display/barcodenet/Barcode+Image+Basic+Features)
  • [Adding Image Stamp in PDF File](http://www.aspose.com/docs/display/pdfnet/Adding+Image+Stamp+in+PDF+File)

In order to add BarCode image to form field, please try using following code snippet.

[C#]

//Create
Form Object<o:p></o:p>

Aspose.Pdf.Facades.Form pdfForm = new Aspose.Pdf.Facades.Form();

//Open Document

pdfForm.BindPdf("input.pdf");

//fill image in Image Field

pdfForm.FillImageField("ImageField", "logo.jpg");

//save updated file

pdfForm.Save(“output.pdf”);
  1. I’m using this for a slightly different purpose. I’m basically trying to “fill out” an existing form, not create a new one. So what I’m doing looks like this:
    Is the code above a valid usage for the AddBarcode method? For me it simply fills in the Field with “123456” and then sets it to read-only.

I have tested the scenario and as per my observations, the BarCode is properly appearing in resultant file. See attached updated document and image given below.

[C#]

Document pdfDocument = new Document(“c:/pdftest/BarCodeAdded_output
(1).pdf”);<o:p></o:p>

TextBoxField textBoxField = pdfDocument.Form.Fields[0] as TextBoxField;

textBoxField.AddBarcode("56789");

pdfDocument.Save(“c:/pdftest/BarCode_Added.pdf”);

Thanks, but it still does not work for me (see attached image). So, a few questions:

  1. Could this be a limitation of the trial software?

  2. Is there any documentation on this method? I’m looking for something more in depth than this: http://www.aspose.com/docs/display/pdfnet/Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField.Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField.AddBarcode+Method

  3. Can you personally think of any reason this method would create the results I’m showing you? I’m using the exact code snippet you provided. The source pdf document was also created externally, not by the Aspose software.

Hi Jeremy,

Thanks for sharing the details.

I have tested the scenario and have observed that when using the API in trial mode, the BarCode is not being added to form field. However in order to overcome this limitation, we recommend you to please request a 30 days temporary license by following instructions specified over Get a temporary license

  1. Is there any documentation on this method? I’m looking for something more in depth than this: http://www.aspose.com/docs/display/pdfnet/Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField.Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField.AddBarcode+Method

The API Reference section only highlights the details regarding particular method/property and details regarding its implementation/usage are specified in Programmers Guide area. However I am afraid we do not have any extensive documentation regarding usage of this feature in our documentation. Nevertheless, you can always share your queries in our forums and we will love to assist you in this regard.

  1. Can you personally think of any reason this method would create the results I’m showing you? I’m using the exact code snippet you provided. The source pdf document was also created externally, not by the Aspose software.

Please try using the code snippet with valid license and in case you still face any issue, please feel free to contact.

Great! I got the trial license and it’s now working. Thanks for your help with that.


Now my question is: do I have any means of modifying the properties of that barcode. Specifically, I’d be looking to increase its size and change the barcode symbology from Code128 to Code39.

Thanks,
Jeremy
aspose_user_123:
Great! I got the trial license and it’s now working. Thanks for your help with that.
Hi Jeremy,

Thanks for the acknowledgement and we are glad to hear that your problem is resolved.

aspose_user_123:
Now my question is: do I have any means of modifying the properties of that barcode. Specifically, I’d be looking to increase its size and change the barcode symbology from Code128 to Code39.
In order to change BarCode size, you may consider updating field dimensions. However please note that Aspose.Pdf only provides basic feature for creating BarCode inside PDF form and in order to get more advanced features for BarCode creation/manipulation, please try using Aspose.BarCode. For further details, please check my previous post 627655.