Hi Awais,
Please find attached the input document and the output document produced. If you see the output, the barcode is properly added on the first page but on the second page which contains a table the barcode gets displaced. It does not gets added properly at the top right hand corner.
The code I have used is as below-
Barcode Generation
private static BufferedImage generateBarcode()
{
BarCodeBuilder barCodeBuilder = new BarCodeBuilder();
String barcodeText="XYZsdflksdkjfls;dfk;dsf;lk";
barCodeBuilder.setCodeText(barcodeText);
barCodeBuilder.setDataMatrixEncodeMode(DataMatrixEncodeMode.Auto);
barCodeBuilder.setSymbologyType(Symbology.DataMatrix);
barCodeBuilder.setCodeLocation(CodeLocation.None);
return barCodeBuilder.getBarCodeImage();
}
public static void AddImageToPage(Paragraph para, int page) throws Exception {
Document doc = (Document) para.getDocument();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveTo(para);
builder.insertImage(generateBarcode(), RelativeHorizontalPosition.PAGE, 540,RelativeVerticalPosition.PAGE, 40, -1, -1, WrapType.NONE);
}
Main()
{
Document doc = new Document("AsposeInput.docx");
System.out.println(doc.getPageCount());
LayoutCollector layoutCollector = new LayoutCollector(doc);
NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (int page = 1; page <= doc.getPageCount(); page++) {
for (Paragraph paragraph : (Iterable) paragraphs) {
if (layoutCollector.getStartPageIndex(paragraph) == page) {
AddImageToPage(paragraph, page);
break;
}
}
}
doc.save("AsposeOutput.docx");
}
Please let me know the fix for this.
Also will need one more help from you. If you see the output document the barcode image is somewhat bigger in size. How can I make the barcode size samller on the output document?
Thanks for your help