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

Export Exception

2 Answers 114 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 10 Feb 2011, 06:20 PM
using this document:
<t:RadDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:t="clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents" version="1.0" DefaultPageLayoutSettings="793.6667,1122.467" LayoutMode="Paged" PageViewMargin="10,10">
  <t:Section PageMargin="72,96,72,96">
    <t:Paragraph Background="#00FFFFFF">
      <t:Span Text="HIHUIHIUGYUFYFGFGHGHJJHKJHJKHKJHKLK "></t:Span>
      <t:Hyperlink FontFamily="Verdana" ForeColor="#FF000000" HighlightColor="#00FFFFFF" Target="Blank" Text="(...) P.F. Preencher" UnderlineDecoration="None" URL="DIAS_DESCARGA"></t:Hyperlink>
      <t:Span Text=" "></t:Span>
    </t:Paragraph>
    <t:Paragraph Background="#00FFFFFF">
      <t:Span FontWeight="Bold" Text="CLÁUSULA QUINTA - DA TAXA DE RETORNO "></t:Span>
      <t:Span Text="  "></t:Span>
    </t:Paragraph>
    <t:Paragraph Background="#00FFFFFF" TextAlignment="Justify">
      <t:Span Text="A título de incentivo pela manutenção e participação de produtos cadastrados, as partes ajustam uma taxa de retorno de "></t:Span>
      <t:Hyperlink FontFamily="Verdana" ForeColor="#FF000000" HighlightColor="#00FFFFFF" Target="Blank" Text="(...) P.F. Preencher" UnderlineDecoration="None" URL="TAXA_RETORNO"></t:Hyperlink>
      <t:Span HighlightColor="#00FFFFFF" Text=" %"></t:Span>
      <t:Span Text=" ("></t:Span>
      <t:Hyperlink FontFamily="Verdana" ForeColor="#FF000000" HighlightColor="#00FFFFFF" Target="Blank" Text="(...) P.F. Preencher" UnderlineDecoration="None" URL="TAXA_RETORNO_TEXT"></t:Hyperlink>
      <t:Span Text=" ), incidente sobre o valor total das notas fiscais, que será cobrado pelo "></t:Span>
      <t:Span FontWeight="Bold" Text="COMPRADOR "></t:Span>
      <t:Span Text="via "></t:Span>
      <t:Hyperlink FontFamily="Verdana" ForeColor="#FF000000" HighlightColor="#00FFFFFF" Target="Blank" Text="(...) P.F. Preencher" UnderlineDecoration="None" URL="PAYMENT_METHOD"></t:Hyperlink>
      <t:Span Text="  a ser concedido pelo "></t:Span>
      <t:Span FontWeight="Bold" Text="FORNECEDOR "></t:Span>
      <t:Span Text="em cada operação de compra. "></t:Span>
    </t:Paragraph>
    <t:Paragraph Background="#00FFFFFF" TextAlignment="Justify"></t:Paragraph>
    <t:Paragraph Background="#00FFFFFF" TextAlignment="Justify"></t:Paragraph>
  </t:Section>
</t:RadDocument>

DocxFormatProvider provider = new DocxFormatProvider();
 using (Stream output = saveDialog.OpenFile())
 {
 provider.Export(EditorPrint.Document, output); --> returns an exception **
}


**
System.NullReferenceException: FromElement must not be null.
   em Telerik.Windows.Documents.Model.DocumentElement.CopyPropertiesFrom(DocumentElement fromElement)
   em Telerik.Windows.Documents.Model.Span..ctor(Span originalSpan)
   em Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Export.MainDocumentExporter.ExportParagraphMark(Paragraph paragraph)
   em Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Export.MainDocumentExporter.ExportParagraphProperties(Paragraph paragraph)
   em Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Export.MainDocumentExporter.ExportParagraph(Paragraph paragraph)
   em Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Export.MainDocumentExporter.ExportBlock(Block block)
   em Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Export.MainDocumentExporter.Export()
   em Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Export.DocxExporter.AddXmlContentToPackage(DocxPartExporterBase exporter)
   em Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Export.DocxExporter.Export()
   em Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider.Export(RadDocument document, Stream output)
   em TSB_Test.Content.Contracts.ContractDialog.RadRibbonButton_Click(Object sender, RoutedEventArgs e)}


It works fine with the same code but for pdf provider.
Even more strange if I export first as pdf and then as docx it works... any idea why?

2 Answers, 1 is accepted

Sort by
0
Marco
Top achievements
Rank 1
answered on 14 Feb 2011, 11:15 AM
Any solution or explanation for this behaviour?
What libraries should be set on xaml and on c#?
0
Iva Toteva
Telerik team
answered on 14 Feb 2011, 12:09 PM
Hi Marco,

After the document is first created or imported, it needs to be measured and arranged before it can be exported. It is automatically measured and arranged when you show it in a RadRichTextBox, but if you are only using it in code-behind, you need to manually invoke the following function before the export:

private void MeasureAndArrangeInDefaultSize(RadDocument document)
{
    document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
    document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
}

Please let us know if that does not solve the problem.

Regards,
Iva
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
RichTextBox
Asked by
Marco
Top achievements
Rank 1
Answers by
Marco
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or