dimanche 27 avril 2014

Keeping String format while sending it to a printer


Vote count:

0




I am new to this foru. Does any one know how to keep a string format while sending to a printer like microsoft xps printer? My code is below:



String uniPQtyToPFormat = "%1$-20s%5s%25s\r\n";
String unitPrice="1000.00x";
String numberOfUnits="1.00";
String totalPrice="10000000.00";
String formattedUniPQtyToP=String.format(uniPQtyToPFormat,unitPrice,StringUtils.center(numberOfUnits,10),totalPrice);


when I print the "formattedUniPQtyToP" line in a text file, the format is well preserved as I expect. This appears in the text file as:


1000.00x 1000.00x 10000000.00


However, when I print "formattedUniPQtyToP", total price goes to the next line instead of staying at the same line as unitPrice and numberOfUnits as it is illustrated below:


1000.00x 1000.00x

10000000.00


To print the string to xps printer, I am using the following code:



while (measurer.getPosition() < charIterator.getEndIndex()) {
int next=measurer.nextOffset(wrappingWidth);
int limit=next;
if(limit<=text.length()){
for(int i=measurer.getPosition();i<next;i++){
char c=text.charAt(i);
if(c=='\n'){//to break text into line in case there are many lines
limit=i+1;
break;
}
}
}
TextLayout layout = measurer.nextLayout(wrappingWidth,limit,false);
pen.y += layout.getAscent();
float dx = layout.isLeftToRight() ? 0 : (wrappingWidth - layout.getAdvance());
layout.draw(graphics2d, pen.x + dx, pen.y);
pen.y += layout.getDescent() + layout.getLeading();

}


I welcome any help or hint. Patrick



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire