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

Export to docx problem

3 Answers 109 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Luciano
Top achievements
Rank 1
Luciano asked on 17 Aug 2010, 08:45 AM
Hi, I want generate Document with two Section, One Calculate widht Image and one Document from Db.
The Code:

 

RadDocument doc = new RadDocument();

Telerik.Windows.Documents.Model.Section section1 = new Telerik.Windows.Documents.Model.Section();
 

Telerik.Windows.Documents.Model.Paragraph paragraphImage = new Telerik.Windows.Documents.Model.Paragraph();

Stream stream = Application.GetResourceStream(new Uri(@"/AttiDirigenziali;component/Views/Immagini/Stemma.jpg", UriKind.RelativeOrAbsolute)).Stream;

 
Size size = new Size(226, 110);
 

ImageInline image1 = new ImageInline(stream, size, "jpg");
 

paragraphImage.Inlines.Add(image1);

section1.Paragraphs.Add(paragraphImage);

doc.Sections.Add(section1);
 

RadDocument docCorpo = null;

IDocumentFormatProvider provider = new DocxFormatProvider();

Stream s = new MemoryStream(e.Result); //e.result is Document from Db
 

docCorpo = provider.Import(s);

doc.Sections.Add(docCorpo.Sections.First());

 
IDocumentFormatProvider providerPdf = new DocxFormatProvider();

 
MemoryStream output = new MemoryStream();

providerPdf.Export(doc, output);

 

 


Error:
Impossibile eseguire il cast di oggetti di tipo 'Telerik.Windows.Documents.Model.ImageInline' sul tipo 'Telerik.Windows.Documents.Model.Span'.
Thanks



3 Answers, 1 is accepted

Sort by
0
Alex
Telerik team
answered on 18 Aug 2010, 03:05 PM
Hi Luciano,

Unfortunately we were unable to reproduce the problem. It will be helpful if you send us a project that in which the issue is present so we can investigate the problem.

However, I would suggest a simpler solution for you task. You can use the InsertInline method of RadDocument class to insert the image at the beginning of the document. Here is a code snippet:

Stream ImageStream = Application.GetResourceStream(new Uri(@"/MSWordDemo;component/Images/smile.jpg", UriKind.RelativeOrAbsolute)).Stream;
ImageInline imageInline = new ImageInline(ImageStream, new Size(226, 110), "jpg");
  
docCorpo.InsertInline(imageInline);
docCorpo.InsertInline(new Span(FormattingSymbolLayoutBox.ENTER));

This will add the image in a separate paragraph.

I hope this is helpful. Please let us know if you need further assistance.

Regards,
Alex
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Luciano
Top achievements
Rank 1
answered on 19 Aug 2010, 02:36 PM

 

 

RadDocument doc = new RadDocument();

 

 

 

Stream ImageStream = Application.GetResourceStream(new Uri(@"/TestTelerikExportImage;component/Stemma.jpg", UriKind.RelativeOrAbsolute)).Stream;

 

 

 

ImageInline imageInline = new ImageInline(ImageStream, new Size(226, 110), "jpg");

 

doc.InsertInline(imageInline);

/// Error

 


I work on the fly with raddocument for generate document pdf with my wcf.


Thanks, Luciano

 

 

 


 

0
Ivailo Karamanolev
Telerik team
answered on 19 Aug 2010, 02:41 PM
Hi Luciano,

Looking at your code, my only suggestion is to check if ImageStream isn't null by any chance, or if Stemma.jpg is an invalid image (may be other image format like bmp, png, or gif that was renamed to jpg). Without looking at the complete solution (not just code fragments), unfortunately, I can't give you any more clues.
Get back to us if you need further assistance, preferably with a sample solution which demonstrates your problem. You can open a support ticket where you will be able to attach a zipped version of your solution.

Best wishes,
Ivailo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Luciano
Top achievements
Rank 1
Answers by
Alex
Telerik team
Luciano
Top achievements
Rank 1
Ivailo Karamanolev
Telerik team
Share this question
or