Results 1 to 7 of 7

Thread: How to display PDF in Qt?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: How to display PDF in Qt?

    Quote Originally Posted by stelio View Post
    Hi!

    is there any ways to display PDF in an Qt application?

    Thanks!
    stelio
    QT3 DTP Scribus programm import pdf as image .. need only ghostscript an run on mac,win, linux

    this is part of code from QT 4.4 MiniScribus
    http://www.qt-apps.org/content/show....?content=80234

    Qt Code:
    1. extern inline QPixmap LoadPDF(QString fn, int Page, int w )
    2. {
    3. QString tmp, cmd1, cmd2;
    4. const QString pdfFile = PathConvert(fn);
    5. const QString tmpFile = PathConvert(QDir::homePath()+"/sctodaytmps.png");
    6. const QString qttmpFile = QDir::homePath()+"/sctodaytmps.png";
    7. QPixmap pm;
    8. tmp.setNum(Page);
    9. int ret = -1;
    10. tmp.setNum(Page);
    11. args.append("-sDEVICE=png16m");
    12. args.append("-r72");
    13. args.append("-dGraphicsAlphaBits=4");
    14. args.append("-o");
    15. args.append(tmpFile);
    16. args.append("-dFirstPage="+tmp);
    17. args.append("-dLastPage="+tmp);
    18. args.append(pdfFile);
    19. ret = callGS(args);
    20. ////////qDebug() << "### ret " << ret;
    21. if (ret == 0)
    22. {
    23. QPixmap tmpimage(qttmpFile);
    24. QPixmap penna = tmpimage.scaledToWidth(w);
    25. tmpimage.detach();
    26. QFile lastaction(qttmpFile);
    27. lastaction.remove();
    28. p.begin(&penna);
    29. p.setBrush(Qt::NoBrush);
    30. p.setPen(QPen(QBrush(Qt::black),2,Qt::SolidLine));
    31. p.drawRect(0, 0, penna.width(), penna.height());
    32. p.end();
    33. return penna;
    34. }
    35. return pm;
    36. }
    37.  
    38. extern inline int callGS( const QStringList args )
    39. {
    40. const QString startnow = QDir::currentPath();
    41. const QString GhostScriptPath = getGSDefaultExeName();
    42. QDir::setCurrent(_GSCACHE_);
    43. QString cmd1 = GhostScriptPath + " ";
    44. cmd1 += args.join(" ");
    45. int fax = -1;
    46. #if defined Q_WS_MAC
    47. fax = system(cmd1.toLocal8Bit());
    48. QDir::setCurrent(startnow);
    49. return fax;
    50. #endif
    51. QProcess *process = new QProcess(NULL);
    52. process->setReadChannelMode(QProcess::MergedChannels);
    53. process->start( GhostScriptPath , args , QIODevice::ReadOnly );
    54. if (!process->waitForFinished()) {
    55. fax = -1;
    56. } else {
    57. QString ghostcomment = process->readAll().trimmed();
    58. //////qDebug() << "ghostcomment-> " << ghostcomment;
    59. fax = 0;
    60. }
    61.  
    62. QDir::setCurrent(startnow);
    63. return fax;
    64. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2008
    Posts
    2
    Platforms
    MacOS X Windows

    Default Re: How to display PDF in Qt?

    Thanks for all those answers!

    I will investigate xpdf, mupdf and poppler to better understand.

    MiniScribus is very interesting, but as I understand, it convert it to a png. I need to provide graphical zoom feature in the PDF without loosing the vectorial display.

    Is converting PDF to SVG an option?

    stelio

  3. #3
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: How to display PDF in Qt?

    The best option is a poppler fork

    svn co http://poppler-kjk.googlecode.com/svn/trunk/ Fpoppler

    it can run on linux mac e win
    on window you must install automake autoconf
    like this http://www.venge.net/mtn-wiki/BuildingOnWindows

    info on http://blog.kowalczyk.info/software/sumatrapdf/ &&
    Sumatra PDF source on ...
    http://blog.kowalczyk.info/software/.../download.html

Similar Threads

  1. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  2. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 14:06
  3. Replies: 3
    Last Post: 17th October 2007, 12:52
  4. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.