Results 1 to 9 of 9

Thread: Display pdf file in QTextEdit

  1. #1
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Display pdf file in QTextEdit

    Hello,

    I want to display a pdf file in an QText Edit. I believe i have to use Qprinter

    QString file= "Path/file/my.pdf
    QPrinter printer;

    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName(file);
    docTextEdit->print(&printer);

    But QtextEdit shows nothing...
    Any help?

    Thanks in advance

    Olivier

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Display pdf file in QTextEdit

    First read the Qt Docs for QPrinter.
    You are 200% wrong in what you want and how you are trying to do.

  3. #3
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display pdf file in QTextEdit

    Yes i've just noticed.

    the idea is to generate a print of the pdf file and to redirect it to QTextedit.

    Is that possible?

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Display pdf file in QTextEdit

    Quote Originally Posted by toutarrive View Post
    the idea is to generate a print of the pdf file
    That is fine, you can do it using QPrinter.

    Quote Originally Posted by toutarrive View Post
    and to redirect it to QTextedit.
    What do you mean by redirect?

  5. #5
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display pdf file in QTextEdit

    The doc says:

    The QPrinter class is a paint device that paints on a printer.

    This device represents a series of pages of printed output, and is used in almost exactly the same way as other paint devices such as QWidget and QPixmap.

    Instead of painting on a printer i would like to paint on QTextEdit (a QWidget).

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Display pdf file in QTextEdit

    Quote Originally Posted by toutarrive View Post
    Instead of painting on a printer i would like to paint on QTextEdit (a QWidget).
    I am not sure about this. Because I think, Qt docs doesn't says that you can read a PDF file. The only thing Qt deals with is, printing in PDF format. So, Qt can write PDF but cannot read it.
    On Windows you can use ActiveQt to embed the Acrobat ActiveX Control.

  7. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display pdf file in QTextEdit

    for displaying PDF you can use Poppler library as described here: http://doc.trolltech.com/qq/qq27-poppler.html.
    It is available as source and packages (on ubuntu you can install it with apt-get install), and cross-platform, but compiling it for windows is a nightmare
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  8. #8
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display pdf file in QTextEdit

    OK thanks for your answers guys! i do appreciate it.

    I tried to compile poppler on vista.. i gave up.

  9. #9
    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: Display pdf file in QTextEdit

    Quote Originally Posted by toutarrive View Post
    I tried to compile poppler on vista.. i gave up.
    Yes, that's tricky! But search for a project which uses poppler and steal the dll form that project...

Similar Threads

  1. How to display xml file in qwebview?
    By richardander in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2009, 21:10
  2. QTextEdit and insertImage() Display on the Fly..
    By Undefined in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2008, 19:48
  3. Display a file from Directory tree to show in QTextEdit
    By vvdounai in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2007, 13:43
  4. Can't display .jpg,.jpeg file in my QT app
    By Shalabh in forum Qt Programming
    Replies: 3
    Last Post: 23rd April 2007, 14:52
  5. How to display a file in the textBrowser
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2006, 19:47

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.