public IActionResult DocToPDF(IFormCollection data)
{
Stream stream = new MemoryStream();
IFormFile file = data.Files[0];
var fileName = file.FileName;
file.CopyTo(stream);
stream.Position = 0;
Syncfusion.DocIO.DLS.WordDocument wordDocument = newSyncfusion.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
MemoryStream outputStream = new MemoryStream();
pdfDocument.Save(outputStream);
//Closes the instance of PDF document object
outputStream.Position = 0;
render.Dispose();
wordDocument.Dispose();
return File(outputStream, "application/pdf", fileName + ".pdf");
}
|