Skip to content

Commit 268ec00

Browse files
committed
840386- Need to add the explanation for each step and update the sample
1 parent 094b5c9 commit 268ec00

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Blazor/HTML_to_PDF_Blazor/Data/ExportService.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@ namespace HTML_to_PDF_Blazor.Data
1010
{
1111
public class ExportService
1212
{
13-
public MemoryStream CreatePdf()
13+
public MemoryStream CreatePdf(string url)
1414
{
1515
//Initialize HTML to PDF converter.
1616
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
17-
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
18-
//Set Blink viewport size.
19-
blinkConverterSettings.ViewPortSize = new Syncfusion.Drawing.Size(1280, 0);
20-
//Assign Blink converter settings to HTML converter.
21-
htmlConverter.ConverterSettings = blinkConverterSettings;
2217
//Convert URL to PDF document.
23-
PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com");
18+
PdfDocument document = htmlConverter.Convert(url);
2419
//Create memory stream.
2520
MemoryStream stream = new MemoryStream();
2621
//Save the document to memory stream.

Blazor/HTML_to_PDF_Blazor/HTML_to_PDF_Blazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Windows" Version="20.3.0.58" />
8+
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Windows" Version="22.2.5" />
99
</ItemGroup>
1010

1111
</Project>

Blazor/HTML_to_PDF_Blazor/Pages/FetchData.razor

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,33 @@
44
@inject WeatherForecastService ForecastService
55
@inject ExportService exportService
66
@inject Microsoft.JSInterop.IJSRuntime JS
7+
@inject NavigationManager NavigationManager
78
@using System.IO;
89
<h1>Weather forecast</h1>
910

1011
<p>This component demonstrates fetching data from a service.</p>
1112

1213
<button class="btn btn-primary" @onclick="@ExportToPdf">Export to PDF</button>
1314

15+
@code {
16+
private string currentUrl;
17+
/// <summary>
18+
/// Get the current URL
19+
/// </summary>
20+
protected override void OnInitialized()
21+
{
22+
currentUrl = NavigationManager.Uri;
23+
}
24+
}
1425
@functions
1526
{
16-
27+
/// <summary>
28+
/// Create and download the PDF document
29+
/// </summary>
1730
protected async Task ExportToPdf()
1831
{
1932
ExportService exportService = new ExportService();
20-
using (MemoryStream excelStream = exportService.CreatePdf())
33+
using (MemoryStream excelStream = exportService.CreatePdf(currentUrl))
2134
{
2235
await JS.SaveAs("HTML-to-PDF.pdf", excelStream.ToArray());
2336
}

0 commit comments

Comments
 (0)