Download PDF from root without using PDF Viewer

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.


7 Replies 1 reply marked as answer

GK Gowthamraj Kumar Syncfusion Team November 26, 2021 11:06 AM UTC

Hi Boot, 
 
Thank you for your patience.  
 
We  can download the converted document from web browser by using JS script in Blazor application. We have created the sample to download the Html converted PDF document after its saved in a specific root location and download the same file from web browser. We have attached the sample for your reference, kindly try the below sample on your end and let us know the result.  
 
Note: If you want to download the file from specific folder in web browser, it was controlled by the browser setting and the created PDF document was always saved in the download folder. Due to security purposes, we cannot change the saving path from the code snippet. So, we request you to change the specific folder on browser setting, Kindly refer the below link to get the more details, https://support.google.com/chrome/answer/95759

 
Please let us know if you need any further assistance in this. 

Regards, 
Gowthamraj K 


Marked as answer

BD Boot Dat replied to Gowthamraj Kumar November 26, 2021 01:10 PM UTC

hi  Gowthamraj Kumar

i'll look into that. Thanks.



GK Gowthamraj Kumar Syncfusion Team November 26, 2021 01:39 PM UTC

Hi Boot,

Thank you for your update. We will wait to hear from you.

Please follow the below steps to run the sample, 

  • Extract and run the attached sample.
  • Go to Fetch data tab on left side panel
  • Click the Export to PDF button to generate the pdf files.

Regards, 
Gowthamraj K 



BD Boot Dat replied to Gowthamraj Kumar November 26, 2021 10:57 PM UTC

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



GK Gowthamraj Kumar Syncfusion Team November 29, 2021 06:44 AM UTC

Hi Boot, 
 
Thank you for your update. We are glad to know that provided sample is helpful to achieve your requirement. 

Please let us know if you need any further assistance with this. 

Regards, 
Gowthamraj K 



BD Boot Dat March 17, 2023 04:56 PM UTC

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?



IJ Irfana Jaffer Sadhik Syncfusion Team March 18, 2023 05:22 AM UTC

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


Loader.
Up arrow icon