Hi
I have a column in a PdfPtable for displaying prices for various countries.
However, when these prices are formated using a DecimalFormatter and the cell
is aligned to the right, there seems to be inconsitent behaviour in rendering
the cell contents.
Any idea how to overcome this problem?
public static void main(String[] args) {
Document document = new Document();
PdfWriter writer=null;
try {
writer = PdfWriter.getInstance(document, new FileOutputStream
("\\testCurrencyFromat.pdf"));
document.open();
float[] width = {.3f,1f,1f};
PdfPTable table = new PdfPTable(width);
table.setWidthPercentage(80);
float f = 1000000f;
//Some sample locales
Locale LOCALE_SWE =new Locale("sv", "SE");
Locale LOCALE_DNK =new Locale("da", "DK");
Locale LOCALE_FIN=new Locale("fi", "FI");
Locale LOCALE_NOR =new Locale("no", "NO");
Locale LOCALE_US =new Locale("en", "US");
Locale LOCALE_EN =new Locale("en", "GB");
Locale[] locs ={LOCALE_SWE,LOCALE_DNK,LOCALE_FIN,LOCALE_NOR,
LOCALE_US,LOCALE_EN};
//iterate through locales
for (int i = 0; i < locs.length; i++) {
Locale loc = locs[i];
DecimalFormatSymbols dfds = new DecimalFormatSymbols(loc);
PdfPCell cellCur = new PdfPCell(new Phrase
(dfds.getInternationalCurrencySymbol()));
table.addCell(cellCur);
DecimalFormat dfCurrency = new DecimalFormat
("\u00A4#,##0.00",new DecimalFormatSymbols(loc));
String data = dfCurrency.format(f);
PdfPCell celll = new PdfPCell(new Phrase(data));
table.addCell(celll);
Paragraph p = new Paragraph(data);
p.setAlignment(Paragraph.ALIGN_RIGHT);
PdfPCell cellr = new PdfPCell(p);
cellr.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cellr);
}
document.add(table);
document.close();
} catch (DocumentException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/