This is a migrated thread and some comments may be shown as answers.

Convert Docx to pdf

4 Answers 200 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Miriam
Top achievements
Rank 1
Miriam asked on 19 Apr 2017, 04:31 PM

Hi, 

 

Is it possible to do the DOCX to PDF conversion? Because I have a document in a folder and I want to export to pdf.

 

4 Answers, 1 is accepted

Sort by
0
Miriam
Top achievements
Rank 1
answered on 19 Apr 2017, 06:05 PM

I have a Byte [ ] of word document containing Text and tables.

I´m using the next code but I can´t convert the word document to pdf

byte[] documento = null;
                            RadFlowDocument documento2 = new RadFlowDocument();
                            Telerik.Windows.Documents.Common.FormatProviders.IFormatProvider<RadFlowDocument> formatProvider3 = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
                            string path = Path.Combine(carpetaReportes, "EstudioViabilidadF_4516_Orden_10310.docx");
                            documento = bytesW;
                            string nom="Archivo.pdf";
                            using (MemoryStream m = new MemoryStream())
                            {
                                using (FileStream stream = File.Open(path, FileMode.Open))
                                {
                                    documento2 = formatProvider3.Import(stream);
                                    formatProvider3.Export(documento2, m);
                                    GuardarHistoria(nom, m);
                                }
                            }

0
Mihail
Telerik team
answered on 24 Apr 2017, 07:23 AM
Hello Miriam,

From your code, I can see that you are trying to import a DOCX file path with the formatProvider3 variable.
I am afraid that this won't work as the formatProvider3 is an instance of the PdfFormatProvider class. If you would like to import a DOCX file you should use the DocxFormatProvider class. If you would like to export the document to PDF format then you should use the PdfFormatProvider class.
Each supported file format has its own format provider which should be used for the import/export operations.

I hope this information is helpful.

Regards,
Mihail
Telerik by Progress

0
Miriam
Top achievements
Rank 1
answered on 05 May 2017, 09:43 PM

Thanks for your help. Following your advice I'm using the next code:

RadFlowDocument document = provider.Import(bytesword);

Path.Combine(carpetaReportes, "Estudio_" + IdPaciente + "_Orden_" + OrdenServ + ".pdf");

PdfFormatProvider providerPdf = new PdfFormatProvider();   ---->In this line appears the exception

using (Stream c = File.Open(nombrePDF, FileMode.Create))
                {
                    providerPdf.Export(document, c);                             
                }

 

But I get the next error: Operation can not destabilize the runtime as shown in the picture

0
Mihail
Telerik team
answered on 09 May 2017, 07:39 AM
Hello Miriam,

From the stack trace in the screenshot, I can see that there is some problem with a font used in the document.
My recommendation for you is to open a new support ticket with product ASP (AJAX/MVC) PdfProcessig and provide the problematic document. This way we will be able to investigate what is causing the issue.

Regards,
Mihail
Telerik by Progress

Tags
PdfProcessing
Asked by
Miriam
Top achievements
Rank 1
Answers by
Miriam
Top achievements
Rank 1
Mihail
Telerik team
Share this question
or