Hi.
I m using iTEXT.jar for barcode
integration.
We have framework through which we generate pdf
files.We hv predefined pdf templates and on the fly we add data to it to create
the resulted pdf.Now i m adding barcode to this resulted pdf.But the new pdf
does not contain the original data,but shows the template with barcode.ie.data
is lost.
Can u help me to find out why?
I m attaching my code snippet with
comments.
private String
createBarcode()throws
PdfException{
String barcodedPdfName = getFileLocation(); PdfImportedPage page; int rotation; int i = 0; try
{
PdfReader reader = new PdfReader(getTempPdfName()); //already created pdf with data int n
=
reader.getNumberOfPages();
Document document = new Document(reader.getPageSizeWithRotation(1)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(barcodedPdfName)); //shld write the contents of the prev generated pdf with barcode
document.open();
PdfContentByte cb1 = writer.getDirectContent(); Image
img = barcodeViewDecorator.getBarcode().createImageWithBarcode(cb1,Color.black,
Color.blue);
img.setAbsolutePosition(defaultBarcodeView.getX_coordinates(),defaultBarcodeView.getY_coordinates());
if(defaultBarcodeView.isMultiplePageBarcode()){
while (i < n) { i++; document.setPageSize(reader.getPageSizeWithRotation(i)); document.newPage(); page = writer.getImportedPage(reader, i); rotation = reader.getPageRotation(i); if (rotation == 90 || rotation == 270) { cb1.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).height());
}
else { cb1.addTemplate(page, 1f, 0, 0, 1f, 0, 0); } document.add(img);
}
}else{
page = writer.getImportedPage(reader,1); rotation = reader.getPageRotation(1); if (rotation == 90 || rotation == 270) { cb1.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).height());
}
else { cb1.addTemplate(page, 1f, 0, 0, 1f, 0, 0); }
document.add(img)
;
} document.close() ; } catch (IOException e)
{
throw new PdfException(e.getMessage() ); } catch (DocumentException e) { throw new PdfException(e.getMessage() ); } finally { return barcodedPdfName; } } Thanks and Best
Regards Pritam. Best Regards
Pritam. |