using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;
[HttpPost]
[Route("DocToPDF")]
public string DocToPDF()
{
IFormFile file = HttpContext.Request.Form.Files[0];
Stream stream = new MemoryStream();
file.CopyTo(stream);
stream.Position = 0;
Syncfusion.DocIO.DLS.WordDocument wordDocument = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx);
//Instantiation of DocIORenderer for Word to PDF conversion
DocIORenderer render = new DocIORenderer();
//Converts Word document into PDF document
PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
//Saves the PDF file
FileStream fileStream = new FileStream(hostingEnvironment.WebRootPath + "\\Files\\" + "sample.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
pdfDocument.Save(fileStream);
//Closes the instance of PDF document object
render.Dispose();
wordDocument.Dispose();
pdfDocument.Dispose();
fileStream.Close();
return "Success";
} |
containerInstance.serviceUrl = 'http://localhost:62869/api/documenteditor/'; //set the URL launched in your system. |
container.documentEditor.saveAsBlob('Docx').then((exportedDocument) => {
var formData = new FormData();
formData.append('fileName', 'sample.pdf');
formData.append('data', exportedDocument);
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', container.serviceUrl + ' DocToPDF ', true);
httpRequest.responseType = 'blob';
httpRequest.send(formData);
}); |