8
8
9
9
namespace taskt . Core . Automation . Commands
10
10
{
11
- [ Serializable ]
11
+ [ Serializable ]
12
12
[ Attributes . ClassAttributes . Group ( "Data Commands" ) ]
13
13
[ Attributes . ClassAttributes . Description ( "" ) ]
14
14
[ Attributes . ClassAttributes . UsesDescription ( "" ) ]
15
15
[ Attributes . ClassAttributes . ImplementationDescription ( "" ) ]
16
16
public class PDFTextExtractionCommand : ScriptCommand
17
17
{
18
18
[ XmlAttribute ]
19
- [ Attributes . PropertyAttributes . PropertyDescription ( "Please indicate the PDF file path" ) ]
19
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Please indicate the PDF file path or PDF file URL " ) ]
20
20
[ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowFileSelectionHelper ) ]
21
- [ Attributes . PropertyAttributes . InputSpecification ( "Enter or Select the path to the applicable file." ) ]
22
- [ Attributes . PropertyAttributes . SampleUsage ( @"C:\temp\myfile.pdf or [vFilePath]" ) ]
21
+ [ Attributes . PropertyAttributes . InputSpecification ( "Enter or Select the path to the applicable file or enter file URL ." ) ]
22
+ [ Attributes . PropertyAttributes . SampleUsage ( @"C:\temp\myfile.pdf , [vFilePath] or https://temp.com/myfile.pdf " ) ]
23
23
[ Attributes . PropertyAttributes . Remarks ( "" ) ]
24
24
public string v_FilePath { get ; set ; }
25
25
26
+ [ XmlAttribute ]
27
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Please select source type of PDF file" ) ]
28
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "File Path" ) ]
29
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "File URL" ) ]
30
+ [ Attributes . PropertyAttributes . InputSpecification ( "Select source type of PDF file" ) ]
31
+ [ Attributes . PropertyAttributes . SampleUsage ( "Select **File Path**, **File URL**" ) ]
32
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
33
+ public string v_FileSourceType { get ; set ; }
34
+
26
35
[ XmlAttribute ]
27
36
[ Attributes . PropertyAttributes . PropertyDescription ( "Please select the variable to receive the PDF text" ) ]
28
37
[ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
@@ -42,10 +51,44 @@ public PDFTextExtractionCommand()
42
51
public override void RunCommand ( object sender )
43
52
{
44
53
45
- //get variable path to source file
54
+ //get variable path or URL to source file
46
55
var vSourceFilePath = v_FilePath . ConvertToUserVariable ( sender ) ;
56
+ // get source type of file either from a physical file or from a URL
57
+ var vSourceFileType = v_FileSourceType . ConvertToUserVariable ( sender ) ;
47
58
59
+ if ( vSourceFileType == "File URL" )
60
+ {
61
+ //create temp directory
62
+ var tempDir = Core . IO . Folders . GetFolder ( Folders . FolderType . TempFolder ) ;
63
+ var tempFile = System . IO . Path . Combine ( tempDir , $ "{ Guid . NewGuid ( ) } .pdf") ;
64
+
65
+ //check if directory does not exist then create directory
66
+ if ( ! System . IO . Directory . Exists ( tempDir ) )
67
+ {
68
+ System . IO . Directory . CreateDirectory ( tempDir ) ;
69
+ }
70
+
71
+ // Create webClient to download the file for extraction
72
+ var webclient = new System . Net . WebClient ( ) ;
73
+ var uri = new Uri ( vSourceFilePath ) ;
74
+ webclient . DownloadFile ( uri , tempFile ) ;
75
+
76
+ // check if file is downloaded successfully
77
+ if ( System . IO . File . Exists ( tempFile ) )
78
+ {
79
+ vSourceFilePath = tempFile ;
80
+ }
81
+
82
+ // Free not needed resources
83
+ uri = null ;
84
+ if ( webclient != null )
85
+ {
86
+ webclient . Dispose ( ) ;
87
+ webclient = null ;
88
+ }
89
+ }
48
90
91
+ // Check if file exists before proceeding
49
92
if ( ! System . IO . File . Exists ( vSourceFilePath ) )
50
93
{
51
94
throw new System . IO . FileNotFoundException ( "Could not find file: " + vSourceFilePath ) ;
@@ -68,6 +111,8 @@ public override List<Control> Render(frmCommandEditor editor)
68
111
base . Render ( editor ) ;
69
112
70
113
//create standard group controls
114
+ RenderedControls . AddRange ( CommandControls . CreateDefaultDropdownGroupFor ( "v_FileSourceType" , this , editor ) ) ;
115
+
71
116
RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_FilePath" , this , editor ) ) ;
72
117
73
118
0 commit comments