Results 1 to 3 of 3

Thread: overwrite pdf file

  1. #1
    Join Date
    May 2011
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default overwrite pdf file

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: overwrite pdf file

    Then delete the file first. QDir::remove().

  3. The following user says thank you to Lykurg for this useful post:

    terhje (22nd February 2012)

  4. #3
    Join Date
    Feb 2012
    Location
    Olsztyn, Poland
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: overwrite pdf file

    What I did, was:
    Qt Code:
    1. QString pdfFile = QFileDialog::getSaveFileName(this, trUtf8("Save Client Details:"), "Client_"+fullName, "Pdf Files (*.pdf)");
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. Overwrite mode in QLineEdit
    By tarod in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2011, 15:43
  2. Overwrite Qt slot ...
    By jiapei100 in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2010, 09:54
  3. Replies: 6
    Last Post: 17th April 2009, 10:09
  4. Replies: 2
    Last Post: 28th March 2009, 10:11
  5. Overwrite QKeyEvent
    By haldrik in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2008, 19:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.