void ItemSplitter::printpdf(const QString& fileName){ QPrinter printer_html(QPrinter::ScreenResolution);
printer_html.setPageSize(QPrinter::A4);
printer_html.setOutputFormat(QPrinter::PdfFormat);
printer_html.setOutputFileName(fileName);
QPainter painter( &printer_html ); QSizeF pageSize(printer_html.pageRect().width(),printer_html.pageRect().height()); TreeItem * treeItem = rootItem;
QString logo = ("");
QString date = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); QString htmltable[],htmlbody[],htmlfront[],htmltext; htmlbody[] +="<html>";
htmlbody[] +="<body>";
htmlbody[] +="</body>";
htmlbody[] +="</html>"; htmltable[] +="<div><table width=\"85%\" align=\"center\">";
htmltable[] +="</table></div>"; htmlfront[] +=htmltable[];
htmlfront[] +="<tr><td><h1>"+QString("Parameter Report") + "</h1></td><td align=\"right\"><h1>"+ logo +"</h1></td> </tr>";
htmlfront[] +="<tr><td><h3>"+ date + " Page ";
htmlfront[] +="</h3></td><td align=\"right\" ><img src = \"logoprint.png\"></td></tr>";
htmlfront[] +="<tr><td colspan = \"2\"><hr/></td></tr>";
htmlfront[] +=htmltable[]; int pagenum = ;
int counter = ;
htmltext.clear();
htmltext+=htmlfront[];
htmltext+=QString::number(++pagenum);
htmltext+=htmlfront[];
htmltext += htmlbody[];
htmltext += htmltable[];
for( int i = ; i < treeItem->childCount() ; ++i)
{
TreeItem* it1 = treeItem->child(i);
htmltext +="<tr>";
htmltext += "<td colspan = \"4\">";
htmltext += "<strong>";
htmltext+= "Collumn " + it1->data(E_COORDINATE).toString();
htmltext+= ": " + it1->data(E_NAME).toString();
htmltext += "</strong>";
htmltext += "</td>";
htmltext +="</tr>";
counter += ;
for( int i = ; i < it1->childCount() ; ++i ,++counter)
{
TreeItem* it2 = it1->child(i);
htmltext +="<tr>";
htmltext +="<td>";
htmltext+= it2->data(E_COORDINATE).toString();
htmltext +="</td>"; htmltext +="<td>";
htmltext+= it2->data(E_NAME).toString();
htmltext +="</td>"; htmltext +="<td>";
htmltext+= it2->data(E_VALUE).toString();
htmltext +="</td>"; htmltext +="<td align=\"right\">";
htmltext+= it2->data(E_UNIT).toString();
htmltext +="</td>";
htmltext +="</tr>";
}
htmltext +="<tr>";
htmltext += "<td colspan = \"4\">";
htmltext += "</td>";
htmltext +="</tr>";
int nextcount;
if(i + < treeItem->childCount()){
it1 = treeItem->child(i + );
nextcount = it1->childCount();
}
else
{
nextcount = ;
}
if(counter + nextcount + > )
{
counter = ;
htmltext+=htmltable[];
// htmltext+="<div style=\"page-break-after:auto !important;\"></div>";
QTextDocument text_document;
text_document.setHtml(htmltext);
text_document.setPageSize(pageSize);
text_document.drawContents(&painter);
printer_html.newPage();
htmltext.clear();
htmltext+=htmlfront[];
htmltext+=QString::number(++pagenum);
htmltext+=htmlfront[];
htmltext +=htmltable[];
}
}
// qDebug() << html;
if( counter > )
{
htmltext += htmlbody[];
QTextDocument text_document;
text_document.setHtml(htmltext);
text_document.setPageSize(pageSize);
text_document.drawContents(&painter);
qDebug() <<" page count:" << text_document.pageCount();
} }