我使用IText在pdf上制作条形码,我不知道如何将这个条形码居中。
这是我的代码
para = new Paragraph(nom_ecole,FontFactory.getFont(FontFactory.TIMES_BOLD,45));
para.setAlignment(Element.ALIGN_CENTER);
document.add(para);
para = new Paragraph(nom_eleve1+" "+prenom_eleve1,FontFactory.getFont(FontFactory.TIMES_BOLD,45));
para.setAlignment(Element.ALIGN_CENTER);
document.add(para);
codebarre.setCodeType(Barcode.EAN8);
codebarre.setCode(id_doss1);
document.add(codebarre.createImageWithBarcode(cb,BaseColor.BLACK,BaseColor.BLACK));
答案 0 :(得分:0)
You need to calculate the coordinates of the page by width and height
May be it will help you..
Long width=(long) pdfReader.getPageSize(i).getWidth();
Long height=(long) pdfReader.getPageSize(i).getHeight();
if (pdfReader.getPageRotation(i) % 180 == 0) {
x = width / 2;
y = height - 20;
}
else {
x = width / 2;
y = height - 20;
}
ColumnText.showTextAligned(pdfStamper.getOverContent(i), Element.ALIGN_CENTER, header, x, y+3, 0);