patrik08
24th April 2007, 10:47
I try to load a Portable pixmap to QImage
http://en.wikipedia.org/wiki/Portable_Pixmap_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
#include <QFile>
#include <QtCore>
#include <QCoreApplication>
#include <aconf.h>
#include <stdio.h>
#include "parseargs.h"
#include "GString.h"
#include "Object.h"
#include "PDFDoc.h"
#include "SplashBitmap.h"
#include "Splash.h"
#include "SplashOutputDev.h"
#include "config.h"
#include <iostream>
#include <QImage>
using namespace std;
/* 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 */
int main(int argc, char *argv[]) {
QCoreApplication a( argc, argv );
PDFDoc *doc;
GString *fileName;
GString *ownerPW, *userPW;
SplashColor paperColor;
SplashOutputDev *splashOut;
GBool ok;
int resolution = 300;
ownerPW = NULL;
userPW = NULL;
int sumpage;
const QString filepdf = argv[1];
if (filepdf.size() < 1) {
cout << "Usage:\n";
cout << "appsname pdf_file";
return 0;
} else {
/* build the class ! */
fileName = new GString(new GString(filepdf)); /* GString is hack to accept QString */
doc = new PDFDoc(fileName, ownerPW, userPW);
paperColor[0] = paperColor[1] = paperColor[2] = 0xff;
splashOut = new SplashOutputDev(splashModeRGB8, 1, gFalse, paperColor);
sumpage = doc->getNumPages();
splashOut->startDoc(doc->getXRef());
for (int i=0;i<sumpage;i++) {
int pagenr = i + 1; /* render page pdf nr. */
doc->displayPage(splashOut, pagenr, resolution, resolution, 0, gFalse, gTrue, gFalse);
QByteArray dat = splashOut->takeBitmap();
QImage pdfpage;
pdfpage.loadFromData(dat);
/* if ok save .... */
if (!pdfpage.isNull()) {
const QString filepage = QString("Page%1.png").arg(pagenr);
pdfpage.save(filepage,"PNG",100);
}
}
/* remove class */
delete splashOut;
delete doc;
}
return 0;
}
http://en.wikipedia.org/wiki/Portable_Pixmap_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
#include <QFile>
#include <QtCore>
#include <QCoreApplication>
#include <aconf.h>
#include <stdio.h>
#include "parseargs.h"
#include "GString.h"
#include "Object.h"
#include "PDFDoc.h"
#include "SplashBitmap.h"
#include "Splash.h"
#include "SplashOutputDev.h"
#include "config.h"
#include <iostream>
#include <QImage>
using namespace std;
/* 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 */
int main(int argc, char *argv[]) {
QCoreApplication a( argc, argv );
PDFDoc *doc;
GString *fileName;
GString *ownerPW, *userPW;
SplashColor paperColor;
SplashOutputDev *splashOut;
GBool ok;
int resolution = 300;
ownerPW = NULL;
userPW = NULL;
int sumpage;
const QString filepdf = argv[1];
if (filepdf.size() < 1) {
cout << "Usage:\n";
cout << "appsname pdf_file";
return 0;
} else {
/* build the class ! */
fileName = new GString(new GString(filepdf)); /* GString is hack to accept QString */
doc = new PDFDoc(fileName, ownerPW, userPW);
paperColor[0] = paperColor[1] = paperColor[2] = 0xff;
splashOut = new SplashOutputDev(splashModeRGB8, 1, gFalse, paperColor);
sumpage = doc->getNumPages();
splashOut->startDoc(doc->getXRef());
for (int i=0;i<sumpage;i++) {
int pagenr = i + 1; /* render page pdf nr. */
doc->displayPage(splashOut, pagenr, resolution, resolution, 0, gFalse, gTrue, gFalse);
QByteArray dat = splashOut->takeBitmap();
QImage pdfpage;
pdfpage.loadFromData(dat);
/* if ok save .... */
if (!pdfpage.isNull()) {
const QString filepage = QString("Page%1.png").arg(pagenr);
pdfpage.save(filepage,"PNG",100);
}
}
/* remove class */
delete splashOut;
delete doc;
}
return 0;
}