Skip to content
Permalink
Browse files
Working program
  • Loading branch information
antialize committed May 7, 2008
0 parents commit 1e55e71dabf90c41c15a6cc47adbf198be0b2c95
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
@@ -0,0 +1,14 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(wkhtmltopdf)
SET( CMAKE_COLOR_MAKEFILE ON )
SET( CMAKE_VERBOSE_MAKEFILE ON )
SET( CMAKE_INCLUDE_CURRENT_DIR TRUE )
ADD_DEFINITIONS( -Wall -ansi)
SET( QT_USE_QTWEBKIT TRUE )
FIND_PACKAGE( Qt4 REQUIRED )
INCLUDE( ${QT_USE_FILE} )
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR} )
QT4_WRAP_CPP(HAT wkhtmltopdf.hh)
ADD_EXECUTABLE(wkhtmltopdf wkhtmltopdf.cc ${HAT})
TARGET_LINK_LIBRARIES( wkhtmltopdf ${QT_LIBRARIES} )
INSTALL(TARGETS wkhtmltopdf DESTINATION bin)
@@ -0,0 +1,41 @@
#include "wkhtmltopdf.hh"
QApplication * app;

void WKHtmlToPdf::run(int argc, char ** argv) {
if(argc != 3) {
fprintf(stderr,
"Usage: wkhtmltopdf <input file> <output file>\n"
"\t<input file> URL or local path to html document\n"
"\t<output file> Name of ps or pdf file to be produced\n");
exit(1);
}
QUrl url(argv[1]);
v.load(url);
out = argv[2];
connect(&v, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
connect(&v, SIGNAL(loadFinished()), this, SLOT(loadFinished()));
}

void WKHtmlToPdf::loadFinished() {
printf("Outputting page \r");
fflush(stdout);
QPrinter p(QPrinter::HighResolution);
p.setOutputFileName(out);
p.setPaperSize(QPrinter::A4);
v.print(&p);
printf("Done \n");
app->quit();
}

void WKHtmlToPdf::loadProgress(int progress) {
printf("Loading page: %d%% \r",progress);
fflush(stdout);
}

int main(int argc, char * argv[]) {
QApplication a(argc,argv);
app = &a;
WKHtmlToPdf x;
x.run(argc,argv);
return a.exec();
}
@@ -0,0 +1,16 @@
#ifndef __wkhtmltopdf_hh__
#define __wkhtmltopdf_hh__
#include <QObject>
#include <QtGui>
#include <QWebView>
class WKHtmlToPdf : public QObject {
Q_OBJECT
public:
QWebView v;
char * out;
void run(int argc, char** argv);
public slots:
void loadFinished();
void loadProgress(int progress);
};
#endif //__wkhtmltopdf_hh__

0 comments on commit 1e55e71

Please sign in to comment.