This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
39 lines (36 loc) · 1.42 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <QtDebug>
#include <QApplication>
#include <QWebEnginePage>
#include <QCommandLineParser>
#include "pdfgenerator.h"
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QString message = qFormatLogMessage(type, context, msg);
QTextStream(stderr) << message << "\n";
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QCoreApplication::setApplicationName("genpdf");
QCoreApplication::setApplicationVersion("1.0.0");
/* setup logging */
qSetMessagePattern("%{time} [%{type}] %{message}");
qInstallMessageHandler(messageHandler);
qInfo().noquote() << QCoreApplication::applicationName() << QCoreApplication::applicationVersion();
/* parse command line arguments */
QCommandLineParser parser;
parser.setApplicationDescription("Converts the web page INPUT into the PDF file OUTPUT");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("INPUT", "Path of the HTML file to process");
parser.addPositionalArgument("OUTPUT", "Path of the PDF file to create");
parser.parse(QCoreApplication::arguments());
const QStringList positionalArgs = parser.positionalArguments();
if(positionalArgs.size() != 2)
{
parser.showHelp(1);
}
/* generate PDF from HTML file */
PDFGenerator generator(positionalArgs.at(0), positionalArgs.at(1));
return generator.generate();
}