@@ -78,14 +78,16 @@ protected override async Task ProcessRecordAsync()
7878 {
7979 string html = Content ;
8080
81+ string ? filePath = null ;
8182 if ( ParameterSetName == ParameterSetNames . File )
8283 {
83- if ( ! File . Exists ( FilePath ) )
84+ filePath = GetUnresolvedProviderPathFromPSPath ( FilePath ) ;
85+ if ( ! File . Exists ( filePath ) )
8486 {
85- WriteWarning ( $ "File '{ FilePath } ' doesn't exist.") ;
87+ WriteWarning ( $ "File '{ filePath } ' doesn't exist.") ;
8688 return ;
8789 }
88- html = File . ReadAllText ( FilePath ) ;
90+ html = File . ReadAllText ( filePath ) ;
8991 }
9092 else if ( ParameterSetName == ParameterSetNames . Uri )
9193 {
@@ -106,27 +108,30 @@ protected override async Task ProcessRecordAsync()
106108 return ;
107109 }
108110
109- if ( File . Exists ( OutputFilePath ) && ! Force . IsPresent )
111+ var outputFilePath = GetUnresolvedProviderPathFromPSPath ( OutputFilePath ) ;
112+
113+ if ( File . Exists ( outputFilePath ) && ! Force . IsPresent )
110114 {
111- WriteWarning ( $ "File '{ OutputFilePath } ' already exists. Use -Force to overwrite.") ;
115+ WriteWarning ( $ "File '{ outputFilePath } ' already exists. Use -Force to overwrite.") ;
112116 return ;
113117 }
114118
115- if ( ! ShouldProcess ( OutputFilePath , "Convert HTML to PDF" ) )
119+ if ( ! ShouldProcess ( outputFilePath , "Convert HTML to PDF" ) )
116120 {
117121 return ;
118122 }
119123
120124 try
121125 {
122- if ( CssFilePath != null && CssFilePath . Length > 0 )
126+ var cssFiles = CssFilePath ? . Select ( p => GetUnresolvedProviderPathFromPSPath ( p ) ) . ToArray ( ) ;
127+ if ( cssFiles != null && cssFiles . Length > 0 )
123128 {
124129 var cssContent = new StringBuilder ( ) ;
125- foreach ( var css in CssFilePath . Where ( File . Exists ) )
130+ foreach ( var css in cssFiles . Where ( File . Exists ) )
126131 {
127132 cssContent . AppendLine ( File . ReadAllText ( css ) ) ;
128133 }
129- foreach ( var missing in CssFilePath . Where ( p => ! File . Exists ( p ) ) )
134+ foreach ( var missing in cssFiles . Where ( p => ! File . Exists ( p ) ) )
130135 {
131136 WriteWarning ( $ "CSS file '{ missing } ' doesn't exist.") ;
132137 }
@@ -140,26 +145,27 @@ protected override async Task ProcessRecordAsync()
140145 }
141146 }
142147
143- using var fs = new FileStream ( OutputFilePath , FileMode . Create , FileAccess . Write ) ;
148+ using var fs = new FileStream ( outputFilePath , FileMode . Create , FileAccess . Write ) ;
144149 var properties = new iText . Html2pdf . ConverterProperties ( ) ;
145- if ( ! string . IsNullOrEmpty ( BaseUri ) )
150+ var baseUri = ! string . IsNullOrEmpty ( BaseUri ) ? GetUnresolvedProviderPathFromPSPath ( BaseUri ) : null ;
151+ if ( ! string . IsNullOrEmpty ( baseUri ) )
146152 {
147- properties . SetBaseUri ( BaseUri ) ;
153+ properties . SetBaseUri ( baseUri ) ;
148154 }
149155 iText . Html2pdf . HtmlConverter . ConvertToPdf ( html , fs , properties ) ;
150156 if ( Open . IsPresent )
151157 {
152158 var psi = new System . Diagnostics . ProcessStartInfo
153159 {
154- FileName = OutputFilePath ,
160+ FileName = outputFilePath ,
155161 UseShellExecute = true ,
156162 } ;
157163 System . Diagnostics . Process . Start ( psi ) ;
158164 }
159165
160- if ( ShouldProcess ( OutputFilePath , "Write output" ) )
166+ if ( ShouldProcess ( outputFilePath , "Write output" ) )
161167 {
162- WriteObject ( OutputFilePath ) ;
168+ WriteObject ( outputFilePath ) ;
163169 }
164170 }
165171 catch ( Exception ex )
0 commit comments