Hi,
Syncfusion version 25.2.4
We're using the DocumentEditor control to create great looking documents.
Now we want to export those to PDF using a server side webservice running on .net and IIS.
Following the documentation we ended up with this code from github: https://github.com/SyncfusionExamples/EJ2-Document-Editor-Web-Services/tree/master/Minimal%20Web%20API
We compiled the code using Visual Studio 2022 and are compiling against .net 6 and set the components via nuget for syncfusion version 25.2.4.
Then test while running the resulting .exe from the command line and verify using localhost:8000/loadDefault by putting that URL in the browser that the webservice functions normally. It returns the sfdt document as expected.
Now we took the example from the demo at: https://ej2.syncfusion.com/javascript/demos/#/fluent2/document-editor/advanced-exporting.html and put it under a virtual directory on our local IIS server.
The control shows up and works fine, including the -server side- export to PDF. But it is still using the webservice on the servers from Syncfusion and that is not allowed for production. So we want to switch over to the local webservice.
The host url in javascript is adjusted as follows:
var hostUrl = 'https://localhost:8000/api/documenteditor/';
If we try to export to PDF again, with our own version of the webservice, the webservice crashes...
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HN5I2NLHJQBO", Request id "0HN5I2NLHJQBO:00000003": An unhandled exception was thrown by the application.
System.InvalidOperationException: Incorrect Content-Type: application/json;charset=UTF-8
at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()
at Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Form()
at Program.<>c__DisplayClass0_0.<<Main>$>b__10(HttpRequest request) in C:\Users\Wil\source\repos\EJ2-Document-Editor-Web-Services-master\Minimal Web API\Program.cs:line 108
at lambda_method14(Closure , Object , HttpContext )
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass36_0.<Create>b__0(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Builder.Extensions.UsePathBaseMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
Any ideas as to what is wrong?
Thanks,
Wil
Wil, we were unable to reproduce the reported issue on our end. It may be related to the code you are using. Could you please provide the code and a simple sample that you are working with? This will help us investigate the problem further. Additionally, could you confirm if this issue occurs only when exporting to PDF or in other operations, such as importing a Word document, pasting with formatting, by using your custom web service?
Hello Kavitha,
Thank you for your answer.
Good questions. I just tried and import of a Word Document and pasting text with formatting works as expected.
So no problem there, the main issue is not getting the pdf export to work.
Attached is our test code in a zip. We just double click in Windows explorer on the html files to test (although also tested via a web share with the same result)
It contains 2 examples:
index.html -> this uses our local webservice and the webservice crashes on the export and no pdf gets generated.
index-sf-26.2.4.html -> this example uses the cdn version of SyncFusion webservice itself and works as expected.
Testing via toolbar button "Export" -> Server side exporting -> select "PDF"
The .net code that we are using is this: https://github.com/SyncfusionExamples/EJ2-Document-Editor-Web-Services/tree/master/Minimal%20Web%20API
We have not made ANY changes to the code.
Do you still want me to upload that too?
thanks,
Wil
Attachment: Minimal_Web_APIsource20240806_bff6d21d.zip
edit: Forgot to say that we created an empty file called
customDict.dic in the App_Data folder as else there will be other issues.
Hi Wil van Antwerpen,
In the provided project ,We have modified the Export API endpoint and saveDocument method to support for PDF format exporting. Please find the attached Minimal Web API source project below.
Regards,
Suresh I
Hello Suresh,
Thank You!
That makes a big difference and I can confirm that it now works as a standalone binary.
My next step is to get this to work as an IIS module and I appear to be bumping into the following error (again & again). The error is in the Windows eventlog.
Application: w3wp.exe
CoreCLR Version: 6.0.3224.31407
.NET Version: 6.0.32
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException: Changing the URL is not supported because Addresses IsReadOnly.
at Microsoft.AspNetCore.Builder.WebApplication.Listen(String url)
at Microsoft.AspNetCore.Builder.WebApplication.Run(String url)
at Program.<Main>$(String[] args) in C:\Users\Wil\source\repos\EJ2-Document-Editor-Web-Services-master\Minimal Web API\Program.cs:line 127
Obviously the first thing to do is to look at Program.cs line 127...
It has this single line:
app.Run("https://localhost:8000/");
So it makes perfect sense that when you try to contact the webservice via https://localhost/sfWebDocumentEditor/api/documenteditor that it throws an error like above.
However I have tried changing that url like so:
app.Run("https://localhost/sfWebDocumentEditor/");But the error persisted.
Obviously I'm not a .net developer that works a lot with web services.
How would I change this so that the web service does not complain?
Changing that to the following:
app.Run();
and the runtime error is resolved.
It still doesn't work as a IIS webservice though, so I'm a bit puzzled as to what the problem is now.
Ideas are welcome.
Thanks!
--
Wil
Maybe this helps?
Trying the following url in the browser:
localhost/sfWebDocumentEditor/loadDefault
Returns the following html in the browser:
"
An attempt was made to access a socket in a way forbidden by its access permissions. [::ffff:34.160.67.190]:443 (www.syncfusion.com:443)
"
Puzzled...
Edit:
The access permissions error was due to a host based firewall. Disabling that and "loadDefault" works, but only loadDefault. Opening a Word Document or trying to print a pdf file still does not work when running the Minimal Web API code under IIS.
--
Wil
Hi Wil Van Antwerpen,
Currently we are checking on this and will update the further details on Aug 13, 2024.
Regards,
Suresh I
Hello Suresh,
Much appreciated. Thank you for the update.
I'm suspecting that it I'm missing something simple, but haven't found yet what it is.
Especially as loadDefault now works while running under IIS.. it does appear that the service is very close to functional.
--
Wil
Hi Suresh,
Found it!
Something small indeed.
On the IIS host, the testing was done via localhost and there was a self signed certificate for accessing via https.
The html/javascript code to test is on localhost/sfWebDocumentEditorTest/index.html
The webservice is running on localhost/sfWebDocumentEditor
This works, accessing on https://localhost/sfWebDocumentEditorTest/index.html
This does not work: http://localhost/sfWebDocumentEditorTest/index.html
Also not working is testing when opening via the local filesystem (double click in windows explorer)
Also not working is if the service url is not using https.
eg.
var hostUrl = 'http://localhost/sfWebDocumentEditor/api/documenteditor/';
One more question (sorry).
Is it possible to turn off the requirement for https?
In case the service is running on localhost, it does not add much to use SSL.
Or
would we run into a CORS issue if we did that? (As obviously the
application using the service would be hosting on a domain name, not on
localhost)
Thanks!
--
Wil
The https requirement is probably just a matter of commenting out the line:
app.UseHttpsRedirection();
Final question.
I've applied the license at the javascript level. This does not appear to be sufficient to satisfy the pdf export.
Where do I set this in the .net service?
thanks,
Wil
Hi Suresh,
Re. license..
I seem to be able to find my way around it now as I'm answering my own questions. 🤔
Untested so far, but it seems that the answer to that particular question is documented here:
https://help.syncfusion.com/document-processing/licensing/how-to-register-in-an-application
I'll get back to testing that theory, but figured to post it here already. 😉
--
Wil
Hi Wil Van Antwerpen,
Regarding the licensing queries, we request you to refer to the below provided documentation links on how to register license key in the applications.
To generate license keys : https://help.syncfusion.com/document-processing/licensing/how-to-generate
To register license keys : https://help.syncfusion.com/document-processing/licensing/how-to-register-in-an-application#aspnet-core
Regards,
Suresh I
Thanks Suresh for the superb help.
Yes, that's the way I went for registering my license and it works well.
Everything works now (with the exception that I still need a certificate for localhost, but that's not necessarily a bad thing)
Case Closed, thanks again.
--
Wil