Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Working program
Browse files Browse the repository at this point in the history
  • Loading branch information
antialize committed May 7, 2008
0 parents commit 1e55e71
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
@@ -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)
41 changes: 41 additions & 0 deletions wkhtmltopdf.cc
@@ -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();
}
16 changes: 16 additions & 0 deletions wkhtmltopdf.hh
@@ -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.