Skip to content

Commit 0f01864

Browse files
938086: Resolved tag issue with establishing code
1 parent 1dd1bc2 commit 0f01864

File tree

3 files changed

+53
-66
lines changed

3 files changed

+53
-66
lines changed

ej2-asp-core-mvc/code-snippet/document-editor/export-pdf/aspnet-core.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

ej2-asp-core-mvc/code-snippet/document-editor/export-pdf/aspnet-mvc.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

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

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,64 @@ The following way illustrates how to convert the document as PDF:
7676
* Using Save API in server-side, you can convert the sfdt to stream.
7777
* Finally, convert the stream to PDF using `Syncfusion.DocIORenderer.Net.Core` library.
7878

79+
```csharp
80+
[AcceptVerbs("Post")]
81+
[HttpPost]
82+
[EnableCors("AllowAllOrigins")]
83+
[Route("ExportPdf")]
84+
public void ExportPdf([FromBody]SaveParameter data)
85+
{
86+
// Converts the sfdt to stream
87+
Stream document = WordDocument.Save(data.content, FormatType.Docx);
88+
Syncfusion.DocIO.DLS.WordDocument doc = new Syncfusion.DocIO.DLS.WordDocument(document, Syncfusion.DocIO.FormatType.Docx);
89+
//Instantiation of DocIORenderer for Word to PDF conversion
90+
DocIORenderer render = new DocIORenderer();
91+
//Converts Word document into PDF document
92+
PdfDocument pdfDocument = render.ConvertToPDF(doc);
93+
// Saves the document to server machine file system, you can customize here to save into databases or file servers based on requirement.
94+
FileStream fileStream = new FileStream("sample.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
95+
//Saves the PDF file
96+
pdfDocument.Save(fileStream);
97+
pdfDocument.Close();
98+
fileStream.Close();
99+
document.Close();
100+
}
101+
102+
```
103+
79104
{% elsif page.publishingplatform == "aspnet-mvc" %}
80105

81106
* Using Save API in server-side, you can convert the sfdt to stream.
82107
* Finally, convert the stream to PDF using `Syncfusion.DocToPdfConverter.AspNet.Mvc5` library.
83108

84-
{% endif %}
85-
86-
{% if page.publishingplatform == "aspnet-core" %}
87-
88-
{% tabs %}
89-
{% highlight cshtml tabtitle="CSHTML" %}
90-
{% endhighlight %}
91-
{% highlight c# tabtitle="DocumentEditorController.cs" %}
92-
{% include code-snippet/document-editor/export-pdf/aspnet-core.cs %}
93-
{% endhighlight %}
94-
{% endtabs %}
95-
96-
{% elsif page.publishingplatform == "aspnet-mvc" %}
97-
98-
{% tabs %}
99-
{% highlight cshtml tabtitle="CSHTML" %}
100-
{% endhighlight %}
101-
{% highlight c# tabtitle="DocumentEditorController.cs" %}
102-
{% include code-snippet/document-editor/export-pdf/aspnet-mvc.cs %}
103-
{% endhighlight %}
104-
{% endtabs %}
109+
```csharp
110+
111+
using Syncfusion.DocIO;
112+
using Syncfusion.DocIO.DLS;
113+
using Syncfusion.Pdf;
114+
using Syncfusion.DocToPDFConverter;
115+
116+
[HttpPost]
117+
public void ExportPdf([FromBody] SaveParameter data)
118+
{
119+
// Converts the sfdt to stream
120+
Stream document = WordDocument.Save(data.Content, Syncfusion.EJ2.DocumentEditor.FormatType.Docx);
121+
Syncfusion.DocIO.DLS.WordDocument doc = new Syncfusion.DocIO.DLS.WordDocument(document, Syncfusion.DocIO.FormatType.Docx);
122+
//Instantiation of DocIORenderer for Word to PDF conversion
123+
DocToPDFConverter render = new DocToPDFConverter();
124+
//Converts Word document into PDF document
125+
PdfDocument pdfDocument = render.ConvertToPDF(doc);
126+
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "sample.pdf");
127+
// Saves the document to server machine file system, you can customize here to save into databases or file servers based on requirement.
128+
FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
129+
//Saves the PDF file
130+
pdfDocument.Save(fileStream);
131+
pdfDocument.Close();
132+
fileStream.Close();
133+
document.Close();
134+
}
135+
136+
```
105137
{% endif %}
106138

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

0 commit comments

Comments
 (0)