-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_dds.h
352 lines (294 loc) · 11.5 KB
/
pdf_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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#ifndef PDF_DDS_H
#define PDF_DDS_H
#include <QtWebEngineWidgets>
#include <QThread>
#include "form.h"
class Widget1 : public QWidget
{
public:
QStringList list;
explicit Widget1(QWidget *parent = nullptr):
QWidget(parent), button2(new QPushButton),button(new QPushButton),progressbar(new QProgressBar), progressbar2(new QProgressBar), view(new QWebEngineView), view2(new QWebEngineView)
{
pdfForm();
button->setText(tr("generate pdf dds"));
button->setEnabled(false);
connect(button, &QPushButton::clicked, this, &Widget1::onClicked);
connect(view, &QWebEngineView::loadFinished, this, &Widget1::onLoadFinished);
connect(view->page(), &QWebEnginePage::pdfPrintingFinished, this, &Widget1::onPdfPrintingFinished);
//connect(button, &QPushButton::clicked, this, &Widget::onClicked2);
connect(view2, &QWebEngineView::loadFinished, this, &Widget1::onLoadFinished2);
connect(view2->page(), &QWebEnginePage::pdfPrintingFinished, this, &Widget1::onPdfPrintingFinished2);
// === Load List Dari form pdf1 ===S===
QStringList form = pdfForm();
qInfo() << "Coba List String dari Form" << form;
// === Load List Dari form pdf1 ===S===
//!=================================================================================
loadlspdf1();
loadpdf1();
//!=================================================================================
QString path2("doc/temp/");
QString path("doc/html/");
QDir dir(path);
QFile htmlFile (path+ "srt1.html");
if (!htmlFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
qInfo() << "Html File tdk terbuka"; return;
}
QString htmlContent;
htmlContent = htmlFile.readAll();
htmlContent.replace("#DSTR#", nmdis );
htmlContent.replace("#KMP#", nmkamp );
htmlContent.replace("#TERBILANG#", terbilang);
htmlContent.replace("#NOREK#", norek);
htmlContent.replace("#NMREK#", nmrek);
htmlContent.replace("#NMBANK#", nmbank);
htmlContent.replace("#NKKP#", nmkkp);
htmlContent.replace("#NBENK#", nmbenk);
htmlContent.replace("#JKK#", jkk);
htmlContent.replace("#tahap#", tahap);
htmlContent.replace("#JML#", jml);
htmlContent.replace("#%#" , persen);
htmlContent.replace("#KPDNS#", nmkpdns);
htmlContent.replace("#tahap2#", tahap2);
htmlContent.replace("#PKPLD#", pkpldns);
//QString nmkdns;
htmlContent.replace("#NIPKDNS#", nip);
htmlContent.replace("****", nosrt1);
htmlContent.replace("####", nosrt2);
QDate d = QDate::fromString(tgl,"dd-MM-yyyy");
QString tgl_ = d.toString("dd MMMM yyyy");
htmlContent.replace("#TGL#", tgl_);
htmlContent.replace("#thn#", thn);
htmlContent.replace("#thn2#",thn2);
htmlContent.replace("#UDSTR#", unmdis);
htmlContent.replace("#UKMP#", unmkam );
htmlContent.replace("#SKKP#", skkam);
htmlContent.replace("#sk#", skkam);
htmlContent.replace("#skben#", skben );
QString html = htmlContent;
htmlFile.close();
QString l= html;
QFile fOut(path2+"dds.html");
fOut.open(QFile::WriteOnly | QFile::Text);
if(fOut.open(QFile::WriteOnly | QFile::Text)){qInfo()<<"tdk Bisa Buka file";} else {
QTextStream stream(&fOut);
stream << l;
fOut.flush();
fOut.close();
// QMessageBox::information(this,tr("Info"),tr("dds tersimpan"));
}
QFile htmlFile2 (path+ "srt2.html");
if (!htmlFile2.open(QIODevice::ReadOnly | QIODevice::Text))
{
qInfo() << "Html File 2 tdk terbuka"; return;
}
QString htmlContent2;
htmlContent2 = htmlFile2.readAll();
htmlFile2.close();
htmlContent2.replace("#DSTR#", nmdis );
htmlContent2.replace("#KMP#", nmkamp );
htmlContent2.replace("#TERBILANG#", terbilang);
htmlContent2.replace("#NOREK#", norek);
htmlContent2.replace("#NMREK#", nmrek);
htmlContent2.replace("#NMBANK#", nmbank);
htmlContent2.replace("#NKKP#", nmkkp);
htmlContent2.replace("#NBENK#", nmbenk);
htmlContent2.replace("#JKK#", jkk);
htmlContent2.replace("#tahap#", tahap);
htmlContent2.replace("#JML#", jml);
htmlContent2.replace("#%#" , persen);
htmlContent2.replace("#KPDNS#", nmkpdns);
htmlContent2.replace("#tahap2#", tahap2);
htmlContent2.replace("#PKPLD#", pkpldns);
htmlContent2.replace("#NIPKDNS#", nip);
htmlContent2.replace("****", nosrt1);
htmlContent2.replace("####", nosrt2);
htmlContent2.replace("#TGL#", tgl_);
htmlContent2.replace("#thn#", thn);
htmlContent2.replace("#thn2#",thn2);
htmlContent2.replace("#UDSTR#", unmdis);
htmlContent2.replace("#UKMP#", unmkam );
htmlContent2.replace("#SKKP#", skkam);
htmlContent2.replace("#sk#", skkam);
htmlContent2.replace("#skben#", skben );
QString html2 = htmlContent2;
htmlFile2.close();
fOut.close();
QString l2= html2;
QFile fOut2(path2+"dds2.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/dds.html");
view->setHtml(html);
view->load(url);
QUrl url2 = QUrl::fromLocalFile("/doc/temp/dds2.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);
}
QStringList pdfForm()
{
Form *f = new Form;
f->rundatapdf1();
return f->getLspdf1();
}
//private:
void onLoadFinished(bool ok)
{
button->setEnabled(ok);
}
void onLoadFinished2(bool ok)
{
button2->setEnabled(ok);
}
void onClicked()
{
progressbar->setRange(0, 0);
QString path("laporan/dds/");
QDir dir(path);
//QString Nama Auto
QString nmpdf = tahap +" dis "+nmdis+" kam "+nmkamp+".pdf";
QFile pdfFile ( path + "D " + nmpdf+".pdf");
QString fn = path + "D " + nmpdf +".pdf";
QFile pdfFile2 (path+"K " +nmpdf+".pdf");
QString fn2 = path + "K "+nmpdf+".pdf";
if(pdfFile.exists()){ pdfFile.remove(); }
if(pdfFile.exists()) {QMessageBox::information(this,"Info...","Tutup File pdf yg terbuka dan Generate Kembali"); qInfo()<<"Silahkan tutup pdf file"; return;}
if(pdfFile2.exists()){ pdfFile2.remove(); }
if(pdfFile2.exists()) {QMessageBox::information(this,"Info...","Tutup File pdf yg terbuka dan Generate Kembali"); qInfo()<<"Silahkan tutup pdf file"; return;}
// view2->page()->printToPdf(fn2,QPageLayout(QPageSize(QPageSize(QSize(780,1154))), QPageLayout::Portrait, QMargins(25,15,15,15)) );
view->page()->printToPdf(fn,QPageLayout(QPageSize(QPageSize(QSize(780,1154))), QPageLayout::Landscape, QMargins(50,0,15,15)) );
// view->page()->printToPdf(fn,QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Landscape, QMargins(25,15,15,15)) );
view2->page()->printToPdf(fn2,QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMargins(25,1,15,10)));
view->page()->pdfPrintingFinished(fn, QMessageBox::information(this,"Info...","Menyiapkan file, <b>Tekan ok setelah loading selesai</b>"));
bool ok ;
view2->page()->pdfPrintingFinished(fn2, (ok=true));
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+ "dtpdf1.txt");
if (!dtpdf1.open(QIODevice::ReadOnly | QIODevice::Text))
{
qInfo() << "dtpdf1.txt File tdk terbuka";
return;
}
QTextStream stream(&dtpdf1);
while (!stream.atEnd()) {
QString line = stream.readAll();
list = line.split("/n");
list << "aaa";
}
}
void loadpdf1()
{
nmdis = list.at(0);
nmkamp = list.at(1);
terbilang= toCamelCase(list.at(2).toCaseFolded());
norek = list.at(3);
nmrek = list.at(4);
nmbank = list.at(5);;
nmkkp = list.at(6);;
nmbenk = list.at(7);;
jkk = list.at(8);;
tahap = list.at(9);
jml = list.at(10);
persen = list.at(11);
nmkpdns = list.at(12);
tahap2 = list.at(13);
pkpldns = list.at(14);
//QString nmkdns;
nip = list.at(15);
nosrt1 = list.at(16);
nosrt2 = list.at(17);
tgl = list.at(18);
thn=tgl.right(4);
unmdis = list.at(19);
unmkam =list.at(20);
skben=list.at(21);
skkam=list.at(22);
thn2=list.at(23);
}
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() <<"pdf Finish"<< filename << ok;
progressbar->setRange(0, 1);
}
void onPdfPrintingFinished2(const QString & filename, bool ok)
{
qDebug() <<"pdf Finish 2"<< filename << ok;
progressbar2->setRange(0, 1);
}
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 nmdis ;
QString nmkamp ;
QString terbilang;
QString norek ;
QString nmrek ;
QString nmbank ;
QString nmkkp ;
QString nmbenk;
QString jkk ;
QString tahap ;
QString jml ;
QString persen ;
QString nmkpdns ;
QString tahap2 ;
QString pkpldns ;
//QString nmkdns;
QString nip ;
QString nosrt1 ;
QString nosrt2 ;
QString tgl ;
QString thn ;
QString skben;
QString skkam;
QString unmdis ;
QString unmkam ;
QString thn2;
//===================================================
QPushButton *button2;
QPushButton *button;
QProgressBar *progressbar;
QProgressBar *progressbar2;
QWebEngineView *view;
QWebEngineView *view2;
};
#endif // PDF_DDS_H