Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
A barcode is a visual representation of data in the form of parallel lines or patterns. Barcodes are widely used in various industries such as retail, logistics, healthcare, banking, and many others.
Microsoft Word allows users to embed barcodes directly into documents using fields. Users can insert a specific type of barcode, such as a QR code or a linear barcode, using the BARCODE field.
In this article, we will look at how the BARCODE field is implemented in Aspose.Words and how Aspose.Words allows users to work with Word documents to which a barcode has already been added.
Aspose.Words supports various types of barcodes. The barcode type is passed as a string value in the BarcodeType property.
When saving to Word formats that support barcodes, you can use any type of barcode that is supported by Microsoft Word. If an incorrect type of barcode was passed, Word will display an error.
When saving to other formats, such as PDF, Aspose.Words delegates barcode rendering to the user code, so the user is limited to the barcode types of their implementation or library used.
Aspose.Words provides the ability to:
Aspose.Words has an interface for generating custom barcodes that makes it easy to use Aspose.Words and Aspose.BarCode together to render barcode images in output documents. For example, you can create a DOC, OOXML, or RTF document and add DISPLAYBARCODE field to it using Aspose.Words. Or you can load a DOC, OOXML or RTF document with DISPLAYBARCODE field already existing in it and provide your implementation of custom barcode generator.
A typical DISPLAYBARCODE field has the following syntax:
{ DISPLAYBARCODE "SomeData" QR \h 720 }
Below is an example code generator using the Aspose.Words and Aspose.BarCode APIs. This example shows how to insert barcode images at DISPLAYBARCODE field position in a Word document:
You can also save the document with the loaded or newly inserted barcode in fixed page formats such as PDF, XPS, etc. The following code example shows how to save a Word document to PDF format:
When working with barcodes, you can set some additional properties. Aspose.Words provides you with the BarcodeParameters class – class for barcode parameters to pass-through to BarcodeGenerator.
Aspose.Words supports embedded 96 ppi resolution for images generated with IBarcodeGenerator, which limits the minimum size of a barcode image. To address this, developers can manually insert barcode images with the target resolution into a Word document and save them in the required format. For more details and examples on working with barcodes, see the article Read Barcodes from Word Documents.
Q: How can I programmatically insert a DISPLAYBARCODE field into a Word document?
A: Create a DocumentBuilder, use InsertField with the field code syntax, e.g.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertField("{ DISPLAYBARCODE \"1234567890\" CODE128 }");
After inserting the field, you can assign a custom IBarcodeGenerator implementation to render the barcode when the document is saved.
Q: What is the purpose of the IBarcodeGenerator interface?
A: IBarcodeGenerator lets you supply your own barcode rendering logic. Implement the generateBarcodeImage(BarcodeParameters parameters) method to return a java.awt.image.BufferedImage. Aspose.Words calls this method for each DISPLAYBARCODE field when saving to formats that do not support native barcode rendering (e.g., PDF).
Q: Which barcode types are supported by Aspose.Words out‑of‑the‑box?
A: The BarcodeParameters.getBarcodeType() property accepts any barcode type that Microsoft Word recognises (QR, CODE128, EAN13, etc.). If you need additional types, use Aspose.BarCode or another library inside your IBarcodeGenerator implementation.
Q: How can I control the resolution or size of the generated barcode image?
A: Set the Resolution property on BarcodeParameters (default 96 ppi). You can also specify width and height in the field switches (\h for height, \w for width). Example: { DISPLAYBARCODE "Data" QR \h 720 \w 300 }.
Q: Do I need a license to use barcode generation with Aspose.Words for Java?
A: Yes. To remove evaluation limitations and enable full functionality (including custom IBarcodeGenerator), apply a valid Aspose.Words for Java license via License license = new License(); license.setLicense("Aspose.Words.Java.lic");. The same license also covers any Aspose.BarCode usage if you integrate the two libraries.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.