Hi,
I am trying to create a receipt. The paper width is 8 cm and I want a
margin of 0.3 cm. Since I don't have the right printer yet I have to
test it using A4 paper. So what I do is to set the top, left and bottom
margin to the specified 0.3 cm + 1 cm (37px) to be able to print it.
The right margin is set to 348px which should be the 595px for the A4
minus the left margin minus 210px being the printable area of the
paper.
At the top of the page should be a logo no higher that 57px. If smaller
space should be added to the top and bottom. Below the logo should be a
text and a horizontal line of width 210px. I had a problem finding the
best way to draw a line when I don't use ContentByte, so I created a
table with one cell and a border.
Now my problem is that the logo and the line do not respect the width I
set. Can anyone tell me why?
Font normal18 = new Font(Font.TIMES_ROMAN, 18, Font.NORMAL);
Document document = new Document(PageSize.A4, 37, 348, 37, 37);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
PdfPTable fatLine = new PdfPTable(1);
fatLine.setTotalWidth(210);
PdfPCell c = new PdfPCell();
c.setBorderWidth(4);
c.setPadding(0);
fatLine.addCell(c);
fatLine.setHorizontalAlignment(Element.ALIGN_LEFT);
fatLine.setSpacingBefore(8);
PdfWriter writer = PdfWriter.getInstance(document, bos);
document.open();
Image logo =
Image.getInstance("/Users/birthe/Desktop/ComplimentaLogo.gif");
float w = logo.plainWidth();
float h = logo.plainHeight();
if ((w > 210) || (h > 57)) {
float scale = 100 / Math.max((w / 210), (h /
57));
logo.scalePercent(scale);
}
h = logo.scaledHeight();
PdfPTable logoTable = new PdfPTable(1);
logoTable.setTotalWidth(210);
logoTable.setHorizontalAlignment(Element.ALIGN_LEFT);
logoTable.setSpacingAfter(8);
PdfPCell cell = new PdfPCell(logo);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setBorderWidth(0);
cell.setPaddingRight(0);
cell.setPaddingLeft(0);
cell.setPaddingBottom((57-h) / 2);
cell.setPaddingTop((57-h) / 2);
cell.setBackgroundColor(Color.YELLOW);
logoTable.addCell(cell);
document.add(logoTable);
document.add(new Paragraph("Neste time", normal18));
document.add(fatLine);
}
catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
Thanks
Birthe Berland______________________________________________________________________
css-discuss [EMAIL PROTECTED]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/