I try to load a Portable pixmap to QImage
http://en.wikipedia.org/wiki/Portabl...ap_file_format and QImage not load ..

I hack the XPDF 3.0.2 to enable build on QT4.3 i build on Win Mingw

http://ppk.ciz.ch/qt_c++/XPDF_2_QT.tar.bz2 400kb

the hard work was the pro file to accept minumum to make Portable pixmap


only lib give no problem. main apps say ...

main.cpp: In function `int main(int, char**)':
main.cpp:54: error: conversion from `SplashBitmap*' to non-scalar type `QByteArr
ay' requested



Qt Code:
  1. #include <QFile>
  2. #include <QtCore>
  3. #include <QCoreApplication>
  4.  
  5. #include <aconf.h>
  6. #include <stdio.h>
  7. #include "parseargs.h"
  8. #include "GString.h"
  9. #include "Object.h"
  10. #include "PDFDoc.h"
  11. #include "SplashBitmap.h"
  12. #include "Splash.h"
  13. #include "SplashOutputDev.h"
  14. #include "config.h"
  15. #include <iostream>
  16. #include <QImage>
  17. using namespace std;
  18.  
  19. /* xpdf 3.02 PDF 1.4 dir and libs hacked to QT4 get http://ppk.ciz.ch/qt_c++/XPDF_2_QT.tar.bz2 400kb */
  20.  
  21.  
  22. int main(int argc, char *argv[]) {
  23. QCoreApplication a( argc, argv );
  24.  
  25. PDFDoc *doc;
  26. GString *fileName;
  27. GString *ownerPW, *userPW;
  28. SplashColor paperColor;
  29. SplashOutputDev *splashOut;
  30. GBool ok;
  31. int resolution = 300;
  32. ownerPW = NULL;
  33. userPW = NULL;
  34. int sumpage;
  35.  
  36. const QString filepdf = argv[1];
  37. if (filepdf.size() < 1) {
  38. cout << "Usage:\n";
  39. cout << "appsname pdf_file";
  40.  
  41. return 0;
  42. } else {
  43. /* build the class ! */
  44. fileName = new GString(new GString(filepdf)); /* GString is hack to accept QString */
  45. doc = new PDFDoc(fileName, ownerPW, userPW);
  46. paperColor[0] = paperColor[1] = paperColor[2] = 0xff;
  47. splashOut = new SplashOutputDev(splashModeRGB8, 1, gFalse, paperColor);
  48. sumpage = doc->getNumPages();
  49. splashOut->startDoc(doc->getXRef());
  50.  
  51. for (int i=0;i<sumpage;i++) {
  52. int pagenr = i + 1; /* render page pdf nr. */
  53. doc->displayPage(splashOut, pagenr, resolution, resolution, 0, gFalse, gTrue, gFalse);
  54. QByteArray dat = splashOut->takeBitmap();
  55. QImage pdfpage;
  56. pdfpage.loadFromData(dat);
  57. /* if ok save .... */
  58. if (!pdfpage.isNull()) {
  59. const QString filepage = QString("Page%1.png").arg(pagenr);
  60. pdfpage.save(filepage,"PNG",100);
  61. }
  62.  
  63. }
  64.  
  65. /* remove class */
  66. delete splashOut;
  67. delete doc;
  68.  
  69. }
  70. return 0;
  71. }
To copy to clipboard, switch view to plain text mode