Com esse codigo meu programa imprime, mas ele corta se imprimir mais d uma linha, gostaria d imprimir no final da página, como o código imprimi, só queria q não cortasse.
//classe de impressão
public int print(Graphics g, PageFormat format, int page)
throws PrinterException {
if (page != 0)
return NO_SUCH_PAGE;
else {
Graphics2D gr = (Graphics2D) g;
// Determina a pos. de início do texto
float posX = (float) format.getImageableX() + 5;
float posY = (float) format.getImageableY() + 690;//690
// Define a largura do texto como 350 pontos
float larguraTexto = 500;
// Imprime parágrafos formatados
Iterator it = texto.iterator();
while (it.hasNext()) {
String line = (String) it.next();
// Caso haja uma linha em branco, substituir por um espaço
// para permitir formatação
if (line.length() == 0) {
line = " ";
}
// Texto formatado a ser impresso
AttributedString str = new AttributedString(line);
// Define a fonte do texto como Arial 12 itálico
str.addAttribute(TextAttribute.FONT, new Font("Arial",
Font.ITALIC, 12));
// Cria objeto para quebrar o texto formatado
LineBreakMeasurer quebrador =
new LineBreakMeasurer(
str.getIterator(),
gr.getFontRenderContext());
// Cria um TextLayout para armazenar cada linha 'quebrada'
TextLayout linha = quebrador.nextLayout(larguraTexto);
while (linha != null) {
// Posiciona a linha
posY += linha.getAscent();
linha.draw(gr, posX, posY);
// Soma espaço para a próxima linha
posY += linha.getDescent() + linha.getLeading();
linha = quebrador.nextLayout(larguraTexto);
}
}
return PAGE_EXISTS;
}
}
//ação do botao
PrinterJob job = PrinterJob.getPrinterJob();
texto = new ArrayList();
String temp="";
for(int i=0; i<tempo.length();i++){
temp+=tempo.charAt(i);
if(tempo.charAt(i)=='\n'){
texto.add(temp);
temp="";
}
}
texto.add(tempo);
job.setPrintable(this);
PageFormat landscape = job.defaultPage();
Paper paper = new Paper();
paper.setImageableArea(10, 10, (8.26-0.78-0.78)*72, (11.69-0.78-0.78)*72);
paper.setSize(8.26*72,11.69*72);
landscape.setOrientation(PageFormat.LANDSCAPE);
landscape.setPaper(paper);
if (job.printDialog()) {
try {
job.print();
} catch (PrinterException e) {
JOptionPane.showMessageDialog(this,"entrou no try", "Erro",JOptionPane.ERROR_MESSAGE);
/*...*/
}
}
Me ajudem!!!
