Skip to content

Commit 3691a91

Browse files
Merge pull request #3851 from syncfusion-content/938086-Export-mvc
938086: Added export code in MVC
2 parents d7e43e1 + d95787e commit 3691a91

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public ActionResult Default()
2+
{
3+
return View();
4+
}
5+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public ActionResult Default()
2+
{
3+
return View();
4+
}
5+

ej2-asp-core-mvc/document-editor/how-to/export-document-as-pdf.md

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: post
3-
title: Export Document As PDF in ##Platform_Name## Document Editor Component
3+
title: Export PDF Document in ##Platform_Name## Document Editor Component |Syncfusion
44
description: Learn here all about export document as PDF in Syncfusion ##Platform_Name## Document Editor component of Syncfusion Essential JS 2 and more.
55
platform: ej2-asp-core-mvc
66
control: Export Document As PDF
@@ -26,7 +26,9 @@ N> You can install the PDF export packages from this [`link`](https://www.npmjs.
2626
{% include code-snippet/document-editor-container/export-pdf-client/tagHelper %}
2727
{% endhighlight %}
2828
{% highlight c# tabtitle="Export-pdf-client.cs" %}
29-
{% endhighlight %}{% endtabs %}
29+
{% include code-snippet/document-editor-container/export-pdf-client/document-editor.cs %}
30+
{% endhighlight %}
31+
{% endtabs %}
3032

3133
{% elsif page.publishingplatform == "aspnet-mvc" %}
3234

@@ -35,14 +37,16 @@ N> You can install the PDF export packages from this [`link`](https://www.npmjs.
3537
{% include code-snippet/document-editor-container/export-pdf-client/razor %}
3638
{% endhighlight %}
3739
{% highlight c# tabtitle="Export-pdf-client.cs" %}
38-
{% endhighlight %}{% endtabs %}
40+
{% include code-snippet/document-editor-container/export-pdf-client/document-editor.cs %}
41+
{% endhighlight %}
42+
{% endtabs %}
3943
{% endif %}
4044

4145

4246

4347
## Export document as PDF in server-side using Syncfusion<sup style="font-size:70%">&reg;</sup> DocIO
4448

45-
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.
49+
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.
4650

4751
The following way illustrates how to convert the document as PDF:
4852

@@ -55,7 +59,9 @@ The following way illustrates how to convert the document as PDF:
5559
{% include code-snippet/document-editor-container/export-pdf-server/tagHelper %}
5660
{% endhighlight %}
5761
{% highlight c# tabtitle="Export-pdf-server.cs" %}
58-
{% endhighlight %}{% endtabs %}
62+
{% include code-snippet/document-editor-container/export-pdf-server/document-editor.cs %}
63+
{% endhighlight %}
64+
{% endtabs %}
5965

6066
{% elsif page.publishingplatform == "aspnet-mvc" %}
6167

@@ -64,10 +70,12 @@ The following way illustrates how to convert the document as PDF:
6470
{% include code-snippet/document-editor-container/export-pdf-server/razor %}
6571
{% endhighlight %}
6672
{% highlight c# tabtitle="Export-pdf-server.cs" %}
67-
{% endhighlight %}{% endtabs %}
73+
{% include code-snippet/document-editor-container/export-pdf-server/document-editor.cs %}
74+
{% endhighlight %}
75+
{% endtabs %}
6876
{% endif %}
6977

70-
78+
{% if page.publishingplatform == "aspnet-core" %}
7179

7280
* Using Save API in server-side, you can convert the sfdt to stream.
7381
* Finally, convert the stream to PDF using `Syncfusion.DocIORenderer.Net.Core` library.
@@ -94,6 +102,42 @@ public void ExportPdf([FromBody]SaveParameter data)
94102
fileStream.Close();
95103
document.Close();
96104
}
105+
106+
```
107+
108+
{% elsif page.publishingplatform == "aspnet-mvc" %}
109+
110+
* Using Save API in server-side, you can convert the sfdt to stream.
111+
* Finally, convert the stream to PDF using `Syncfusion.DocToPdfConverter.AspNet.Mvc5` library.
112+
113+
```csharp
114+
115+
using Syncfusion.DocIO;
116+
using Syncfusion.DocIO.DLS;
117+
using Syncfusion.Pdf;
118+
using Syncfusion.DocToPDFConverter;
119+
120+
[HttpPost]
121+
public void ExportPdf([FromBody] SaveParameter data)
122+
{
123+
// Converts the sfdt to stream
124+
Stream document = WordDocument.Save(data.Content, Syncfusion.EJ2.DocumentEditor.FormatType.Docx);
125+
Syncfusion.DocIO.DLS.WordDocument doc = new Syncfusion.DocIO.DLS.WordDocument(document, Syncfusion.DocIO.FormatType.Docx);
126+
//Instantiation of DocIORenderer for Word to PDF conversion
127+
DocToPDFConverter render = new DocToPDFConverter();
128+
//Converts Word document into PDF document
129+
PdfDocument pdfDocument = render.ConvertToPDF(doc);
130+
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "sample.pdf");
131+
// Saves the document to server machine file system, you can customize here to save into databases or file servers based on requirement.
132+
FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
133+
//Saves the PDF file
134+
pdfDocument.Save(fileStream);
135+
pdfDocument.Close();
136+
fileStream.Close();
137+
document.Close();
138+
}
139+
97140
```
141+
{% endif %}
98142

99143
Get the complete working sample in this [`link`](https://github.com/SyncfusionExamples/Export-document-as-PDF-in-Document-Editor/).

0 commit comments

Comments
 (0)