Implement the
option to export from word to pdf with the Document Editor
The user opens a word document.
It gives you export to pdf, angular sends the blog to the server and with DocIO it exports to PDF.
In this case, take the example document that has some images.
Attached I send the word document of the server generated correctly and the exported pdf document. Some additional lines are presented that do not comply with the correct format.
Attached word document and pdf, as well as the image of the pdf
Attachment: WordToPdf_d63573cd.zip
I do not understand
From a unit test it works fine, but from an api it doesn't work correct.
//API controller for the conversion. (it does not work)
[AcceptVerbs("Post")]
[HttpPost]
[EnableCors("AllowAllOrigins")]
[Route("ExportPdf")]
public void ExportAsPdfSinPost()
{
//Open the file as Stream
var docStream = new FileStream(@"G:\2019\Ejemplo.docx", FileMode.Open, FileAccess.Read);
//Loads file stream into Word document
var wordDocument = new WDocument(docStream, Syncfusion.DocIO.FormatType.Automatic);
//Instantiation of DocIORenderer for Word to PDF conversion
var render = new DocIORenderer();
//Sets Chart rendering Options.
render.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Jpeg;
//Converts Word document into PDF document
var pdfDocument = render.ConvertToPDF(wordDocument);
//Releases all resources used by the Word document and DocIO Renderer objects
render.Dispose();
wordDocument.Dispose();
//Saves the PDF file
var outputStream = new MemoryStream();
pdfDocument.Save(outputStream);
//Closes the instance of PDF document object
pdfDocument.Close();
System.IO.File.WriteAllBytes(@"G:\2019\EjemploVoid.pdf",outputStream.ToArray());
}
it works
[Test]
public void TestToPdfejemploAngular()
{
//Open the file as Stream
var docStream = new FileStream(@".\Archivos\ejemploAngular.docx", FileMode.Open, FileAccess.Read);
//Loads file stream into Word document
var wordDocument = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic);
//Instantiation of DocIORenderer for Word to PDF conversion
var render = new DocIORenderer();
//Sets Chart rendering Options.
render.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Jpeg;
//Converts Word document into PDF document
var pdfDocument = render.ConvertToPDF(wordDocument);
//Releases all resources used by the Word document and DocIO Renderer objects
render.Dispose();
wordDocument.Dispose();
//Saves the PDF file
var outputStream = new MemoryStream();
pdfDocument.Save(outputStream);
//Closes the instance of PDF document object
pdfDocument.Close();
File.WriteAllBytes(@".\Archivos\ejemploAngular.pdf",outputStream.ToArray());
Assert.IsTrue(File.Exists(@".\Archivos\ejemploAngular.pdf"));
}