@@ -39,7 +39,7 @@ public PDFtk(PDFtkOptions options)
39
39
{
40
40
var key = "NumberOfPages: " ;
41
41
var line = executeProcessResult . StandardOutput
42
- . Split ( Environment . NewLine )
42
+ . Split ( new [ ] { Environment . NewLine } , StringSplitOptions . None )
43
43
. Single ( x => x . StartsWith ( key ) ) ;
44
44
45
45
pages = int . Parse ( line . Substring ( key . Length ) ) ;
@@ -103,8 +103,8 @@ public async Task<IPDFtkResult<IDataField[]>> GetDataFieldsAsync(string filePath
103
103
if ( executeProcessResult . Success )
104
104
{
105
105
dataFields = executeProcessResult . StandardOutput
106
- . Split ( "---" + Environment . NewLine , StringSplitOptions . RemoveEmptyEntries )
107
- . Select ( x => x . Split ( Environment . NewLine , StringSplitOptions . RemoveEmptyEntries ) )
106
+ . Split ( new [ ] { "---" + Environment . NewLine } , StringSplitOptions . RemoveEmptyEntries )
107
+ . Select ( x => x . Split ( new [ ] { Environment . NewLine } , StringSplitOptions . RemoveEmptyEntries ) )
108
108
. Select ( DataField . Parse )
109
109
. ToArray ( ) ;
110
110
}
@@ -190,7 +190,13 @@ private static async Task<IPDFtkResult<byte[]>> ResolveSingleFileExecutionResult
190
190
var bytes = Array . Empty < byte > ( ) ;
191
191
if ( executeProcessResult . Success )
192
192
{
193
+ #if NETSTANDARD2_0
194
+ bytes = File . ReadAllBytes ( outputFile . TempFileName ) ;
195
+ await Task . CompletedTask ;
196
+
197
+ #else
193
198
bytes = await File . ReadAllBytesAsync ( outputFile . TempFileName ) ;
199
+ #endif
194
200
}
195
201
196
202
return new PDFtkResult < byte [ ] > ( executeProcessResult , bytes ) ;
@@ -206,13 +212,19 @@ private static async Task<IPDFtkResult<IReadOnlyCollection<KeyValuePair<string,
206
212
var outputFiles = Directory . GetFiles ( outputDirectory . TempDirectoryFullName , searchPattern ) ;
207
213
foreach ( var outputFile in outputFiles )
208
214
{
215
+ #if NETSTANDARD2_0
216
+ var bytes = File . ReadAllBytes ( outputFile ) ;
217
+ await Task . CompletedTask ;
218
+ #else
209
219
var bytes = await File . ReadAllBytesAsync ( outputFile ) ;
220
+ #endif
210
221
var fileName = Path . GetFileName ( outputFile ) ;
211
- outputFileBytes . Add ( KeyValuePair . Create ( fileName , bytes ) ) ;
222
+ outputFileBytes . Add ( new KeyValuePair < string , byte [ ] > ( fileName , bytes ) ) ;
212
223
}
213
224
}
214
225
215
- return new PDFtkResult < IReadOnlyCollection < KeyValuePair < string , byte [ ] > > > ( executeProcessResult , outputFileBytes . AsReadOnly ( ) ) ;
226
+ return new PDFtkResult < IReadOnlyCollection < KeyValuePair < string , byte [ ] > > > ( executeProcessResult ,
227
+ outputFileBytes . AsReadOnly ( ) ) ;
216
228
}
217
229
218
230
/// <inheritdoc/>
@@ -272,10 +284,11 @@ public async Task<IPDFtkResult<IReadOnlyCollection<KeyValuePair<string, byte[]>>
272
284
273
285
return await ResolveSingleDirectoryExecutionResultAsync ( executeProcessResult , outputDirectory , "*" ) ;
274
286
}
275
-
276
-
287
+
288
+
277
289
/// <inheritdoc/>
278
- public async Task < IPDFtkResult < byte [ ] > > AttachFiles ( string pdfFilePath , IEnumerable < string > files , int ? page = null )
290
+ public async Task < IPDFtkResult < byte [ ] > > AttachFiles ( string pdfFilePath , IEnumerable < string > files ,
291
+ int ? page = null )
279
292
{
280
293
using var outputFile = TempPDFtkFile . Create ( ) ;
281
294
var args = new List < string > ( 7 )
@@ -290,7 +303,7 @@ public async Task<IPDFtkResult<byte[]>> AttachFiles(string pdfFilePath, IEnumera
290
303
args . Add ( "to_page" ) ;
291
304
args . Add ( p . ToString ( ) ) ;
292
305
}
293
-
306
+
294
307
args . Add ( "output" ) ;
295
308
args . Add ( outputFile . TempFileName ) ;
296
309
var executeProcessResult = await _pdftkProcess . ExecuteAsync ( args . ToArray ( ) ) ;
0 commit comments