11using Gotenberg . Sharp . API . Client ;
22using Gotenberg . Sharp . API . Client . Domain . Builders ;
3- using Gotenberg . Sharp . API . Client . Domain . Builders . Faceted ;
43using Gotenberg . Sharp . API . Client . Domain . Settings ;
54using Gotenberg . Sharp . API . Client . Infrastructure . Pipeline ;
5+
66using Microsoft . Extensions . Configuration ;
77
88var config = new ConfigurationBuilder ( )
@@ -30,15 +30,16 @@ static async Task<string> CreateFromHtml(string destinationDirectory, string res
3030
3131 using var httpClient = new HttpClient ( authHandler ?? ( HttpMessageHandler ) handler )
3232 {
33- BaseAddress = options . ServiceUrl
33+ BaseAddress = options . ServiceUrl ,
34+ Timeout = options . TimeOut
3435 } ;
3536
3637 var sharpClient = new GotenbergSharpClient ( httpClient ) ;
3738
3839 var builder = new HtmlRequestBuilder ( )
39- . AddAsyncDocument ( async doc =>
40+ . AddAsyncDocument ( async doc =>
4041 doc . SetBody ( await GetHtmlFile ( resourcePath , "body.html" ) )
41- . SetFooter ( await GetHtmlFile ( resourcePath , "footer.html" ) )
42+ . SetFooter ( await GetHtmlFile ( resourcePath , "footer.html" ) )
4243 ) . WithPageProperties ( dims => dims . UseChromeDefaults ( ) )
4344 . WithAsyncAssets ( async assets =>
4445 assets . AddItem ( "ear-on-beach.jpg" , await GetImageBytes ( resourcePath ) )
@@ -53,10 +54,8 @@ static async Task<string> CreateFromHtml(string destinationDirectory, string res
5354 var resultPath = Path . Combine ( destinationDirectory , $ "GotenbergFromHtml-{ DateTime . Now : yyyyMMddHHmmss} .pdf") ;
5455 var response = await sharpClient . HtmlToPdfAsync ( request ) ;
5556
56- using ( var destinationStream = File . Create ( resultPath ) )
57- {
58- await response . CopyToAsync ( destinationStream , CancellationToken . None ) ;
59- }
57+ await using var destinationStream = File . Create ( resultPath ) ;
58+ await response . CopyToAsync ( destinationStream , CancellationToken . None ) ;
6059
6160 return resultPath ;
6261}
@@ -69,4 +68,4 @@ static Task<byte[]> GetImageBytes(string resourcePath)
6968static Task < byte [ ] > GetHtmlFile ( string resourcePath , string fileName )
7069{
7170 return File . ReadAllBytesAsync ( Path . Combine ( resourcePath , fileName ) ) ;
72- }
71+ }
0 commit comments