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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

PDFViewer Toolbar and binary PDF's in database

Thread ID:

Created:

Updated:

Platform:

Replies:

145751 Jul 6,2019 01:21 PM UTC Jul 22,2019 01:09 PM UTC ASP.NET Core - EJ 2 13
loading
Tags: PDF Viewer
Yoab Youssoufou
Asked On July 6, 2019 01:21 PM UTC

Hello,
concerning the PDFViewer for ej2 dotnet core, I have 2 questions:
1) Using this code
 
<div id="target" style="display:block;height:600px">   
    <ejs-pdfviewer id="pdfviewer" style="height:750px" 
                   serviceUrl="http://localhost:55629/api/PdfViewer" 
                   documentPath="PDF Succinctly.pdf" 
                   enableToolbar="true"
                   enablePrint="false"
                  >

    </ejs-pdfviewer>

</div>

I am unable to disable printing, the only way to prevent printing and downloading is by disabling the toolbar, it is all or nothing as long as the Toolbar is enabled all the toolbarItems are enabled whether or not you disable them as above.

2) Can I please have a sample dealing with binary PDF stored in the database, in my case I cannot use the file system.

Ramya Thirugnanam [Syncfusion]
Replied On July 8, 2019 11:25 AM UTC

Hi Yoab, 
 
Thanks for contacting Syncfusion support. 
 
Please find the details for you queries in the following table. 
 
Query 
Details 
I am unable to disable printing, the only way to prevent printing and downloading is by disabling the toolbar, it is all or nothing as long as the Toolbar is enabled all the toolbarItems are enabled whether or not you disable them as above. 
You can disable the print and download toolbar items by hiding the toolbar items from the toolbar of PDF Viewer control. Please find more details from the below documentation. 
 
 
Can I please have a sample dealing with binary PDF stored in the database, in my case I cannot use the file system. 
Yes, we can load the PDF documents from the database in the PDF Viewer control. We have created ASP.NET Core application to load the PDF document as base64 string from the database using PDF Viewer control. It can be downloaded from the following link. 
 
 
In the above sample, we have provided a button “Load PDF document as Base64String” in the page. When the button is clicked, a request will be sent to the sever to get the base64 string of the document stored in the database. This base64 string will be loaded in the PDF Viewer control after the completion of the request. 
 
Note: Please modify the connection string and the variables as the per your database in the above sample. 
 
Please confirm us that the above sample meets your requirements. If not, provide more details about your requirements. It will be helpful for us to analyze further and assist you better.  
 
Regards, 
Ramya T 


Yoab Youssoufou
Replied On July 8, 2019 07:22 PM UTC

Thank you Ramya this solves the problem perfectly.
But I still have one more question how would this example look like with the razor tag helpers <ejs-pdfviewer> instead of using javascript.

Ramya Thirugnanam [Syncfusion]
Replied On July 9, 2019 11:12 AM UTC

Hi Yoab, 
 
We have created the sample using the ejs-pdfviewer tag helper in ASP.NET Core, instead of using JavaScript and shared the same in the following location. 
 
In the above sample, we have loaded the PDF document from the database during the control initialization using the documentPath API. In the server side we have modified the code in the Load() to load the document from the database using the GetDocument() with the provided PDF document name. Please find the modified code from the below. 
 
Index.cshtml: 
<div id="target" style="display:block;height:600px"> 
<ejs-pdfviewer id="pdfviewer" style="height:750px" 
               serviceUrl="/api/PdfViewer" 
               documentPath="PDF Succinctly.pdf" 
               toolbarSettings="@(new Syncfusion.EJ2.PdfViewer.PdfViewerToolbarSettings { ShowTooltip = true, ToolbarItem = "OpenOption,PageNavigationTool,MagnificationTool,PanTool,SelectionTool,SearchOption,DownloadOption,UndoRedoTool,AnnotationEditTool"})"></ejs-pdfviewer> 
</div> 
 
Note: PDF Succinctly.pdf is the name of the PDF document used to search the document from the database. You can modify it as per your requirement. 
 
