Mysql and PDF
-
personal
Need a little help need to get data from a select and play in a pdf. The two separated can normally do, ie create a pdf with data "fixed" quiet and will make the connection to the database, select, delete, upgrade is also quiet.
Now the two together still can not, I tried to do this:
@
QPrinter printer;
QString dt_venda,cod_venda,valor,cod_arm,forma;
printer.setColorMode(QPrinter::Color);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("/home/will/Vendas_do_dia.pdf");
QPainter painter;
QImage imagem ("/home/will/foto_dia.jpg");
if (! painter.begin(&printer)) { // failed to open file
qWarning("failed to open file, is it writable?");
}
painter.drawImage(10,10,imagem);
painter.drawText (400,50,Data);
painter.drawText(10,60,"____________________________________________________________________________________");
Conexao();
QSqlQuery qry;
qry.prepare("select dt_venda,codVenda,valor,codArm,form_pag from vendas where dt_venda= :data");
qry.bindValue(":data",Data);
qry.exec();
while(qry.next())
{
dt_venda = qry.value(0).toString();
cod_venda = qry.value(1).toString();
valor = qry.value(2).toString();
cod_arm = qry.value(3).toString();
forma = qry.value(4).toString();painter.drawText(10,90,dt_venda); painter.drawText(10,110,cod_venda); painter.drawText(10,130,valor); painter.drawText(10,150,cod_arm); painter.drawText(10,180,forma); } painter.end(); QDesktopServices::openUrl(QUrl("/home/will/Vendas_do_dia.pdf"));@
Only it's not working printing the pdf file ie back empty any suggestions on how to get that impression?
-
Recently, I did the same thing.
But your problem is not very clear to me.
Are you getting empty pdf page?
First check the values of the variables dt_venda ,cod_venda ,valor , cod_arm , forma not empty.
And try to use point to printer instead of reference. (here : painter.begin(&printer))