File tree Expand file tree Collapse file tree
src/components/BootstrapBlazor.PdfViewer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,7 +39,10 @@ public partial class PdfViewer
3939 /// Gets or sets whether to use Google Docs for PDF rendering. Default is false.
4040 /// </summary>
4141 [ Parameter ]
42- public bool UseGoogleDocs { get ; set ; } = false ;
42+ public bool UseGoogleDocs { get ; set ; }
43+
44+ [ Inject , NotNull ]
45+ private NavigationManager ? NavigationManager { get ; set ; }
4346
4447 private string ? ClassString => CssBuilder . Default ( "bb-pdf-viewer-container" )
4548 . AddClassFromAttributes ( AdditionalAttributes )
@@ -85,7 +88,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
8588
8689 if ( rerender )
8790 {
88- await InvokeVoidAsync ( "loadPdf" , Id , _url ) ;
91+ await InvokeVoidAsync ( "loadPdf" , Id , GetAbsoluteUri ( _url ) ) ;
8992 }
9093 }
9194
@@ -97,9 +100,20 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
97100 {
98101 LoadedCallaback = nameof ( TriggerOnLoaded ) ,
99102 NotSupportCallback = nameof ( TriggerNotSupportCallback ) ,
100- Url
103+ Url = GetAbsoluteUri ( Url )
101104 } ) ;
102105
106+ private string GetAbsoluteUri ( string ? url )
107+ {
108+ url ??= string . Empty ;
109+ if ( string . IsNullOrEmpty ( url ) || ! UseGoogleDocs )
110+ {
111+ return url ;
112+ }
113+ var uri = NavigationManager . ToAbsoluteUri ( url ) ;
114+ return uri . AbsoluteUri ;
115+ }
116+
103117 /// <summary>
104118 /// Trigger OnLoaded callback when the PDF document is loaded.
105119 /// </summary>
You can’t perform that action at this time.
0 commit comments