We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to save PDF on specific server location

How can I save a pdf file to a specific server location using PDFViewer???

The threads that I found aren't really that helpful when it comes to this particular issue. Can someone please give me an explanation to make this possible.


7 Replies 1 reply marked as answer

FA Farai October 28, 2022 05:43 AM UTC

To be more specific, I'd like to save the original file name from clienr-side to a specific server location. I'm struggling to get that file name.



CK Chinnamunia Karthik Chinna Thambi Syncfusion Team October 28, 2022 03:15 PM UTC

Hi Farai,


In the given sample, the document is saved in the server location with the same file name at the client side.


Code Snippet:


        public IActionResult Download([FromBody] Dictionary<string, string> jsonObject)

        {

            PdfRenderer pdfviewer = new PdfRenderer(_cache);

            string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);

            string base64String = documentBase.Split(new string[] { "data:application/pdf;base64," }, StringSplitOptions.None)[1];

            if (base64String != null || base64String != string.Empty)

            {

                byte[] byteArray = Convert.FromBase64String(base64String);

                MemoryStream ms = new MemoryStream(byteArray);

                var path = _hostingEnvironment.ContentRootPath; System.IO.File.WriteAllBytes(path + $"/{jsonObject["documentId"]}", byteArray);

            }

            return Content(String.Empty);

        }


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SaveDocumentInTheServer-1144564809.zip


Steps to save the PDF in the server location:


  • Run the sample
  • Load the PDF
  • Download PDF // Now the PDF is saved in the server location


Please let us know if you have any concerns on this.



Regards,

CCM Karthik



FA Farai October 30, 2022 09:19 AM UTC

Thank you, CCM Karthik. It works.


Is there a way I can use my own custom button to accomplish the same results? And also, is there a way I can get the document's original path?





CK Chinnamunia Karthik Chinna Thambi Syncfusion Team October 31, 2022 12:36 PM UTC

Hi Farai,

 

Kindly find the details for the respective queries.

 

Is there a way I can use my own custom button to accomplish the same results?

 

Kindly refer the below sample to save the document in the server with a button click.

 

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SaveDocumentInTheServer2-96881226.zip

 

Steps to save the PDF in the server location:

 

  • Run the sample
  • Click the "save" button. // Now the PDF is saved in the server location

is there a way I can get the document's original path?

 

It is not possible to get the document's original path while loading the document.

 

Please let us know if you have any concerns on this.


Regards,

CCM Karthik


Marked as answer

FA Farai October 31, 2022 12:38 PM UTC

Thanks you good sir. I will get back to you



FA Farai October 31, 2022 01:41 PM UTC

Thank you,  CCM Karthik. Works perfectly.



CK Chinnamunia Karthik Chinna Thambi Syncfusion Team November 1, 2022 06:28 AM UTC

Hi Farai,

 

Thanks for the update. We are closing this ticket now, Kindly re-open this ticket, if you have any concerns on this.


Regards,

CCM Karthik


Loader.
Live Chat Icon For mobile
Up arrow icon