-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpdf2txt.bas
2326 lines (2127 loc) · 64.6 KB
/
pdf2txt.bas
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
' PDF2TXT
' Version 4.0
' November 20, 2015
' Copyright 2005 - 2015 by Jamal Mazrui
' GNU Lesser General Public License (LGPL)
#Compile Exe
#Dim All
' #Resource "sample.pbr"
%USEMACROS = 1
#Include "private.inc"
#Include "win32api.inc"
' #Include "C:\SayTools\SayTools.inc"
#Include "CommCtrl.inc"
#Include "ShLwApi.inc"
#Include "RichEdit.inc"
#Include "EOIni.inc"
#Include "funcky.inc"
#Include "MyLib.inc"
#Include "fn.inc"
#Include "ezgui30.inc"
'#Include "iSQP0511PB.inc"
' Application Constants and Declares
%id_Elevate = 90
$id_Elevate = "90"
%id_pdflabel=91
%id_pdf=92
%id_open=93
%id_select=94
%ID_GRAB=95
%ID_PASSWORDLabel =96
%ID_PASSWORD =97
%ID_imageFormat =98
%ID_ExtraOutputs =99
%id_viewlabel=106
%id_view=107
%id_txtlabel=108
%id_txt=109
%id_browse=110
%id_subfolders=111
%id_move=112
%id_replace=113
%ID_APPEND=114
%id_convert=1
%id_look=116
%id_defaults=117
%ID_EXPLORER=118
%id_quit=119
$id_quit="119"
%id_help=120
$id_help="120"
%id_statusbar=121
%id_forwardfind=122
$id_forwardfind="122"
%id_reversefind=123
%id_forwardagain=124
$id_forwardagain="124"
%id_reverseagain=125
%ID_ESCAPE = 126
$ID_ESCAPE = "126"
%ID_SETBOOKMARK=127
$ID_SETBOOKMARK="127"
%ID_CLEARBOOKMARK=128
$ID_CLEARBOOKMARK="128"
%ID_GOTOBOOKMARK=129
$ID_GOTOBOOKMARK="129"
%ID_GOTOPERCENT=130
$ID_GOTOPERCENT="130"
%ID_STARTSELECT=131
$ID_STARTSELECT="131"
%ID_CompleteSELECT=132
$ID_CompleteSELECT="132"
%ID_COPYALL=133
$ID_COPYALL="133"
%ID_COPYAPPEND=134
$ID_COPYAPPEND="134"
%Form1FILE = 500
%Form1NEWFILE = 505
%Form1OPENFILE = 510
%Form1SAVEFILE = 515
%Form1SAVEAS = 520
%Form1SEPARATOR_525 = 525
%Form1EXIT = 530
%Form1EDIT = 600
%Form1CUT = 605
%Form1COPY = 610
%Form1PASTE = 615
%Form1HELP = 700
%Form1HELP1 = 705
%Form1BUTTON1 = 100
%Form1Convert = 105
%Form1CHECK1 = 110
%Form1CHECK2 = 115
%Form1CHECK3 = 120
%Form1RADIO1 = 125
%Form1RADIO2 = 130
%Form1TEXT1 = 135
%Form1LISTBOX1 = 140
%Form1COMBOBOX1 = 145
%Form1LABEL1 = 150
%Form1FRAME1 = 155
Declare Sub Form1FILE_Select()
Declare Sub Form1NEWFILE_Select()
Declare Sub Form1OPENFILE_Select()
Declare Sub Form1SAVEFILE_Select()
Declare Sub Form1SAVEAS_Select()
Declare Sub Form1EXIT_Select()
Declare Sub Form1EDIT_Select()
Declare Sub Form1CUT_Select()
Declare Sub Form1COPY_Select()
Declare Sub Form1PASTE_Select()
Declare Sub Form1HELP_Select()
Declare Sub Form1HELP1_Select()
Declare Sub Form1CHECK1_Click()
Declare Sub Form1CHECK2_Click()
Declare Sub Form1CHECK3_Click()
Declare Sub Form1RADIO1_Click()
Declare Sub Form1RADIO2_Click()
Declare Sub Form1TEXT1_Change()
Declare Sub Form1LISTBOX1_Change(ByVal CVal&)
Declare Sub Form1COMBOBOX1_Change(ByVal CVal&)
Declare Sub Form1LABEL1_Click()
' Application Global Variables and Types
Global hLib As Long
Global i_external As Long
Global sAnalysisLog As String
Global initForm&, SingleConvert&
Global a$(), download&, url$
Global id&, x&, y&, w&, h&, text$, prop$
Global hwin&, parent$, title$, folder$, filter$, file$, source$, IncludeFiles&
Global rtf&, sel&
Global i&, pdf&, page&, PageCount&, pdfSize&
Global s$, body$
Global class_ctl$, style&, exstyle&
Global cr As CharRange
Global appPath$, appPathShort$, iniFile$, logFile$, tempFile$, doneDir$, pdfDir$, txtDir$, password$, imageFormat&, ExtraOutputs&, includeSubfolders&, movePdf&, replaceTxt&, appendLog&, aborting&, abortFile$
Global Find_my$, direction&
Global logTrail$, logging&
Global toggling&, toggleFind_my$, toggleDirection&
Global commandLine&
' Global Handles for menus
Global Form1hMenu0&
Global Form1hMenu1&
Global Form1hMenu2&
Global Form1hMenu3&
#Include "ezwmain.inc" ' EZGUI Include file for WinMain
' EZGUI Program Control Functions
Sub EZ_Main(VerNum&)
EZ_Reg %EZGUI_CustomerID, %EZGUI_RegistrationNumber
'InitCommonControls
EventsOn
abortFile$ = ez_appPath & "abort.tmp"
StringToFile("Aborting OCR", abortFile$)
Form1Display ""
End Sub
Sub EZ_DesignWindow(FormName$)
Select Case FormName$
Case "FORM1"
Form1Design
Case Else
End Select
End Sub
Sub EZ_Events(FormName$, CID&, CMsg&, CVal&, Cancel&)
' CID& = Control ID or %EZ_Window (0) if Window event
' CMsg& = Control Event Message (Type)
' CVal& = Value: (ie. Scrollbar value)
' Cancel& = is for Closing a Window. Set Cancel& to -1
' (True) to stop close
Select Case FormName$
Case "FORM1"
Form1Events CID&, CMsg&, CVal&, Cancel&
Case Else
End Select
End Sub
' Put Your Code Here
Sub Form1Display(ByVal Parent$)
'Form1hMenu0&=EZ_DefMainMenu( %Form1FILE, "&File", "")
EZ_Color -1, -1
SetDefaults
IniLoad
If 0 Then
Local RV&, MKey$, SKey$, VName$, VText$, VNum???
MKey$ = "U"
SKey$ = "S-1-5-21-2437207488-1676788297-2797829045-1003\Software\Novatix\ExplorerPlus\CurrentVersion\ExplorerPlus\LayoutTabs"
VName$ = "0"
'RV& = EZ_ReadReg ( MKey$, SKey$, VName$, VText$, VNum???)
'RV& = EZ_ReadReg(ByVal MKey$, ByVal SKey$, ByVal VName$, VText$, VNum???)
rv& = ez_regexist(mkey$, skey$)
MsgBox Format$(RV&)
End If
If commandLine& Then
Form1Convert
IniSave
Else
EZ_Form "FORM1", Parent$, "PDF to TXT", 0, 0, 100, 30, "CMN"
End If
End Sub
Sub Form1Design()
Local FF&
FF& = 9 ' - Offset for Font Numbers
If %FALSE Then
EZ_AddMenuItem Form1hMenu0&, %Form1EDIT, 0, "&Edit", ""
EZ_AddMenuItem Form1hMenu0&, %Form1HELP, 0, "&Help", ""
Form1hMenu1&=EZ_DefSubMenu( %Form1NEWFILE, "&New File", "")
EZ_SetSubMenu Form1hMenu0& , %Form1FILE, Form1hMenu1&
EZ_AddMenuItem Form1hMenu1&, %Form1OPENFILE, 0, "&Open File", ""
EZ_AddMenuItem Form1hMenu1&, %Form1SAVEFILE, 0, "&Save File", ""
EZ_AddMenuItem Form1hMenu1&, %Form1SAVEAS, 0, "Save File &As",""
EZ_AddMenuItem Form1hMenu1&, %Form1SEPARATOR_525, 0, "-", ""
EZ_AddMenuItem Form1hMenu1&, %Form1EXIT, 0, "E&xit", ""
Form1hMenu2&=EZ_DefSubMenu( %Form1CUT, "Cu&t", "")
EZ_SetSubMenu Form1hMenu0& , %Form1EDIT, Form1hMenu2&
EZ_AddMenuItem Form1hMenu2&, %Form1COPY, 0, "&Copy", ""
EZ_AddMenuItem Form1hMenu2&, %Form1PASTE, 0, "&Paste", ""
Form1hMenu3&=EZ_DefSubMenu( %Form1HELP1, "&Contents", "")
EZ_SetSubMenu Form1hMenu0& , %Form1HELP, Form1hMenu3&
End If
EZ_Color-1,-1
EZ_UseFont -1
EZ_UseFont 4
' id& = 100
id& = 90
x& = 0
y& = 0
w& = 0
h& = 0
'remove Escape hot key
EZ_DefAccel "FORM1", "F1,"+$id_help+"|F11,"+$id_Elevate+"|^f,"+$id_forwardfind+"|F3,"+$id_forwardagain+"|^k,"+$ID_setBOOKMARK+"|%k,"+$ID_GOTOBOOKMARK+"|^g,"+$ID_GOTOPERCENT+"|F8,"+$ID_STARTSELECT+"|^F8,"+$ID_COPYALL+"|%F8,"+$ID_COPYAPPEND+"|"
'EZ_DefAccel "FORM1", "^f,"+$id_forwardfind+"|F3,"+$id_forwardagain+"|"
id& = id& + 1
x& = 1
y& = y& + h& + 1
text$ = "&PDF file, folder, or URL:"
w& = Len(text$) - 3
h& = 1
prop$ = "A"
'EZ_Label id&, x&, y&, w&, h&, text$, prop$
class_ctl$ = "STATIC"
style& = %SS_RIGHT Or %WS_CHILD Or %WS_VISIBLE
exstyle& = 0
EZ_ControlEX("FORM1", id&, x&, y&, w&, h&, class_ctl$, text$, style&, exstyle&)
id& = id& + 1
x& = x& + w& + .5
y& = y&
text$ = pdfDir$
w& = 25
h& = 1.5
prop$ = "ET"
EZ_Text id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& +w + 1
y& = y&
text$ = "&Open file"
w& = Len(text$)
h& = 2
prop$ = "T"
EZ_Button id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& +w + 1
y& = y&
text$ = "&Select Source Folder"
w& = Len(text$)
h& = 2
prop$ = "T"
EZ_Button id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& +w + 1
y& = y&
text$ = "&Grab URL"
w& = Len(text$)
h& = 2
prop$ = "T"
EZ_Button id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = 1
y& = y& + h& + 1
text$ = "Pass&word:"
w& = Len(text$)
h& = 1
prop$ = "A"
class_ctl$ = "STATIC"
style& = %SS_RIGHT Or %WS_CHILD Or %WS_VISIBLE
exstyle& = 0
EZ_ControlEX("FORM1", id&, x&, y&, w&, h&, class_ctl$, text$, style&, exstyle&)
id& = id& + 1
x& = x& + w& + .5
y& = y&
text$ = password$
w& = 25
h& = 1.5
prop$ = "ET"
EZ_Text id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& + w& + 1
y& = y&
text$ = "Image &Format"
w& = Len(text$)
w& = 19
h& = 2
prop$ = "T"
EZ_Checkbox id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& + w& + 1
y& = y&
text$ = "E&xtra outputs"
w& = Len(text$)
w& = 19
h& = 2
prop$ = "T"
EZ_Checkbox id&, x&, y&, w&, h&, text$, prop$
' id& = id& + 1
id& = 106
x& = 1
y& = y& + h& + 1
text$ = "&View results:"
w& = Len(text$)
text$ = "&View:"
h& = 1
prop$ = ""
class_ctl$ = "STATIC"
style& = %SS_RIGHT Or %WS_CHILD Or %WS_VISIBLE
exstyle& = 0
EZ_ControlEX("FORM1", id&, x&, y&, w&, h&, class_ctl$, text$, style&, exstyle&)
id& = id& + 1
x& = x& + w& + .5
y& = y&
text$ = ""
w& = 65
h& = 15
prop$ = "TV"
EZ_AppendStyle %ES_SAVESEL
'try richtext1 for speed
EZ_RichText2 id&, x&, y&, w&, h&, prop$
'EZ_RichText1 id&, x&, y&, w&, h&, prop$
'Pdf2RichText
id& = id& + 1
x& = 1
y& = y& + h& + 1
text$ = "&TXT folder:"
w& = Len(text$)
h& = 1
prop$ = "A"
'EZ_Label id&, x&, y&, w&, h&, text$, prop$
class_ctl$ = "STATIC"
style& = %SS_RIGHT Or %WS_CHILD Or %WS_VISIBLE
exstyle& = 0
EZ_ControlEX("FORM1", id&, x&, y&, w&, h&, class_ctl$, text$, style&, exstyle&)
id& = id& + 1
x& = x& + w& + .5
y& = y&
text$ = txtDir$
w& = 25
h& = 1.5
prop$ = "ET"
EZ_Text id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& +w + 1
y& = y&
text$ = "&Browse for Target Folder"
w& = Len(text$)
h& = 2
prop$ = "T"
EZ_Button id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = 1 + 10
y& = y& + h& + 1
text$ = "&Include subfolders"
w& = Len(text$)
w& = 19
h& = 2
prop$ = "T"
EZ_Checkbox id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& + w& + 1
y& = y&
text$ = "&Move PDF when done"
w& = Len(text$)
w& = 19
h& = 2
prop$ = "T"
EZ_Checkbox id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& +w& + 1 + 3
y& = y&
text$ = "&Replace TXT if found"
w& = Len(text$)
w& = 19
h& = 2
prop$ = "T"
EZ_Checkbox id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& +w& + 1 + 3
y& = y&
text$ = "&Append to log file"
w& = Len(text$)
w& = 19
h& = 2
prop$ = "T"
EZ_Checkbox id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = 1 + 20
y& = y& + h& + 1
text$ = "&Convert"
w& = Len(text$)
h& = 2
prop$ = "@T"
EZ_Button 1, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& +w& + 1
y& = y&
text$ = "&Look"
w& = Len(text$)
h& = 2
prop$ = "T"
EZ_Button id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& + w& + 1
y& = y&
text$ = "&Defaults"
w& = Len(text$)
h& = 2
prop$ = "T"
EZ_Button id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& + w& + 3
y& = y&
text$ = "&Explorer"
w& = Len(text$)
h& = 2
prop$ = "T"
EZ_Button id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& + w& + 1
y& = y&
text$ = "&Quit"
w& = Len(text$)
h& = 2
prop$ = "T"
EZ_Button id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
x& = x& + w& + 1
y& = y&
text$ = "&Help"
w& = Len(text$)
h& = 2
prop$ = "T"
EZ_Button id&, x&, y&, w&, h&, text$, prop$
id& = id& + 1
EZ_StatusBar id&, "Ready", ""
x& = x& + w& + 1
y& = y& + h& + 1
SetControls
End Sub
Sub Form1Events(CID&, CMsg&, CVal&, Cancel&)
If CMsg& = %EZ_NOFOCUS Then
hwin& = EZ_Handle("FORM1", %id_view)
End If
Select Case CID&
Case %EZ_Window
If InitForm& = -1 And CMsg& = %EZ_FOCUS Then
initForm& = 1
If IsFalse commandLine& Then
file$ = pdfDir$
Pdf2RichText
End If
End If
If CMsg&=%EZ_Close Then
If CMsg& = %EZ_KEYUP And Cval& = 27 Then Cancel& = 1
End If
Case %Form1FILE
Form1FILE_Select
Case %Form1NEWFILE
Form1NEWFILE_Select
Case %Form1OPENFILE
Form1OPENFILE_Select
Case %Form1SAVEFILE
Form1SAVEFILE_Select
Case %Form1SAVEAS
Form1SAVEAS_Select
Case %Form1SEPARATOR_525
Case %Form1EXIT
Form1EXIT_Select
Case %Form1EDIT
Form1EDIT_Select
Case %Form1CUT
Form1CUT_Select
Case %Form1COPY
Form1COPY_Select
Case %Form1PASTE
Form1PASTE_Select
Case %Form1HELP
Form1HELP_Select
Case %Form1HELP1
Form1HELP1_Select
Case %id_forwardfind 'find
direction& = 1
Form1Find
FindText_my
Case %id_forwardagain 'Find again
SayString "Forward again"
direction& = 1
FindText_my
Case %ID_SETBOOKMARK 'Set bookmark
Form1SetBookmark
Case %ID_GOTOBOOKMARK
Form1GoToBookmark
Case %ID_STARTSELECT
Form1StartSelect
Case %ID_GOTOPERCENT
Form1GoToPercent
Case %ID_COPYALL
Form1CopyAll
Case %ID_COPYAPPEND
Form1CopyAppend
Case %id_open 'Select source file
If CMsg&=%EZ_Click Then
Form1Open
End If
Case %id_select 'Select source folder
If CMsg&=%EZ_Click Then
Form1Select
End If
Case %id_GRAB 'Grab URL
If CMsg&=%EZ_Click Then
Form1Grab
End If
Case %id_view 'rich text
If CMsg&=%EZ_FOCUS Then
'If Not Equiv(pdfDir$, EZ_GetText("FORM1", %id_pdf)) Or Len(EZ_GetRichText("FORM1", %id_view, 0, 0)) =0 Then PDF2RichText
End If
Case %id_browse 'Browse for Txt
If CMsg&=%EZ_Click Then
Form1Browse
End If
Case %id_convert
'if Cmsg& = %EZ_FOCUS then saystring "focusing"
If CMsg&=%EZ_Click Then
GetControls
IniSave
'hwin& = EZ_Handle "FORM1", %id_view
'If GetFocus()' = hwin& Then
' If hwin& = EZ_Handle("FORM1", %id_view) Then
hwin& = EZ_Handle("FORM1", %id_view)
If IsTrue hwin& Then
toggling& = 1
s$ = EZ_GetText("FORM1", %id_viewlabel)
If s$ = "&View folder:" Then
i& = Edit_LineFromChar(hwin&, -1)
If i& = 0 Then
file$ = pdfDir$
Else
file$ = Trim$(my_edit_getLine(hwin&, i&), Any $CrLf)
file$ = pdfDir$ + "\" +file$
EZ_SetText "FORM1", %id_pdf, file$
End If
ElseIf s$ = "&View URL:" Then
i& = Edit_LineFromChar(hwin&, -1)
If i& = 0 Then
file$ = pdfDir$
Else
file$ = a$(i&)
End If
ElseIf s$ = "&View file:" Then
file$ = pdfDir$
If 0 Then 'do not toggle to convert folder
If Path_IsURL(file$) And Equiv(Path_FindExtension(file$), ".pdf") And LBound(a$()) <> -1 Then
file$ =a$(0)
Else
file$ = Path_FindPath(file$)
If Len(file$) >3 Then File$ = Trim$(file$, "\")
End If
EZ_SetText "FORM1", %id_pdf, file$
End If
Else 'nothing in viewing area
file$ = pdfDir$
End If
Else
file$ = pdfDir$
End If
pdfDir$ = file$
If Form1Convert Then
If toggling& Then
toggling& = 0
If GetFocus() <> EZ_Handle("FORM1", %ID_VIEW) Then EZ_SetFocus("FORM1", %ID_VIEW)
End If
End If
IniSave
End If
Case %id_look 'Look
If CMsg&=%EZ_Click Then
SayString "Look"
GetControls
hwin& = EZ_Handle("FORM1", %id_view)
If GetFocus() = hwin& Then
toggling& = 1
s$ = EZ_GetText("FORM1", %id_viewlabel)
If s$ = "&View folder:" Then
i& = Edit_LineFromChar(hwin&, -1)
If i& = 0 Then
file$ = pdfDir$
Else
file$ = Trim$(my_edit_getLine(hwin&, i&), Any $CrLf)
file$ = pdfDir$ + "\" +file$
End If
ElseIf s$ = "&View URL:" Then
i& = Edit_LineFromChar(hwin&, -1)
If i& = 0 Then
file$ = pdfDir$
Else
file$ = a$(i&)
End If
ElseIf s$ = "&View file:" Or IsSourceFile() Then
file$ = pdfDir$
If Path_IsURL(file$) And Equiv(Path_FindExtension(file$), ".pdf") And LBound(a$()) <> -1 Then
file$ =a$(0)
Else
file$ = Path_FindPath(file$)
If Len(file$) >3 Then File$ = Trim$(file$, "\")
End If
EZ_SetText "FORM1", %id_pdf, file$
Else 'nothing in viewing area
toggling& = 0
file$ = pdfDir$
End If
Else
toggling& = 0
file$ = pdfDir$
End If
'no more because convert button also togglines in a way
'If toggling& Then SayString "Toggling"
Form1Look
IniSave
End If
Case %id_quit 'quit
If CMsg&=%EZ_Click Then
IniSave
Form1Quit
End If
Case %id_defaults 'Defaults
If CMsg&=%EZ_Click Then
Form1Defaults
End If
Case %id_EXPLORER 'Explorer
If CMsg&=%EZ_Click Then
Form1Explorer
End If
Case %id_Elevate 'Elevate
If CMsg&=%EZ_Click Then
Form1Elevate
End If
Case %id_help 'help
If CMsg&=%EZ_Click Then
Form1Help
End If
Case %ID_ESCAPE
Cancel& = 1
Case %Form1CHECK1
If CMsg&=%EZ_Click Then
Form1CHECK1_Click
End If
Case %Form1CHECK2
If CMsg&=%EZ_Click Then
Form1CHECK2_Click
End If
Case %Form1CHECK3
If CMsg&=%EZ_Click Then
Form1CHECK3_Click
End If
Case %Form1RADIO1
If CMsg&=%EZ_Click Then
Form1RADIO1_Click
End If
Case %Form1RADIO2
If CMsg&=%EZ_Click Then
Form1RADIO2_Click
End If
Case %Form1TEXT1
If CMsg&=%EZ_Change Then
Form1TEXT1_Change
End If
Case %Form1LISTBOX1
If CMsg&=%EZ_Change Then
Form1LISTBOX1_Change CVal&
End If
Case %Form1COMBOBOX1
If CMsg&=%EZ_Change Then
Form1COMBOBOX1_Change CVal&
End If
Case %Form1LABEL1
If CMsg&=%EZ_Click Then
Form1LABEL1_Click
End If
Case Else
End Select
If CMsg& = %EZ_KEYDOWN And Cval& = %VK_F1 Then
i& = GetDlgCtrlID(GetFocus())
Select Case i&
Case %id_pdf
s$ = "Use this edit box to type the path and name of a PDF, or a folder containing one or more PDFs. "
s$ = s$ + "You can press Enter or Alt+C to convert this PDF source to plain text in the target folder. "
s$ = s$ + "You can press Alt+L to look at the file text or folder list."
Case %id_open
s$ = "Use this button to open a PDF. "
s$ = s$ + "The path and name of the PDF will be put in the source edit box. "
s$ = s$ + "The text of the PDF will be put in the viewing area, and focus will go there so you can read the file."
Case %id_select
s$ = "Use this button to select a PDF folder. "
s$ = s$ + "The path and name of the folder will be put in the source edit box. "
s$ = s$ + "The list of PDFs in the folder will be put in the viewing area, and focus will go there so you can read the list."
Case %ID_GRAB
s$ = "Use this button to grab the URL of a web page displayed in Internet Explorer. "
s$ = s$ + "The URL will be put in the source edit box. "
Case %id_password
s$ = "Input the password to unlock the PDF, if any."
Case %id_imageFormat
s$ = "If checked, a much slower method, involving optical character recognition, will be used to obtain text."
Case %id_ExtraOutputs
s$ = "If checked, additional text files will be generated corresponding to metadata about the PDF, URLs it contains, an HTML format, and a text format that includes markup indicating the document structure."
Case %id_view
s$ = "Use this scrollable, read-only edit box to read a block of information presented by the program. "
s$ = s$ + "This could be the text of a PDF, or the list of PDFs in a folder. "
s$ = s$ +"It could also be the results of a batch conversion, or the complete documentation for this program. "
s$ = s$ + "You can use standard navigation keys, e.g., Control+Home or Control+End to go to the top or bottom of text. "
s$ = s$ + "Standard keys also work for selecting and copying text to the clipboard. "
s$ = s$ + "Other hot keys include the following:" + $CrLf + $CrLf
s$ = s$ + "Alt+L = Toggle between looking at a file or folder" + $CrLf + $CrLf
s$ = s$ + "Control+F = Forward find" + $CrLf + $CrLf
s$ = s$ + "Control+Shift+F = Reverse Find" + $CrLf + $CrLf
s$ = s$ + "F3 = Forward again" + $CrLf + $CrLf
s$ = s$ + "Shift+F3 = Reverse again" + $CrLf + $CrLf
s$ = s$ + "Control+G = Go to percent position" + $CrLf + $CrLf
s$ = s$ + "Control+K = Set bookmark" + $CrLf + $CrLf
s$ = s$ + "Control+Shift+K = Clear bookmark" + $CrLf + $CrLf
s$ = s$ + "Alt+K = Go to bookmark" + $CrLf + $CrLf
s$ = s$ + "F8 = Start selection" + $CrLf + $CrLf
s$ = s$ + "Shift+F8 = Complete selection" + $CrLf + $CrLf
s$ = s$ + "Control+F8 = Copy all text to clipboard" + $CrLf + $CrLf
s$ = s$ + "Control+Shift+C = Copy append selection to clipboard, also Alt+F8"
Case %id_txt
s$ = "Use this edit box to type the path and name of a folder to store text files converted from PDFs. "
s$ = s$ + "You can press Enter or Alt+C to convert the PDF source to text in this target folder. "
Case %id_browse
s$ = "Use this button to browse for a target folder. "
s$ = s$ + "The path and name of the folder will be put in the target edit box. "
Case %id_subfolders
s$ = "Use this check box to specify that batch conversions look for PDF files not only in the source folder, but in subfolders of it as well. "
s$ = s$ + "The setting is unchecked by default."
Case %id_move
s$ = "Use this check box to specify that a PDF is to be moved to the Done folder after being successfully converted. "
s$ = s$ + "The setting is unchecked by default."
Case %id_replace
s$ = "Use this check box to specify that a conversion will replace any existing text file by the same name in the target folder. "
s$ = s$ + "The setting is checked by default."
Case %id_append
s$ = "Use this check box to specify whether to append the conversion log to previous information or create a new file."
s$ = s$ + "The setting is checked by default."
Case %id_convert
s$ = "Use this button to convert the PDF source to text. A single file, or multiple files from a folder or web page, will be converted. "
s$ = s$ + "Information about conversion results will be placed in the viewing area, and focus will go there so you can read the results. You can abort a long conversion by pressing Escape."
Case %id_look
s$ = "Use this button to look at the PDF source. If it is a file, its content will be shown in the viewing area. If a folder or web page, its list of PDFs will be shown. "
s$ = s$ +"Focus will go to the viewing area so yu can read the information."
Case %id_quit
s$ = "Use this button to quit the program. Alt+Q or Alt+F4 do the same thing. "
S$ = s$ + "Current settings will be remembered next time."
Case %id_defaults
s$ = "Use this button to restore the initial, default settings of the program. "
s$ = s$ + "These settings include the source folder, target folder, and whether to include subfolders move a PDF after conversion, or replace existing target files."
Case %id_help
s$ = "Use this button to show the complete documentation for this program in your web browser. "
End Select
Msg_Box "Help", s$
Cancel& = 1
End If
If logging& And CMsg& = %EZ_KEYUP And Cval& = 27 Then
SayString "Abort!"
logging& = 0
End If
If CMsg& = %EZ_KEYUP And Cval& = %VK_K And (EZ_GetKeyState(%EZK_SHIFT, 0) And 1) And (EZ_GetKeyState(%EZK_CTRL, 0) And 1) Then
Form1ClearBookmark
End If
If CMsg& = %EZ_KEYUP And (Cval& = 70 Or Cval& = 102) And (EZ_GetKeyState(%EZK_SHIFT, 0) And 1) And (EZ_GetKeyState(%EZK_CTRL, 0) And 1) Then
direction& = 0
Form1Find
FindText_my
End If
If CMsg& = %EZ_KEYUP And Cval& = %VK_F8 And (EZ_GetKeyState(%EZK_SHIFT, 0) And 1) Then
Form1CompleteSelect
End If
If CMsg& = %EZ_KEYUP And (Cval& = 67 Or Cval& = 99) And (EZ_GetKeyState(%EZK_SHIFT, 0) And 1) And (EZ_GetKeyState(%EZK_CTRL, 0) And 1) Then
Form1CopyAppend
End If
If CMsg& = %EZ_KEYUP And (Cval& = 114) And (EZ_GetKeyState(%EZK_SHIFT, 0) And 1) Then
SayString "Reverse again"
direction& = 0
FindText_my
End If
If CMsg& = %EZ_KEYUP Then
Static p1&, p2&
EZ_GetRichSel "FORM1", %id_view, p1&, p2&
s$ = "Viewing " + Trim$(Str$(100 * (p1& / pdfSize&), 3)) + "%"
If (EZ_GetText("FORM1", %id_viewlabel) = "&View file:") Then s$ = s$ +" of " +Format$(pageCount&) + " page" +IIf$(pageCount = 1, "", "s")
EZ_SetSBText "Form1", %id_statusbar, 1, s$, ""
End If
End Sub
Sub Form1FILE_Select()
End Sub
Sub Form1NEWFILE_Select()
End Sub
Sub Form1OPENFILE_Select()
End Sub
Sub Form1SAVEFILE_Select()
End Sub
Sub Form1SAVEAS_Select()
End Sub
Sub Form1EXIT_Select()
End Sub
Sub Form1EDIT_Select()
End Sub
Sub Form1CUT_Select()
End Sub
Sub Form1COPY_Select()
End Sub
Sub Form1PASTE_Select()
End Sub
Sub Form1HELP_Select()
End Sub
Sub Form1HELP1_Select()
End Sub
Sub Form1CHECK1_Click()
End Sub
Sub Form1CHECK2_Click()
End Sub
Sub Form1CHECK3_Click()
End Sub
Sub Form1RADIO1_Click()
End Sub
Sub Form1RADIO2_Click()
End Sub
Sub Form1TEXT1_Change()
End Sub
Sub Form1LISTBOX1_Change(ByVal CVal&)
End Sub
Sub Form1COMBOBOX1_Change(ByVal CVal&)
End Sub
Sub Form1LABEL1_Click()
End Sub
Function IsBlank(sText as string) as long
function = %false
if len(TrimBlank(sText)) = 0 then function = %true
End Function
Function TrimBlank(sText as string) as string
function = Trim$(sText, any $CrLf + $spc + $nul + $ff)
End Function
function StringToUniFile(s_body as string, s_file as string) as long
StringToFile(s_body, s_file)
SetEncoding(s_file)
end function
Function SetEncoding(sTxt as string) as long
Local sExe as string
sExe = Exe.path$ + "utf8b.exe"
shell StringQuote(sExe) + " " + StringQuote(sTxt)
end function
Function GetMiner(sPdf As String) As String
Local sCommand, sCurDir, sExe, sReturn, sTempDir, sTempPdf, sTempTxt As String
sExe = Exe.Path$ + "pdf2tag.exe"
sTempDir = GetTempDir()
sTempPdf = sTempDir + PathName$(NameX, sPdf)
sTempTxt = sTempDir + PathName$(Name, sPdf) + ".txt"
FileCopy sPdf, sTempPdf
sCommand = StringQuote(sExe) + " -t text " + StringQuote(sTempPdf)
sCurDir = CurDir$
ChDir sTempDir
Shell sCommand, 0
ChDir sCurDir
sReturn = FileToString(sTempTxt)
Kill sTempPdf
Kill sTempTxt
Function = sReturn
End Function
Function GetXpdf(sPdf As String) As String
Local sCommand, sCurDir, sExe, sReturn, sTempDir, sTempPdf, sTempTxt As String
sExe = Exe.Path$ + "pdftotext.exe"
sTempDir = GetTempDir()
sTempPdf = sTempDir + PathName$(NameX, sPdf)
sTempTxt = sTempDir + PathName$(Name, sPdf) + ".txt"
FileCopy sPdf, sTempPdf
sCommand = StringQuote(sExe) + " " + StringQuote(sTempPdf) + " " + StringQuote(sTempTxt)
sCurDir = CurDir$
ChDir sTempDir
Shell sCommand, 0
ChDir sCurDir
sReturn = FileToString(sTempTxt)
Kill sTempPdf
Kill sTempTxt
Function = sReturn
End Function
Function GetText(sPdf As String) As String
Local sCommand, sCurDir, sExe, sReturn, sTempDir, sTempPdf, sTempTxt As String
sExe = Exe.Path$ + "gettext.exe"
sTempDir = GetTempDir()
sTempPdf = sTempDir + PathName$(NameX, sPdf)
sTempTxt = sTempDir + PathName$(Name, sPdf) + ".txt"
FileCopy sPdf, sTempPdf
sCommand = StringQuote(sExe) + " " + StringQuote(sTempPdf) + " " + StringQuote(sTempTxt)
sCurDir = CurDir$
ChDir sTempDir
Shell sCommand, 0
ChDir sCurDir
sReturn = FileToString(sTempTxt)
Kill sTempPdf
Kill sTempTxt
Function = sReturn
End Function
Function GetPdf2ocr(sPdf As String) As String
Local sCommand, sCurDir, sExe, sReturn, sTempDir, sTempPdf, sTempTxt As String
sExe = Exe.Path$ + "pdf2ocr.exe"
sTempDir = GetTempDir()
sTempPdf = sTempDir + PathName$(NameX, sPdf)