File tree Expand file tree Collapse file tree 3 files changed +18
-10
lines changed
Blazor/HTML_to_PDF_Blazor Expand file tree Collapse file tree 3 files changed +18
-10
lines changed Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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 }
You can’t perform that action at this time.
0 commit comments