|
[HttpPost]
[Route("DocToPDF")]
public string DocToPDF(string fileName)
{
Stream stream = new MemoryStream();
IFormFile file = HttpContext.Request.Form.Files[0];
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);
MemoryStream ms = new MemoryStream();
//Saves the PDF file
pdfDocument.Save(ms);
string base64String = Convert.ToBase64String(ms.ToArray());
string base64 = String.Format("data:application/pdf;base64," + base64String);
//Closes the instance of PDF document object
render.Dispose();
wordDocument.Dispose();
pdfDocument.Dispose();
ms.Close();
return base64String;
} |