PDA

View Full Version : Printer paper layouts



IsoArska
17th July 2010, 11:24
I have a BIG problem. i am making billing program and i need print my invoices, i can print my invoices yes but i cant find a way to make good layout/template for it. in my country the invoices is strandard and i have to use that template.

here is the code :


QString html;
QString css;


css +=".padding5px{padding:5px 5px 5px 5px; border-color:white}";
css +=".padding10px{padding:5px 5px 5px 5px; border-color:white}";
css +=".t{background-color:blue;border:1px solid black;}";

html +="<html>";
html+="<head><link rel='stylesheet' type='text/css' href='testi.css'></head>";
html +="<body><table class='t' width='100%' border=0 cellspacing=0>"
"<tr><td><font size='+1'>"
"<b><i>" + title +"</i></b></font></td>";
html+="<td>Päivämäärä <br> 30.6.2010 </td>";
html+="<td>Laskunnumero 15555</td>";
html+="<tr><td rowspan='4' style='border:1px black solid;'>"+asiakkaanLaskutusnimi+"<br>";
html+=asiakkaanLaskutusosoite+"<br>"+asiakkaanLaskutusPostinro+" "+asiakkaanLaskutusPostitoimi;"</td>";
html+="<td>Viitteenne</td><td>Viitteenne</td><tr>";
html+="<td>Asiakasnro</td><tr><td>Toimitusaika</td>";
html+="<td>Huomautusaika</td><tr><td>Maksuehto</td><td>viivästyskorko</td></table><br><br>";
html+="<table border=0 cellspacing='3'><tr >";
html+="<td>Tuotenumero</td><td>Tuotenimi</td><td>kpl-hinta</td><td>Alennus</td><td>Yhteensä</td><tr>";

for(int i=0; i<=m_ui->tuotteetTable->rowCount()-1;i++){
QTableWidgetItem *tuotenro = m_ui->tuotteetTable->item(i,0);
QTableWidgetItem *tuoteNimi = m_ui->tuotteetTable->item(i,1);
QTableWidgetItem *tuoteKplhinta = m_ui->tuotteetTable->item(i,2);
QTableWidgetItem *tuoteRivihinta = m_ui->tuotteetTable->item(i,3);
QTableWidgetItem *alennus = m_ui->tuotteetTable->item(i,4);

html+="<td ><font size='+1'>"+tuotenro->text()+"</font></td><td><font size='+1'>"+tuoteNimi->text()+"</font></td><td><font size='+1'>"+tuoteKplhinta->text()+"</font></td><td><font size='+1'>"+alennus->text()+"</font></td><td><font size='+1'>"+tuoteRivihinta->text()+"</font></td><tr>";
}
html+="</table><br>";
html+="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr>";
html+="<td width='20' class='padding5px' align='right'><font size='-1' >Saajan tilinumero<br> Mottagarens kontonummer</font></td><td width='300' height='50'>EKSP xxxxxx-xxxxxx</td>";
html+="<td colspan='3' height='50'><font size='-1'>IBAN</font></td><td colspan='2' ><font size='-1'>BIC</font></td><tr>";
html+="<td width='20' class='padding5px' align='right'><font size='-1'>Saaja<br>Mottagare</font></td><td class='padding10px' width='200'>Testi Yrityks KY</td>";
html+="<td colspan='5' rowspan='2'></td><tr>";
html+="<td width='20' class='padding5px' align='right'><font size='-1' >Maksajan nimi ja osoite<br>Betalaren namn och adress</font></td><td class='padding10px'>"+asiakkaanLaskutusnimi+"<br>"+asiakkaanLaskutusosoite+"<br>"+asiakkaanLaskutusPostinro+" "+asiakkaanLaskutusPostitoimi+"</td>";
html+="<tr><td width='20' class='padding5px' align='right'><font size='-1' >Allekirjoitus<br>Underskrift</font></td><td>----------------------------------------</td>";
html+="<td class='padding5px' align='left'><font size='-1' >Viitenro<br> ref.nr</font></td><td colspan='4'></td><tr>";
html+="<td width='20' class='padding5px' align='right'><font size='-1' >Tililtä nro.<br> Från konto nr</font></td><td width='50'></td><td width='20'><font size='-1'>Eräpäivä<br>Förf.dag</font></td><td width='100' colspan='2'>xx.xx.xxxx</td><td colspan='2'><b>EUR</b></td></table>";


html +="</table><br></body></html>";



QPrinter printer(QPrinter::ScreenResolution);

printer.setPrinterName("HP LaserJet 4100 Series PCL6");
printer.setPaperSize(QPrinter::A4);
printer.setDocName("Testi");
printer.setOrientation(QPrinter::Portrait);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("lasku.pdf");
printer.setFullPage(true);
printer.setNumCopies(1);
printer.setResolution(300);
QTextDocument *document = new QTextDocument;

document->addResource(QTextDocument::StyleSheetResource,QUrl ("testi.css"),css);
document->setHtml(html);
document->print(&printer);


And the problem is that when i use css styles border attribute the qt richtext engine doesent support it so. is there any other way to do this where i can edit the table data borders, XML mayby ?
the only solution what i came up with is that i make widget for this and print that but this doesent sound right to me. I have googled but i cant find any solution for this. So if any one have a good tutorial or solution for this please tell me, And the Qt version is 4.6 opensource

Lykurg
17th July 2010, 15:22
Hi,

the template doesn't look so complicated, so you can do all the painting yourself using QPainter. Draw the text and lines (= border) with the common functions.


Lykurg