- Home
- Forum
- Angular - EJ 2
- Create a PDF
Create a PDF
Is it possible to automatically generate a pdf from the content of the editor without having to go through the print function and choose a PDF printer ?
do you have a C# nuget that can convert your sfdt format to PDF?
SIGN IN To post a reply.
1 Reply
1 reply marked as answer
SM
Suriya Murugan
Syncfusion Team
April 30, 2021 08:12 AM UTC
Hi Michel,
Direct Sfdt to Pdf is not possible. You can convert the document to Docx and then we can convert the docx to pdf using server side. Document editor content can be exported as PDF file with the help of DocIO library.
You can find the server-side web services written in ASP.Net core & MVC. Kindly download it from below link.
You have to install below package in the above web services for converting the docx to pdf.
Please refer the below documentation for converting documents to PDF
Please refer the below code snippet.
|
using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;
[HttpPost]
[Route("DocToPDF")]
public string DocToPDF()
{
IFormFile file = HttpContext.Request.Form.Files[0];
Stream stream = new MemoryStream();
file.CopyTo(stream);
stream.Position = 0;
Syncfusion.DocIO.DLS.WordDocument wordDocument = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx);
//Instantiation of DocIORenderer for Word to PDF conversion
DocIORenderer render = new DocIORenderer();
//Converts Word document into PDF document
PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
//Saves the PDF file
FileStream fileStream = new FileStream(hostingEnvironment.WebRootPath + "\\Files\\" + "sample.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
pdfDocument.Save(fileStream);
//Closes the instance of PDF document object
render.Dispose();
wordDocument.Dispose();
pdfDocument.Dispose();
fileStream.Close();
return "Success";
} |
Also, we have prepared a sample that saves the document as pdf. Kindly download the sample from below link.
You can run sample and set the service URL as below.
|
containerInstance.serviceUrl = 'http://localhost:62869/api/documenteditor/'; //set the URL launched in your system. |
Use below client-side code to call the server API DoctToPdf
|
container.documentEditor.saveAsBlob('Docx').then((exportedDocument) => {
var formData = new FormData();
formData.append('fileName', 'sample.pdf');
formData.append('data', exportedDocument);
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', container.serviceUrl + ' DocToPDF ', true);
httpRequest.responseType = 'blob';
httpRequest.send(formData);
}); |
Documentation link: https://ej2.syncfusion.com/angular/documentation/document-editor/export/#export-as-blob
Please let us know if you have any questions.
Regards,
Suriya M.
Marked as answer
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
- Marked answer
-
ML Michel Lochten
- Apr 29, 2021 03:12 PM UTC
- Apr 30, 2021 08:12 AM UTC