Skip to content

938086: Added export code in MVC #3851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public ActionResult Default()
{
return View();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public ActionResult Default()
{
return View();
}

58 changes: 51 additions & 7 deletions ej2-asp-core-mvc/document-editor/how-to/export-document-as-pdf.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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" %}

Expand All @@ -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<sup style="font-size:70%">&reg;</sup> 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:

Expand All @@ -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" %}

Expand All @@ -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.
Expand All @@ -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/).