Ho necessità di stampare una fattura su Epson LQ300+,ma non so come impostare il salto pagina.Si tratta di un modulo continuo lungo 20 cm e largo 11,5 cm.Ho provato ad impostare nelle proprietà della stampante un foglio personalizzato specificando anche i margini, ma mi accorgo che il salto pagina è spropositato.Vi posto il pezzo di Codice Java che si occupa della stampa da un Array SrigheFatture come argomento ed altro ...
public class StampaModulo implements Printable {
String [][]sArtVenduti=new String[101][10];
public StampaModulo()
{
}
private static String rightAlign(String str, int width, char filler)
{
while (str.length() < width)
{
str = filler + str;
}
return str;
}
public int print (Graphics g, PageFormat pageFormat, int page)
{
int i;
Graphics2D g2d;
if (page == 0)
{
int xInt = 10,
yInt = 12,
dyInt =12;
g2d = (Graphics2D) g;
g2d.setColor (Color.black);
g2d.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());
Font normale = new Font ("serif", Font.PLAIN, 8);
Font bold = new Font ("serif", Font.BOLD, 8);
g2d.setFont(bold);
g2d.drawString("Nota di consegna per tentata vendita Nr."+sNumero+"", xInt, yInt + 2*dyInt);
g2d.setFont(normale);
g2d.drawString(("Data " + Data + " Ora " + sOraCorrente), xInt, yInt + 4*dyInt);
g2d.setFont(normale);
g2d.drawString(("Condizione di Pagamento " + sPaga), xInt, yInt + 6*dyInt);
g2d.setFont(normale);
g2d.drawString(("Destinatario " + sDesCli), xInt, yInt + 8*dyInt);
g2d.setFont(normale);
g2d.drawString((sCliente+" "+sInd), xInt, yInt + 9*dyInt);
g2d.setFont(normale);
g2d.drawString((" " + sCap+" "+sCit+" "+sPro), xInt, yInt + 10*dyInt);
g2d.setFont(normale);
g2d.drawString((" P.IVA" +sPiva), xInt, yInt + 11*dyInt);
g2d.setFont(normale);
g2d.drawString(("Luogo di Consegna " + sDe1), xInt, yInt + 12*dyInt);
g2d.setFont(normale);
g2d.drawString((" " + sDe2), xInt, yInt + 13*dyInt);
g2d.setFont(normale);
g2d.drawString((" " + sDe3), xInt, yInt + 14*dyInt);
g2d.setFont(normale);
//Stampa Tabella
g2d.drawString("Descrizione Prodotto " + " " + "Quantita"+" " + "Imponibile", xInt, yInt + 15*dyInt);
for (iCol=1; iCol<sArtVenduti.length; iCol++)
{
if(sArtVenduti[iCol][1]!=null || sArtVenduti[iCol][3]!=null)
{
quanterighe=iCol;
String sArticolo = sArtVenduti[iCol][1];
String sDescrizione = sArtVenduti[iCol][2];
String sLotto = sArtVenduti[iCol][3];
String sScadenza = sArtVenduti[iCol][4];
String sQuantita = sArtVenduti[iCol][5];
String sImporto = sArtVenduti[iCol][6];
g2d.drawString(sDescrizione, xInt,iCol*yInt + (iCol+15)*dyInt);
g2d.drawString(sQuantita, xInt+100,iCol*yInt + (iCol+15)*dyInt);
g2d.drawString(sImporto, xInt+150,iCol*yInt + (iCol+15)*dyInt);
g2d.drawString("Lotto "+sLotto+" "+sScadenza, xInt,iCol*yInt + ((iCol+1)+15)*dyInt);
}
}
g2d.drawString("Vettore incaricato del trasporto ", xInt, (quanterighe+1)*yInt + (quanterighe+20)*dyInt);
fPrezzo=new DecimalFormat("########.##");
String STotale=(String)fPrezzo.format(DTotale);
String STotColli=(String)fPrezzo.format(DTotColli);
g2d.drawString("Totale " + STotale+" N.Colli "+STotColli, xInt, (quanterighe+1)*yInt + (quanterighe+24)*dyInt);
g2d.drawString("Firma Vettore/Conducente Firma del Destinatario ", xInt, (quanterighe+1)*yInt + (quanterighe+28)*dyInt);
return (PAGE_EXISTS);
}
else
return (NO_SUCH_PAGE);
}
public void FailaStampa (String [][]sRigheFatture,int NumDoc,int NRighe,String sCli,String sDescli1,String sNdo,String sIndi,String sCap1,String sCitt,int sDest,String PIva,String Des1,String Des2,String Des3,String Pro,String Cpag,String Despag)
{
int i=0;
int j=0;
int iCol=0;
String query = null;
String sImporto = null;
DecimalFormat fPrezzo ,
fPrezzo1;
Double DPrezz1 = 0.0;
double dPrezz1 = 0.0;
int trovato=0;
System.out.println("Parte");
sCliente=sCli;
System.out.println("Parte con il cliente "+sCli);
sNumero=Integer.toString(NumDoc);
sDesCli= sDescli1;
sInd=sIndi;
sCap=sCap1;
sCit=sCitt;
sPro = Pro;
sPiva= PIva;
sPaga = Despag;
sDe1 = Des1;
sDe2 = Des2;
sDe3 = Des3;
String [][]sRigheAliquote=new String[4][3];
fPrezzo=new DecimalFormat("###,###,###.00##");
fPrezzo1=new DecimalFormat("###,###,###.0#");
/*
try
{
//query = "SELECT dfdat,dfndo,dfnot,pcdes,gpdes,d4des,d4de1,d4de2 FROM DDTFAT left join pconta on pccod=dfcli left join gespag on gpcod=dfcpg left join destin on (d4cod=dfcli and d4ser=dfdes) WHERE dfnum="+NumDoc+"";
query = "SELECT * FROM DDTFAT WHERE dfnum="+NumDoc+"";
String sDriver = ("jdbc:firebirdsql:127.0.0.1/3050:" + sPath1DB);
Driver drv = null;
Connection conn = null;
Statement stm = null;
ResultSet res = null;
try {
Class.forName("org.firebirdsql.jdbc.FBDriver");
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
conn = DriverManager.getConnection(sDriver, DB_USER, DB_PASS);
stm = conn.createStatement();
res = stm.executeQuery(query);
if (res.next())
{
++trovato;
//sCli = res.getString("dfcli");
//sNdo = res.getString("dfndo");
sNdo = res.getString("dfndo");
sCpg = res.getString("dfcpg");
sNote = res.getString("dfnot");
}
res.close();
stm.close();
conn.close();
}
catch (SQLException e) {}
sDe1=sDe2=sDe3="";
/*
try
{
if(sDest!=0)
query = "SELECT fcpro,fcnpi,gpdes,d4des,d4de1,d4de2 FROM CLIENT left join gespag on gpcod='"+sCpg+"' left join destin on (d4cod='"+sCli+"' and d4ser="+sDest+") WHERE fccod='"+sCli+"'";
else
query = "SELECT fcpro,fcnpi,gpdes FROM CLIENT left join gespag on gpcod='"+sCpg+"' WHERE fccod='"+sCli+"'";
System.out.println("Faccio "+query);
String sDriver = ("jdbc:firebirdsql:127.0.0.1/3050:" + sPathDB);
Driver drv = null;
Connection conn = null;
Statement stm = null;
ResultSet res = null;
try {
Class.forName("org.firebirdsql.jdbc.FBDriver");
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
conn = DriverManager.getConnection(sDriver, DB_USER, DB_PASS);
stm = conn.createStatement();
res = stm.executeQuery(query);
System.out.println("Res "+res.next());
while (res.next())
{
System.out.println("Ho trovato il record");
++trovato;
sPro = res.getString("fcpro");
sPiva= res.getString("fcnpi");
sPaga = res.getString("gpdes");
if(sDest>0)
{
sDe1 = res.getString("d4des");
sDe2 = res.getString("d4de1");
sDe3 = res.getString("d4de2");
}
System.out.println("Dati "+sCli+" "+sDesCli+" "+sInd+" "+sCit+" "+sPro+" "+sPaga);
break;
}
res.close();
stm.close();
conn.close();
}
catch (SQLException e) {}
Connection con = null;
PreparedStatement prest;
try
{
Class.forName("org.firebirdsql.jdbc.FBDriver");
String sDriver = ("jdbc:firebirdsql:127.0.0.1/3050:" + sPathDB);
con = DriverManager.getConnection(sDriver, DB_USER, DB_PASS);
try
{
String sql = "SELECT * FROM client WHERE fccod = ?";
prest = con.prepareStatement(sql);
prest.setString(1,"+sCli+");
ResultSet rs1 = prest.executeQuery();
System.out.println("Rs1"+rs1.next());
while (rs1.next())
{
System.out.println("Entrato");
String mov_name = rs1.getString(1);
String mov_name1 = rs1.getString(2);
String mov_name2 = rs1.getString(3);
String mov_name3 = rs1.getString(4);
System.out.println(""+mov_name+" "+mov_name1+" "+mov_name2+" "+mov_name3);
}
}
catch (SQLException s)
{
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
*
*/
i=0;
pagine=NRighe/10+1;
DTotale=0.0;
DTotColli=0.0;
for (iCol=1; iCol<=NRighe; iCol++)
{
sArtVenduti[++i][1] = sRigheFatture[iCol][0];
sArtVenduti[i][2] = sRigheFatture[iCol][1];
sArtVenduti[i][3] = sRigheFatture[iCol][2];
sArtVenduti[i][4] = sRigheFatture[iCol][3];
sArtVenduti[i][5] = sRigheFatture[iCol][4];
DPrezz1= new Double(sRigheFatture[iCol][4]);
dPrezz1 = DPrezz1.doubleValue();
DTotColli+=dPrezz1;
sArtVenduti[i][6] = sRigheFatture[iCol][5];
sArtVenduti[i][7] = sRigheFatture[iCol][6];
sArtVenduti[i][8] = sRigheFatture[iCol][7];
sImporto = sRigheFatture[iCol][7];
DPrezz1= new Double(sImporto.replace(',', '.'));
dPrezz1 = DPrezz1.doubleValue();
DTotale+=dPrezz1;
sArtVenduti[i][9] = sRigheFatture[iCol][8];
if(i>=10)
{
PrinterJob printJob = PrinterJob.getPrinterJob ();
printJob.setPrintable (this);
try
{
printJob.print();
}
catch (Exception PrintException)
{
PrintException.printStackTrace();
}
for (j=0; j<=10; j++)
{
sArtVenduti[j][...] = null;
}
i=0;
}
}
if(i>0)
{
PrinterJob printJob = PrinterJob.getPrinterJob ();
printJob.setPrintable (this);
try
{
printJob.print();
}
catch (Exception PrintException)
{
PrintException.printStackTrace();
}
}
}
}
Manca qualcosa tipo definizione di variabile x problemi di quantità di caratteri da postare Datemi una mano così finisco ...