![]() ![]() ![]() In ASP.NET Web API (service), the stream (input document) is converted into PDF in the service side and returned the response with resultant PDF.In ASP.NET Core sample, load the existing presentation document using Essential Presentation and send that document as stream to Web API (service) application.In this sample, the following things have been done: Return File(outputStream, "application/pdf", "Sample.pdf") OutputStream = new MemoryStream(await ()) Gets PDF from content stream if service got success Dispose the input stream and client instances Response = await client.PostAsync(requestUri, new StreamContent(inputStream)) Posts input presentation document to service and gets resultant PDF as content of HttpResponseMessage #region Service approach to send presentation document as stream and gets resultant converted PDF from it. MemoryStream inputStream = new MemoryStream() Saves a presentation into stream and close the presentation instance IPresentation presentation = Presentation.Open(fileStream) String rootPath = _hostingEnvironment.WebRootPath įileStream fileStream = new FileStream(rootPath + "/PPTX/TemplateFile.pptx", FileMode.Open) ![]() The following code snippet explains how to use the previously given web service to the ASP.NET Core applications to convert the PowerPoint file as a PDF document in ASP.NET Core application. HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.ExpectationFailed) HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)Ĭontent = new StreamContent(memoryStream) MemoryStream memoryStream = new MemoryStream() Saves the PDF document to response stream ("Created by Syncfusion – Presentation library", pdfFont, PdfBrush pdfBrush = new PdfSolidBrush(Color.White) Create a new PDF brush to draw the rectangle PdfFont pdfFont = new PdfTrueTypeFont(font, false) Create PDF font and PDF font style using Fontįont font = new Font("Times New Roman", 12f, FontStyle.Regular) To remove this watermark, comment or delete the codes within below "if" statement Adds watermark at top left corner of first page in the generated PDF document to denote that it is generated using demo web service PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation, settings) Converts PowerPoint presentation (PPTX) into PDF document PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings Creates an instance of the PresentationToPdfConverterSettings Presentation.ChartToImageConverter = new ChartToImageConverter Initializes the ChartToImageConverter for converting charts during PPTX to PDF conversion Using (IPresentation presentation = Presentation.Open(stream)) Opens the PowerPoint presentation (PPTX) from stream Public HttpResponseMessage ConvertToPdf() / Converts the PowerPoint presentation (PPTX) to PDF document ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |