Export Exception

3 posts, 0 answers
  1. Marco
    Marco avatar
    21 posts
    Member since:
    Aug 2010

    Posted 10 Feb 2011 Link to this post

    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. Marco
    Marco avatar
    21 posts
    Member since:
    Aug 2010

    Posted 14 Feb 2011 Link to this post

    Any solution or explanation for this behaviour?
    What libraries should be set on xaml and on c#?
  3. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 14 Feb 2011 Link to this post

    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>>
Back to Top