Results 1 to 4 of 4

Thread: How to write test into PDF file

  1. #1
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to write test into PDF file

    Dear Experts,

    I want to create a pdf file and the contents will vry dynamically. e.g i want to write like below


    HEADINGS
    1

    DESCRIPTION
    My description for 1

    HEADINGS
    2

    DESCRIPTION
    My description for 2 goes here

    DESCRIPTION & HEADING are static text and description is dynamic input provided by user. it may b mail id or description about . i've a textedit control where user will provide the description.

    Please let me know how to generate a pdf file and write my text into it.

    I used QPrnter class. but i dont know when my text is exceeding a page, so that i can create a new page.
    Thanks in advance for your help
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to write test into PDF file

    Refer this link... do similarly... http://doc.qt.digia.com/4.6/printing...ng-onto-a-page

    Refer this link... do similarly... http://doc.qt.digia.com/4.6/printing...ng-onto-a-page


    Added after 4 minutes:


    QTextEdit from 4.3 onwards also has a convenience function QTextEdit::print(QPrinter *printer)Use something like, (not tested)
    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    2. printer.setOutputFileName("print.ps");
    3. QPainter painter;
    4. painter.begin(&printer);
    5. QTextEdit text;
    6. text.setText("ur text here");
    7. text.print(&printer);
    To copy to clipboard, switch view to plain text mode 
    Last edited by pkj; 16th August 2013 at 11:53.

  3. #3
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to write test into PDF file

    Quote Originally Posted by pkj View Post
    Refer this link... do similarly... http://doc.qt.digia.com/4.6/printing...ng-onto-a-page

    Refer this link... do similarly... http://doc.qt.digia.com/4.6/printing...ng-onto-a-page


    Added after 4 minutes:


    QTextEdit from 4.3 onwards also has a convenience function QTextEdit::print(QPrinter *printer)Use something like, (not tested)
    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    2. printer.setOutputFileName("print.ps");
    3. QPainter painter;
    4. painter.begin(&printer);
    5. QTextEdit text;
    6. text.setText("ur text here");
    7. text.print(&printer);
    To copy to clipboard, switch view to plain text mode 
    Hi,
    Thanks for the reply. I tried like above code. I've passes .pdf instead of .ps file format. Though its generating file its not appending the text "ur text here inside the file.

    If i go as per link, i've to draw text in my pdf file and i dont know when to create a new page, as the input text is dynamic for me. Please help.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  4. #4
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to write test into PDF file

    Just tried a simple example...
    Qt Code:
    1. void MainWindow::printPdf()
    2. {
    3. QPrinter printer(QPrinter::HighResolution);
    4. printer.setOutputFileName("print.pdf");
    5. ui->textEdit->print(&printer);
    6. }
    To copy to clipboard, switch view to plain text mode 
    textEdit is a object in ui designer file mainWindow. Text edit is not a must. You can use QPainter or refer to the source of Qt to see how a QTextDocument is being used to print.

Similar Threads

  1. Unit Test: Test if QPushButton has a menu
    By FelixB in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2012, 12:12
  2. Best way to write to a file
    By The 11th plague of Egypt in forum Newbie
    Replies: 4
    Last Post: 25th August 2011, 14:43
  3. Replies: 2
    Last Post: 2nd November 2010, 05:15
  4. Replies: 3
    Last Post: 18th October 2007, 18:07
  5. Uic cannot write output file
    By jobrandt in forum Qt Tools
    Replies: 4
    Last Post: 25th May 2007, 07:55

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.