PDA

View Full Version : overwrite pdf file



terhje
22nd February 2012, 10:18
Hi im writing a pdf report to a file from my program.

part of the code:
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(filename); //path + filename
QPainter painter;
painter.begin(&printer);

painter.drawText(sX,sY,"Adress:"); //sX,pX and sY are just coordinates in the pdf.
painter.drawText(pX,sY,adress);
painter.end();

my problem is that if the file already exists it wont write. i get error saying printer not active.
What i want to do is to just overwrite the old file.
any suggestions to how i can do this?
thx, Terhje

Lykurg
22nd February 2012, 10:42
Then delete the file first. QDir::remove().

zuberek
22nd February 2012, 12:41
What I did, was:

QString pdfFile = QFileDialog::getSaveFileName(this, trUtf8("Save Client Details:"), "Client_"+fullName, "Pdf Files (*.pdf)");
And just use printer.setOutputFileName(pdfFile);
When You try to save file, Save File Dialog appears and it has default file name (in this case "Client+fullName") and if there is file with the same name it just ask if You want to overwrite it.