Hi,
I used html converter to convert a url to pdf and saved it in my root directory..
if (args.Item.Text == "PDF")
{
//Code for editing - Check that an Order has been selected from the grid
if (selectedPOHeaderID == 0)
{
WarningHeaderMessage = "Warning!";
WarningContentMessage = "Please select an Order from the grid.";
Warning.OpenDialog();
return;
}
//Initialize the HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @$"{Environment.CurrentDirectory}/QtBinariesDotNetCore/";
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://localhost:5001/previeworder/" + selectedPOHeaderGuid);
FileStream fileStream = new FileStream(@$"wwwroot/Files/" + selectedPOHeaderCustomerName + "-OrderNum" + selectedPOHeaderOrderNumber + ".pdf", FileMode.Create, FileAccess.Write);
//Save and close the PDF document
document.Save(fileStream);
document.Close(true);
}
But i'd like the pdf saved in my root directory downloaded automatically if i'm the app is used on mobile or pc with a web browser.
Can you kindly assist with a code to add at the end of the the above code to download any pdf document after its saved ?
Thank you.
hi
Gowthamraj Kumar
i'll look into that. Thanks.
hi
Gowthamraj Kumar
Everything is going great. thanks
i'm able to save the pdf file in my root as well download on my browser.
thanks for providing the link and sample
Hi I'm trying to use the same solution but on a WASM hosted project,
I have the ExportService and FileUtil class in my client service folder
I as well have the javascript In my index.html
when i run the project, i get error:
Exception: Value cannot be null. (Parameter 'uriString')
it comes when the code runs to this line of code:
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
what does that error means and what am i missing?
Thanks for the update.
Our HTML to PDF converter is only supported on the Blazor server side, currently, it is not supported in Blazor WASM. So, kindly try the conversion with Blazor server side application.
Please refer to the below documentation details:
https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/blazor