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

DOCX to PDF conversion

9 Answers 1450 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 23 Nov 2014, 11:10 PM
Hi

According to this thread it is possible to convert a DOCX file to a PDF. The code there no longer seems to work however.

The code I'm trying to run is:

RadDocument document = null;
IDocumentFormatProvider providerDocx = (IDocumentFormatProvider) new DocxFormatProvider();
using (FileStream stream = File.Open(@"C:\Test.docx", FileMode.Open))
{
    document = providerDocx.Import(stream);
}
 
PdfFormatProvider providerPdf = new PdfFormatProvider();
using (Stream output = File.Open(@"C:\Test.pdf", FileMode.Create))
{
    providerPdf.Export(document, output);
}


The error occurs on the last line: cannot convert from 'Telerik.Windows.Documents.Model.RadDocument' to 'Telerik.Windows.Documents.Fixed.Model.RadFixedDocument'

Is it still possible to convert from docx to PDF?
Tanya
Telerik team
commented on 04 Oct 2021, 07:10 AM

Hi Chris,

Yes, you can convert RadDocument to PDF. Looking at the error you get, it seems like the wrong class is being used. Please, make sure to add a using statement for the Telerik.Windows.Documents.FormatProviders.Pdf namespace and use the PdfFormatProvider from this namespace. More details about this functionality are available at https://docs.telerik.com/devtools/wpf/controls/radrichtextbox/import-export/pdf/pdfformatprovider

Tomáš
Top achievements
Rank 1
Iron
Iron
commented on 12 Oct 2021, 12:17 PM

Hi @Tanya,

After almost 6 years of this question being unanswered, I created answer which addresses this question. And you came 5 days later, creating comment that is stating absolutely the same as in my answer? 
Are you getting some credit for this or what? What's the point of this?
I really don't get this approach.

Tanya
Telerik team
commented on 12 Oct 2021, 02:59 PM

Hi Tomáš,

Excuse me for that misunderstanding. The question popped out as new and I answered it without paying attention to your post thinking it is an old one. And no, I don't get any credit or points for that, it was confusion from my side. Please, accept my apologies. 

9 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 26 Nov 2014, 06:00 PM
Hi Chris,

RadPdfProcessing does not provide an option to convert flow document (e.g. DOCX) to fixed format, although we are working on implementing such functionality. At this point such conversion can only be achieved using the assemblies shipped with RadRichTextBox and the code you found on the forums.

As to the error you are experiencing, the PdfFormatProvider class that can export a RadDocument instance to PDF is located in the Telerik.Windows.Documents.FormatProviders.Pdf assembly. Please refer to this help article for additional information on the assemblies you need to add to your project in order to use the control.

It seems the provider instance you are creating is from the Telerik.Windows.Documents.Fixed.dll and relates to the new RadPdfProcessing library. Like I said, the library does not allow for conversion of flow documents for now, but you can follow this item in the public portal to be notified when the feature is available.

Do not hesitate to contact us if you have any additional questions.

Regards,
Petya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Nils C.
Top achievements
Rank 1
answered on 19 Mar 2015, 10:39 AM
Hi, 

in your Blogpost is announced: PdfProcessing and WordsProcessing now enable seamless conversion of DOCX/RTF/HTML documents to PDF

Do you have an example for that?

Best 

Nils
0
Petya
Telerik team
answered on 19 Mar 2015, 04:52 PM
Hi Nils,

There is an example of this in our online demos for WordsProcessing called Export to PDF.

The basic idea is that you need to use the HtmlFormatProvider /DocxFormatProvider/ RtfFormatProvider to create a RadFlowDocument. Then, use the PdfFormatProvider to export the document to a PDF stream.

Let us know if you face any difficulties with this.

Regards,
Petya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Igor
Top achievements
Rank 1
answered on 09 Sep 2015, 01:10 PM

[quote]Petya said:Hi Nils,

There is an example of this in our online demos for WordsProcessing called Export to PDF.

The basic idea is that you need to use the HtmlFormatProvider /DocxFormatProvider/ RtfFormatProvider to create a RadFlowDocument. Then, use the PdfFormatProvider to export the document to a PDF stream.[/quote] 

Petya, I try to make docx - pdf conversion in my project. Namespace Telerik.Windows.Documents.Flow.FormatProviders does not contain namespace Pdf. Was it changed? Am I missing some reference?

0
Igor
Top achievements
Rank 1
answered on 09 Sep 2015, 04:54 PM
Figured it out. I needed reference to Telerik.Windows.Documents.Flow.FormatProviders.Pdf.dll
0
Shahbaz
Top achievements
Rank 1
answered on 18 Sep 2015, 10:21 AM

hello,

did you manage to convert docx to pdf. can you please share the sample code. i am trying to do the same using Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf but can't get proceed.

thanks..

0
Igor
Top achievements
Rank 1
answered on 20 Sep 2015, 12:37 PM

https://dotnetfiddle.net/tAxzgN

I hid reference to my employer project namespaces.​

Fell free to advice any improvements (=

 

0
gurpreet
Top achievements
Rank 1
answered on 07 Dec 2016, 11:33 AM

RadDocument document = null;
                    IDocxFormatProvider providerDocx = new DocxFormatProvider();
                    using (FileStream stream = File.Open(@"C:\Test.docx", FileMode.Open))
                    {
                        document = providerDocx.Import(stream);
                    }
                    PdfFormatProvider providerPdf = new PdfFormatProvider();
                    using (Stream output = File.Open(@"C:\Test.pdf", FileMode.Create))
                    {
                        providerPdf.Export(document, output);
                    }

 

Error 2  The type or namespace name 'Rad Document' could not be found (are you missing a using directive or an assembly reference? )

any one help me

i am install the Telerik UI for asp.net mvc and add the assembly  "Telerik.Windows.Documents.Core'' and "Telerik.Windows.Documents.Flow.FormatProviders.Pdf"

 

0
Tomáš
Top achievements
Rank 1
Iron
Iron
answered on 30 Sep 2021, 12:45 PM

To all of you, who cannot get this to work, you need to use specific DocxFormatProvider and PdfFormatProvider.

(There are at least 2 versions of both of them in Telerik DLLs.)

 

/*
 * Reference: Telerik.Windows.Documents.FormatProviders.OpenXml.dll
 * FullName: Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider
 */
var providerDocx = new DocxFormatProvider();

/*
 * Reference: Telerik.Windows.Documents.FormatProviders.Pdf.dll
 * FullName: Telerik.Windows.Documents.FormatProviders.Pdf.PdfFormatProvider
 */
var providerPdf = new PdfFormatProvider();

// use any Import method, you like (you can read file and import stream if you like)
var document = providerDocx.Import(docxBytes);

// use any Export method you like (you can export stream and write it to file if you like)
return providerPdf.Export(document);

Tags
PdfProcessing
Asked by
Chris
Top achievements
Rank 1
Answers by
Petya
Telerik team
Nils C.
Top achievements
Rank 1
Igor
Top achievements
Rank 1
Shahbaz
Top achievements
Rank 1
Igor
Top achievements
Rank 1
gurpreet
Top achievements
Rank 1
Tomáš
Top achievements
Rank 1
Iron
Iron
Share this question
or