-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_sppd_dds.h
272 lines (221 loc) · 9 KB
/
pdf_sppd_dds.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#ifndef PDF_SPPD_DDS_H
#define PDF_SPPD_DDS_H
#include <QtWebEngineWidgets>
#include <QThread>
#include "form.h"
class Widget3 : public QWidget
{
public:
QStringList list; QStringList li_bm;
explicit Widget3(QWidget *parent = nullptr):
QWidget(parent), button2(new QPushButton),button(new QPushButton),progressbar(new QProgressBar), progressbar2(new QProgressBar), view(new QWebEngineView), view2(new QWebEngineView)
{
button->setText(tr("generate pdf sppd dds"));
button->setEnabled(false);
connect(button, &QPushButton::clicked, this, &Widget3::onClicked);
connect(view, &QWebEngineView::loadFinished, this, &Widget3::onLoadFinished);
connect(view->page(), &QWebEnginePage::pdfPrintingFinished, this, &Widget3::onPdfPrintingFinished);
//connect(button, &QPushButton::clicked, this, &Widget::onClicked2);
connect(view2, &QWebEngineView::loadFinished, this, &Widget3::onLoadFinished2);
connect(view2->page(), &QWebEnginePage::pdfPrintingFinished, this, &Widget3::onPdfPrintingFinished2);
//!=================================================================================
loadlspdf1();
loadpdf1();
//!=================================================================================
// Form *fr = new Form;
// qInfo() <<"Jumlah Cair dari form" << fr->getTot_sppd();
QString path2("doc/temp/");
QString path("doc/html/");
QDir dir(path);
QFile htmlFile (path+ "SPPD.html");
if (!htmlFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
qInfo() << "Html File SPPD tdk terbuka"; return;
}
QString htmlContent;
htmlContent = htmlFile.readAll();
htmlContent.replace("****",nosrt);
htmlContent.replace("#dddd#",htm);
htmlContent.replace("#total#", tot);
//htmlContent.replace("#tgl#", tgl);
htmlContent.replace("#tgl_#", tgl_);
htmlContent.replace("#tgl#", tgl);
htmlContent.replace("#thn#", thn);
htmlContent.replace("#KPDNS#", kpdns);
htmlContent.replace("#PKPLD#", jkpdns);
htmlContent.replace("#NIPKDNS#", nipkpdns);
htmlContent.replace("#hal#", hal);
QString html = htmlContent;
htmlFile.close();
QString l= html;
QFile fOut(path2+"sppd.html");
fOut.open(QFile::WriteOnly | QFile::Text);
if(fOut.open(QFile::WriteOnly | QFile::Text)){qInfo()<<"tdk Bisa Buka file sppd.html";} else {
QTextStream stream(&fOut);
stream << l;
fOut.flush();
fOut.close();
}
QFile htmlFile2 (path+ "SPPD_Lampiran.html");
if (!htmlFile2.open(QIODevice::ReadOnly | QIODevice::Text))
{
qInfo() << "Html File SPPD L tdk terbuka"; return;
}
QString htmlContent2;
htmlContent2 = htmlFile2.readAll();
htmlFile2.close();
htmlContent2.replace("****",nosrt);
htmlContent2.replace("#dddd#",htm);
htmlContent2.replace("#total#", tot);
//htmlContent2.replace("#tgl#", tgl);
htmlContent2.replace("#tgl_#", tgl_);
htmlContent2.replace("#tgl#", tgl);
htmlContent2.replace("#thn#", thn);
htmlContent2.replace("#KPDNS#", kpdns);
htmlContent2.replace("#PKPLD#", jkpdns);
htmlContent2.replace("#NIPKDNS#", nipkpdns);
htmlContent2.replace("#terbilang#", toCamelCase(terbilang));
htmlContent2.replace("#hal#", hal);
qInfo() << "Terbilang pdf 3" << terbilang;
QString html2 = htmlContent2;
htmlFile2.close();
fOut.close();
QString l2= html2;
QFile fOut2(path2+"sppdl.html");
fOut2.open(QFile::WriteOnly | QFile::Text);
if(fOut2.open(QFile::WriteOnly | QFile::Text)){qInfo()<<"tdk Bisa Buka file";} else {
QTextStream stream2(&fOut2);
stream2 << l2;
fOut2.flush();
fOut2.close();
// QMessageBox::information(this,tr("Info"),tr("dds 2 tersimpan"));
}
fOut2.close();
htmlFile2.close();
QUrl url = QUrl::fromLocalFile("/doc/temp/sppd.html");
view->setHtml(html);
view->load(url);
QUrl url2 = QUrl::fromLocalFile("/doc/temp/sppdl.html");
view2->setHtml(html2);
view2->load(url2);
auto lay = new QVBoxLayout(this);
lay->addWidget(button);
lay->addWidget(progressbar);
//lay->addWidget(view);
//lay->addWidget(view2);
//resize(630, 780);
resize(330, 280);
}
//private:
void onLoadFinished(bool ok)
{
button->setEnabled(ok);
}
void onLoadFinished2(bool ok)
{
button2->setEnabled(ok);
}
void onClicked()
{
progressbar->setRange(0, 0);
QString path("laporan/sppd/");
QDir dir(path);
QFile pdfFile (path+ tgl_+ "SPPD.pdf");
QString fn = path+ tgl_+"SPPD.pdf";
QFile pdfFile2 (path+ tgl_+ "SPPD_L.pdf");
QString fn2 = path+ tgl_+"SPPD_L.pdf";
if(pdfFile.exists()){ pdfFile.remove(); }
if(pdfFile.exists()) {QMessageBox::information(this,"Info...","Tutup File pdf yg terbuka"); qInfo()<<"Silahkan tutup pdf file"; return;}
if(pdfFile2.exists()){ pdfFile2.remove(); }
if(pdfFile2.exists()) {QMessageBox::information(this,"Info...","Tutup File pdf yg terbuka"); qInfo()<<"Silahkan tutup pdf file"; return;}
view->page()->printToPdf(fn,QPageLayout(QPageSize(QPageSize(QSize(743,987))), QPageLayout::Portrait, QMargins(55,25,15,25)) );
view2->page()->printToPdf(fn2,QPageLayout(QPageSize(QPageSize(QSize(780,1154))), QPageLayout::Landscape, QMargins(40,15,15,20)) );
// view->page()->printToPdf(fn,QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Landscape, QMargins(25,15,15,15)) );
// view2->page()->printToPdf(fn,QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Landscape, QMargins(25,15,15,15)) );
view->page()->pdfPrintingFinished(fn, QMessageBox::information(this,"Info...","<b>Generating pdf file...</b>"));
bool ok;
view2->page()->pdfPrintingFinished(fn2, (ok=true));
// if(ok==false){QMessageBox::information(this,"Info...","Generating pdf file Gagal, Coba Kembali"); return; }
sleep(2);
QDesktopServices::openUrl(QUrl::fromLocalFile(fn)); msleep(1); QDesktopServices::openUrl(QUrl::fromLocalFile(fn2));
view->close();
view2->close();
this->close();
}
void run() {
QTimer* timer = new QTimer(this);
timer->setInterval(1);
timer->connect(timer, SIGNAL(timeout()), this, SLOT(doIt()));
timer->start();
}
void loadlspdf1()
{
QString pt("doc/temp/");
QFile dtpdf1 (pt+ "sppd_temp.txt");
if (!dtpdf1.open(QIODevice::ReadOnly | QIODevice::Text))
{
qInfo() << "sppd_temp File tdk terbuka"; return;
}
QTextStream stream(&dtpdf1);
while (!stream.atEnd()) {
QString line = stream.readAll();
list = line.split("#/#");
list << "aaa";
}
}
void loadpdf1()
{
htm = list.at(0);
tot = list.at(1);
tgl = list.at(2);
tgl_= list.at(3);
thn = list.at(4);
nosrt = list.at(5);
hal = list.at(6);
kpdns = list.at(7);
jkpdns= list.at(8);
nipkpdns = list.at(9);
terbilang = list.at(10);
}
QString toCamelCase(const QString &s)
{
QStringList parts = s.split(' ',QString::SkipEmptyParts );
for (int i = 0; i < parts.size(); ++i)
parts[i].replace(0, 1, parts[i][0].toUpper());
return parts.join(" ");
}
void onPdfPrintingFinished(const QString & filename, bool ok)
{
qDebug() << filename << ok;
progressbar->setRange(0, 100);
}
void onPdfPrintingFinished2(const QString & filename, bool ok)
{
qDebug() << filename << ok;
progressbar2->setRange(0, 100);
}
static void usleep(unsigned long usecs){QThread::usleep(usecs);}
static void msleep(unsigned long msecs){QThread::msleep(msecs);}
static void sleep(unsigned long secs){QThread::sleep(secs);}
public slots:
//===================================================
QString htm;
QString tot;
QString tgl;
QString tgl_;
QString thn;
QString nosrt;
QString hal;
QString kpdns;
QString jkpdns;
QString nipkpdns;
QString terbilang;
//===================================================
QPushButton *button2;
QPushButton *button;
QProgressBar *progressbar;
QProgressBar *progressbar2;
QWebEngineView *view;
QWebEngineView *view2;
};
#endif // PDF_SPPD_DDS_H