PdfViewerController.cs 
public IActionResult Load([FromBody] Dictionary<string, string> jsonObject) 
        { 
            PdfRenderer pdfviewer = new PdfRenderer(); 
            MemoryStream stream = new MemoryStream(); 
            object jsonResult = new object(); 
            if (jsonObject != null && jsonObject.ContainsKey("document")) 
            { 
                if (bool.Parse(jsonObject["isFileName"])) 
                {      
                    //Gets the Pdf document as bytearray using its name from the database. 
                 byte[] bytes = GetDocument(jsonObject["document"]); 
                 stream = new MemoryStream(bytes); 
                } 
                else 
                { 
                    byte[] bytes = Convert.FromBase64String(jsonObject["document"]); 
                    stream = new MemoryStream(bytes); 
                } 
            } 
            jsonResult = pdfviewer.Load(stream, jsonObject); 
            return Content(JsonConvert.SerializeObject(jsonResult)); 
        } 
 
Note:  
The PDF document name provided in the documentPath API can be obtained using jsonObject["document"] 
 
Please modify the connection string and the variables as the per your database in the above sample.   
Please confirm us that the above sample meets your requirements. If not, provide more details about your requirements. It will be helpful for us to analyze further and assist you better 
 
Regards,
Ramya T
 


Yoab Youssoufou
Replied On July 10, 2019 12:56 PM UTC

Thank you. I have implemented it and all works well in my localhost but when I deploy the PDF does not get loaded. It is not a folder permission issue since my PDF's are stored in a blob in the database. Also I am using the exact same connection string, i.e. connecting to the remote database even from my local system. I have tried this in several browsers all with same result, the remote host i just get spinner spinning indefinetely while the pdf file renders in the PDFviewer when it is local host. Please do u have any ideas? I have attached the screenshot for both scenarios. 


Attachment: PDFViewerDeployed_6b4798fb.7z

Ramya Thirugnanam [Syncfusion]
Replied On July 11, 2019 03:51 PM UTC

Hi Yoab, 
 
We can reproduce the reproduce the reported issue while hosting the sample in IIS and the issue is reproduced only when the PDF document is loaded from Database. So we suspect that the issue may be due to the security constraints. However we will analyze further on the reported issue and update you with more details on July 15th, 2019. 
 
Regards, 
Ramya T 


Yoab Youssoufou
Replied On July 11, 2019 03:54 PM UTC

Thank you Ramya, I will be waiting.
Best Regards

Yoab Youssoufou
Replied On July 15, 2019 08:16 PM UTC

Hello Ramya,
Today's the 15th, any update yet?

Ramya Thirugnanam [Syncfusion]
Replied On July 16, 2019 12:04 PM UTC

Hi Yoab, 
 
Sorry for the inconvenience caused. 
 
We need some more time to complete our validation. We will get back to you with further details on July 17th, 2019. 
 
Regards, 
Ramya T  


Ramya Thirugnanam [Syncfusion]
Replied On July 18, 2019 04:07 AM UTC

Hi Yoab, 
On further analyses we found that, we can load the PDF document in the hosted environment using file upload option and the issue occurred only while loading the PDF document from database. Hence the issue is not with the PDF Viewer and it occurred due to the database connection string provided in the project. So kindly modify the database connection string based on your hosted environment and ensure the database connections while running the project.  
Regards,
Ramya T
 


Yoab Youssoufou
Replied On July 18, 2019 09:43 AM UTC

Hello Ramya,
It is DEFINETELY not a connectionstring problem, as I said earlier on using the remote connectionstring from my visual studio local environment (localhost) it works fine, and even u have admitted the problem only arises when deployed to IIS, meaning it has to be an IIS permissions issue, I have full control over the IIS server but I'm at a loss on to what settings to relax

Ramya Thirugnanam [Syncfusion]
Replied On July 21, 2019 09:52 AM UTC

Hi Yoab, 
 
We have analyzed and found that this is general issue occurred when connecting to the database from the hosted environment and it is not related to our PDF Viewer control. However we will analyze further on this and update you with more details on July 22nd, 2019 
 
Regards, 
Ramya T 


Yoab Youssoufou
Replied On July 21, 2019 08:44 PM UTC

Ok thanks. waiting

Ramya Thirugnanam [Syncfusion]
Replied On July 22, 2019 01:09 PM UTC

Hi Yoab,   
We have analyzed to find out the root cause of the issue. But we are not able to find out the solution from our side. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates .   
Regards,   
Ramya T   


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon