This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1e55e71
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__ |