|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the Apache 2.0 License |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | +// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone |
| 5 | + |
| 6 | +namespace BootstrapBlazor.Server.Components.Samples; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Html2Image 组件 |
| 10 | +/// </summary> |
| 11 | +public partial class Html2Images |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// 获得 IconTheme 实例 |
| 15 | + /// </summary> |
| 16 | + [Inject] |
| 17 | + [NotNull] |
| 18 | + private IIconTheme? IconTheme { get; set; } |
| 19 | + |
| 20 | + [Inject] |
| 21 | + [NotNull] |
| 22 | + private IStringLocalizer<Foo>? LocalizerFoo { get; set; } |
| 23 | + |
| 24 | + [Inject] |
| 25 | + [NotNull] |
| 26 | + private IHtml2Image? Html2ImageService { get; set; } |
| 27 | + |
| 28 | + [Inject] |
| 29 | + [NotNull] |
| 30 | + private IStringLocalizer<Html2Pdfs>? Localizer { get; set; } |
| 31 | + |
| 32 | + [Inject] |
| 33 | + [NotNull] |
| 34 | + private NavigationManager? NavigationManager { get; set; } |
| 35 | + |
| 36 | + [NotNull] |
| 37 | + private List<Foo>? Items { get; set; } |
| 38 | + |
| 39 | + private string? _exportIcon = ""; |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// <inheritdoc/> |
| 43 | + /// </summary> |
| 44 | + protected override void OnInitialized() |
| 45 | + { |
| 46 | + base.OnInitialized(); |
| 47 | + |
| 48 | + Items = Foo.GenerateFoo(LocalizerFoo); |
| 49 | + |
| 50 | + _exportIcon = IconTheme.GetIconByKey(ComponentIcons.TableExportPdfIcon); |
| 51 | + } |
| 52 | + private async Task OnExportAsync() |
| 53 | + { |
| 54 | + var stream = await Html2ImageService.GetStreamAsync("#table-9527", new Html2ImageOptions() |
| 55 | + { |
| 56 | + //IncludeStyleProperties = [ |
| 57 | + // $"{NavigationManager.BaseUri}_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css", |
| 58 | + // $"{NavigationManager.BaseUri}_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css", |
| 59 | + // $"{NavigationManager.BaseUri}BootstrapBlazor.Server.styles.css", |
| 60 | + // $"{NavigationManager.BaseUri}css/site.css" |
| 61 | + //] |
| 62 | + }); |
| 63 | + if (stream != null) |
| 64 | + { |
| 65 | + var reader = new StreamReader(stream); |
| 66 | + var data = await reader.ReadToEndAsync(); |
| 67 | + reader.Close(); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments