Completed
Last Updated: 10 Jun 2016 05:01 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 08 Mar 2016 13:46
Category: RichTextEditor
Type: Bug Report
1
FIX. RadRichTextEditor - bold text is not exported correctly with the PdfFormatProvider
To reproduce:

private void radButton1_Click(object sender, EventArgs e)
{
    var document = new RadDocument(); 
    var section = new Section();
    document.Sections.Add(section);
    var paragraph = new Paragraph();
    section.Blocks.Add(paragraph);
    var span = new Span("BOLD");
    span.FontWeight = FontWeights.Bold;
    paragraph.Inlines.Add(span);

    span = new Span(" REGULAR");
    paragraph.Inlines.Add(span);

    editor.Document = document;

    var pdfExporter = new PdfFormatProvider();
    var path = Path.GetTempFileName() + ".pdf";
    using (var file = File.Create(path))
    {
        pdfExporter.Export(document, file);
        file.Flush();
        file.Close();
        
    }
    Process.Start(path);
}

Workaround: export .docx file and use the RadWordsProcessing library to import the .doc file and export it to pdf:

private void radButton1_Click(object sender, EventArgs e)
{
    var document = new RadDocument();
    var section = new Section();
    document.Sections.Add(section);
    var paragraph = new Paragraph();
    section.Blocks.Add(paragraph);
    var span = new Span("BOLD");
    span.FontWeight = FontWeights.Bold;
    paragraph.Inlines.Add(span);

    span = new Span(" REGULAR");
    paragraph.Inlines.Add(span);

    editor.Document = document;

    var wordExporter = new Telerik.WinForms.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider();
    var wordPath = Path.GetTempFileName() + ".doc";
    using (var file = File.Create(wordPath))
    {
        wordExporter.Export(document, file);
        file.Flush();
        file.Close();
    }

    Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider provider =
        new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
    using (Stream input = File.OpenRead(wordPath))
    {
        Telerik.Windows.Documents.Flow.Model.RadFlowDocument doc = provider.Import(input);

        Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider pdfProvider =
            new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
        string filePath = @"..\..\" + DateTime.Now.ToLongTimeString().Replace(":", "-");
        using (var output = File.Create(filePath))
        {
            pdfProvider.Export(doc, output);
        }
        Process.Start(filePath);
    }
}
0 comments