- Home
- Forum
- JavaScript - EJ 2
- Save PDF server side
Save PDF server side
Hi,
Is it possible to save an annotated pdf server side using ES5 javascript?
Thanks . . .
|
<button id="id">Save</button>
document.getElementById('id').addEventListener('click', function() {
viewer.serverActionSettings.download = 'SaveDocument';
viewer.download();
viewer.serverActionSettings.download = 'Download';
});
|
|
[HttpPost]
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
public ActionResult SaveDocument([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 + "/ouptut.pdf", byteArray);
}
return Content(string.Empty);
}
|
Hi Vasugi,
Many thanks for your earlier response. The provided example works perfectly however the web service is .net core. Do you have a .net framework example of the web service?
Also, do you have an example where only the annotations toolbar is displayed - ideally only the "highlight", "underline", "strikethrough", "delete annotation" and "comment panel" buttons are displayed (see image)?
Thanks,
Sean
|
Query |
Details | |
|
Many thanks for your earlier response. The provided example works perfectly however the web service is .net core. Do you have a .net framework example of the web service? |
We have shared the MVC sample and documentation for your reference. Please refer to the below links to create a web service using the .net framework.
Web service: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebService-1427312071
Documentation: https://ej2.syncfusion.com/javascript/documentation/pdfviewer/how-to/create-pdfviewer-service/
| |
|
Also, do you have an example where only the annotations toolbar is displayed - ideally only the "highlight", "underline", "strikethrough", "delete annotation" and "comment panel" buttons are displayed (see image)?
|
You can hide and show the toolbar items using the toolbarSettings API. Please refer to the below code snippet and sample.
Code Snippet:
Web service: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebService-1427312071
|
Hi Vasugi,
I have implemented all of your suggestions and mostly have the control working.
The web service however fails when I try to save the document. It fails on this line . . .
string base64String = documentBase.Split(new string[] { "data:application/pdf;base64," }, StringSplitOptions.None)[1];
The exception is System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
I think this is being caused by the line before . . .
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
If I interrogate documentBase I see the following error
Could not load file or assembly 'Syncfusion.Licensing, Version=19.2450.0.51, Culture=neutral, PublicKeyToken=632609b4d040f6b4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
In line with the documentation and various support queries I have check the packages and all look ok . . .
<package id="Syncfusion.Compression.Base" version="19.2.0.51" targetFramework="net46" />
<package id="Syncfusion.EJ2.JavaScript" version="19.2.0.51" targetFramework="net46" />
<package id="Syncfusion.EJ2.PdfViewer.AspNet.Mvc5" version="19.2.0.51" targetFramework="net46" />
<package id="Syncfusion.Licensing" version="19.2.0.51" targetFramework="net46" />
<package id="Syncfusion.Pdf.AspNet.Mvc5" version="19.2.0.51" targetFramework="net46" />
Can you suggest where the problem is?
Thanks,
Sean
- You need to remove the 'Syncfusion.Licensing’ package from the references.
- Then add the 'Syncfusion.Licensing.dll’ with same version of target framework from the package in project folder.
- And please clean and build the project.
Hi Vasugi,
Unfortunately your suggestion did not work.
I have created a stripped down version of the app but the smallest I can make it is 80MB. This exceeds your max attachment size so I cannot upload. Do you have an alternate mechanism to upload our sample web service so you can review?
Alternatively can you upload a working version of the web service with the correct licensing package installed?
Thanks,
Sean
Hi Vasugi,
Just wondering if you have an update on this item - we are approaching our deployment date and need to make a decision on the feasibility of using this control.
Many Thanks,
Sean
Hi Vasugi,
I'm not sure if we are doing something wrong at our end but your sample application does not compile. See attached screen shots. Is there something that we should be doing here before building the solution?
Thanks,
Sean.
Hi Vasugi,
Thanks for the updated application. This has helped us move forward but we are still having multiple problems when we extend your sample into a real world solution . . .
- When we save a pdf, the file will only save if there are no annotations. Once we add annotations we see that documentBase = pdfviewer.GetDocumentAsBase64(jsonObject) returns "object reference not set to an instance of an object" and we then get an "index was outside the bounds of the array error" here -
- Our desired solution for the component is . . .
- we pass any file name for a docx, xlsx, pdf, pptx
- for a docx, xlsx or pptx we convert the file to a pdf on the fly and pass to the viewer
- when the save option is clicked, the annotated pdf is save to the server
Dim base64String As String = documentBase.Split(New String() {"data:application/pdf;base64,"}, StringSplitOptions.None)(1)
When we try to add the further required packages to deliver the conversion logic we end up with some severe package errors when we try to execute the application (eg. Could not load file or assembly 'Syncfusion.Licensing' or one of its dependencies). We get various different cuts of these errors depending on the order in which we install the further packages.
We would greatly appreciate your assistance and a web meeting would be ideal. We are available any time from 1pm BST (UTC +1).
Many Thanks,
Sean.
Apologies Vasugi,
I should have added that we are using .net framework 4.6.2. and Syncfusion version 19.2.0.55.
Thanks . . .
- 13 Replies
- 2 Participants
-
SE Sean
- Jul 16, 2021 01:26 AM UTC
- Aug 17, 2021 09:15 AM UTC