diff --git a/ej2-asp-core-mvc/code-snippet/document-editor-container/export-pdf-client/document-editor.cs b/ej2-asp-core-mvc/code-snippet/document-editor-container/export-pdf-client/document-editor.cs new file mode 100644 index 0000000000..048a3eb88c --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/document-editor-container/export-pdf-client/document-editor.cs @@ -0,0 +1,5 @@ +public ActionResult Default() +{ + return View(); +} + diff --git a/ej2-asp-core-mvc/code-snippet/document-editor-container/export-pdf-server/document-editor.cs b/ej2-asp-core-mvc/code-snippet/document-editor-container/export-pdf-server/document-editor.cs new file mode 100644 index 0000000000..048a3eb88c --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/document-editor-container/export-pdf-server/document-editor.cs @@ -0,0 +1,5 @@ +public ActionResult Default() +{ + return View(); +} + diff --git a/ej2-asp-core-mvc/document-editor/how-to/export-document-as-pdf.md b/ej2-asp-core-mvc/document-editor/how-to/export-document-as-pdf.md index 4e964d3550..0d18e560c9 100644 --- a/ej2-asp-core-mvc/document-editor/how-to/export-document-as-pdf.md +++ b/ej2-asp-core-mvc/document-editor/how-to/export-document-as-pdf.md @@ -1,6 +1,6 @@ --- layout: post -title: Export Document As PDF in ##Platform_Name## Document Editor Component +title: Export PDF Document in ##Platform_Name## Document Editor Component |Syncfusion description: Learn here all about export document as PDF in Syncfusion ##Platform_Name## Document Editor component of Syncfusion Essential JS 2 and more. platform: ej2-asp-core-mvc control: Export Document As PDF @@ -26,7 +26,9 @@ N> You can install the PDF export packages from this [`link`](https://www.npmjs. {% include code-snippet/document-editor-container/export-pdf-client/tagHelper %} {% endhighlight %} {% highlight c# tabtitle="Export-pdf-client.cs" %} -{% endhighlight %}{% endtabs %} +{% include code-snippet/document-editor-container/export-pdf-client/document-editor.cs %} +{% endhighlight %} +{% endtabs %} {% elsif page.publishingplatform == "aspnet-mvc" %} @@ -35,14 +37,16 @@ N> You can install the PDF export packages from this [`link`](https://www.npmjs. {% include code-snippet/document-editor-container/export-pdf-client/razor %} {% endhighlight %} {% highlight c# tabtitle="Export-pdf-client.cs" %} -{% endhighlight %}{% endtabs %} +{% include code-snippet/document-editor-container/export-pdf-client/document-editor.cs %} +{% endhighlight %} +{% endtabs %} {% endif %} ## Export document as PDF in server-side using Syncfusion® DocIO -With the help of [`Synfusion DocIO`](https://help.syncfusion.com/file-formats/docio/word-to-pdf), you can export the document as PDF in server-side. Here, you can search the text. +With the help of [`Syncfusion DocIO`](https://help.syncfusion.com/file-formats/docio/word-to-pdf), you can export the document as PDF in server-side. Here, you can search the text. The following way illustrates how to convert the document as PDF: @@ -55,7 +59,9 @@ The following way illustrates how to convert the document as PDF: {% include code-snippet/document-editor-container/export-pdf-server/tagHelper %} {% endhighlight %} {% highlight c# tabtitle="Export-pdf-server.cs" %} -{% endhighlight %}{% endtabs %} +{% include code-snippet/document-editor-container/export-pdf-server/document-editor.cs %} +{% endhighlight %} +{% endtabs %} {% elsif page.publishingplatform == "aspnet-mvc" %} @@ -64,10 +70,12 @@ The following way illustrates how to convert the document as PDF: {% include code-snippet/document-editor-container/export-pdf-server/razor %} {% endhighlight %} {% highlight c# tabtitle="Export-pdf-server.cs" %} -{% endhighlight %}{% endtabs %} +{% include code-snippet/document-editor-container/export-pdf-server/document-editor.cs %} +{% endhighlight %} +{% endtabs %} {% endif %} - +{% if page.publishingplatform == "aspnet-core" %} * Using Save API in server-side, you can convert the sfdt to stream. * Finally, convert the stream to PDF using `Syncfusion.DocIORenderer.Net.Core` library. @@ -94,6 +102,42 @@ public void ExportPdf([FromBody]SaveParameter data) fileStream.Close(); document.Close(); } + +``` + +{% elsif page.publishingplatform == "aspnet-mvc" %} + +* Using Save API in server-side, you can convert the sfdt to stream. +* Finally, convert the stream to PDF using `Syncfusion.DocToPdfConverter.AspNet.Mvc5` library. + +```csharp + +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.Pdf; +using Syncfusion.DocToPDFConverter; + +[HttpPost] +public void ExportPdf([FromBody] SaveParameter data) +{ + // Converts the sfdt to stream + Stream document = WordDocument.Save(data.Content, Syncfusion.EJ2.DocumentEditor.FormatType.Docx); + Syncfusion.DocIO.DLS.WordDocument doc = new Syncfusion.DocIO.DLS.WordDocument(document, Syncfusion.DocIO.FormatType.Docx); + //Instantiation of DocIORenderer for Word to PDF conversion + DocToPDFConverter render = new DocToPDFConverter(); + //Converts Word document into PDF document + PdfDocument pdfDocument = render.ConvertToPDF(doc); + string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "sample.pdf"); + // Saves the document to server machine file system, you can customize here to save into databases or file servers based on requirement. + FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + //Saves the PDF file + pdfDocument.Save(fileStream); + pdfDocument.Close(); + fileStream.Close(); + document.Close(); +} + ``` +{% endif %} Get the complete working sample in this [`link`](https://github.com/SyncfusionExamples/Export-document-as-PDF-in-Document-Editor/). \ No newline at end of file