Click here to Skip to main content
15,898,587 members
Home / Discussions / Article Writing
   

Article Writing

 
Questionhow to report possible plagiarism? Pin
taber loveless20-Jul-10 9:03
taber loveless20-Jul-10 9:03 
AnswerRe: how to report possible plagiarism? Pin
Luc Pattyn20-Jul-10 9:43
sitebuilderLuc Pattyn20-Jul-10 9:43 
QuestionArticle submission query Pin
nbugalia18-Jul-10 3:57
nbugalia18-Jul-10 3:57 
AnswerRe: Article submission query Pin
Chris Maunder18-Jul-10 4:10
cofounderChris Maunder18-Jul-10 4:10 
GeneralRe: Article submission query Pin
nbugalia18-Jul-10 4:18
nbugalia18-Jul-10 4:18 
GeneralRe: Article submission query Pin
nbugalia20-Jul-10 1:54
nbugalia20-Jul-10 1:54 
GeneralRe: Article submission query Pin
Sean Ewington20-Jul-10 2:46
staffSean Ewington20-Jul-10 2:46 
QuestionC# RTF constructor library Pin
Dima Popov13-Jul-10 4:24
Dima Popov13-Jul-10 4:24 
I wrote a RTF document constructor library in C# almost a year ago. I planned to post an article but never had the time and, in fact, I got bored of writing the library itself. The point was creating reports with clean formatted tables, and I could find no free solutions capable of that.

I'm sorry for being too lazy to write even a good example. But here is something to look at:
C#
private RtfDocument rtf = new RtfDocument(RtfCodePage.Windows1251);
private static RtfFont DefaultFont = new RtfFont("Times New Roman", RtfCharacterSet.Russian, RtfFontFamily.Roman, RtfFontPitch.Variable);

private static RtfParagraphFormatting
    Centered12 = new RtfParagraphFormatting(RtfLanguage.Russian, 12F, RtfTextAlign.Center),
    LeftAligned12 = new RtfParagraphFormatting(RtfLanguage.Russian),
    Centered10 = new RtfParagraphFormatting(RtfLanguage.Russian, 10F, RtfTextAlign.Center);

private static RtfTableCellStyle
    LeftAligned12NoBorder = new RtfTableCellStyle(RtfBorderSetting.None, LeftAligned12),
    Centered12NoBorder = new RtfTableCellStyle(RtfBorderSetting.None, Centered12),
    Centered10AllBordersVertical = new RtfTableCellStyle(RtfBorderSetting.All, Centered10, RtfTableCellVerticalAlign.Center, RtfTableCellTextFlow.LeftToRightBottomToTop);

public RtfExample()
{
    RtfFormattedParagraph
        empty = new RtfFormattedParagraph(LeftAligned12),

        p1fp1 = new RtfFormattedParagraph(Centered12),
        p2fp1 = new RtfFormattedParagraph(LeftAligned12);

    RtfTableRow
        p1tr1 = new RtfTableRow(RtfTableAlign.Center);

    rtf.DefaultLanguage = RtfLanguage.Russian;

    rtf.FontTable.Add(DefaultFont);

    empty.IsFormattingIncluded = false;
    empty.AppendParagraph();

    p1tr1.Cells.AddRange(new RtfTableCell[] {
        new RtfTableCell(5.5F, "A table cell", Centered12NoBorder),
        new RtfTableCell(8.75F, "Another table cell", Centered12NoBorder),
    });

    p1fp1.AppendParagraph(new RtfFormattedText("Sort of header", RtfCharacterFormatting.Bold));
    p1fp1.AppendParagraph();
    p1fp1.AppendParagraph();

    p2fp1.AppendParagraph("Paragraph text");
    p2fp1.AppendParagraph();

    //Etc.

    rtf.Contents.AddRange(new IRtfDocumentPart[] {
        p1fp1,
        p1tr1,
        new RtfPageBreak(),
        p2fp1,
        empty,
    });
}

The conversion to RTF is made using Reflection as the classes have attributes with RTF control words, so the library can be easily expanded (I did not implement the complete RTF Specification). Classes are well documented and self-explanatory.
C#
    /// <summary>
/// Represents a border.
/// </summary>
public class RtfBorder
{
    /// <summary>
    /// Border width in twips.
    /// </summary>
    [RtfControlWord("brdrw")]
    public int Width = 10;

    /// <summary>
    /// Border style.
    /// </summary>
    [RtfControlWord]
    public RtfBorderStyle Style = RtfBorderStyle.SingleThicknessBorder;

    /// <summary>
    /// Index of entry in the color table. Default is -1 and is ignored by RtfWriter.
    /// </summary>
    [RtfControlWord("brdrcf"), RtfIndex]
    public int ColorIndex = -1;

    /// <summary>
    /// Sets the properties of the current border.
    /// </summary>
    /// <param name="width">Width in points.</param>
    /// <param name="style">Border style.</param>
    /// <param name="colorIndex">Index of entry in the color table.</param>
    public void SetProperties(float width, RtfBorderStyle style, int colorIndex)
    {
        Width = TwipConverter.ToTwip(width, MetricUnit.Point);
        Style = style;
        ColorIndex = colorIndex;
    }

    /// <summary>
    /// Copy all the properties of the current border to specified ESCommon.Rtf.RtfBorder object.
    /// </summary>
    /// <param name="border">Border object to copy to.</param>
    public void CopyTo(RtfBorder border)
    {
        border.Width = this.Width;
        border.Style = this.Style;
        border.ColorIndex = this.ColorIndex;
    }
}


Please contact me if you are interested in writing an article about the library or just want to have the source.

modified on Wednesday, July 14, 2010 2:13 AM

AnswerRe: C# RTF constructor library Pin
BillWoodruff27-Jul-10 4:01
professionalBillWoodruff27-Jul-10 4:01 
GeneralRe: C# RTF constructor library Pin
Dima Popov30-Jul-10 4:10
Dima Popov30-Jul-10 4:10 
QuestionShould I re-write old Article or Post New Article? Pin
The Man from U.N.C.L.E.1-Jul-10 1:42
The Man from U.N.C.L.E.1-Jul-10 1:42 
AnswerRe: Should I re-write old Article or Post New Article? Pin
Luc Pattyn1-Jul-10 2:34
sitebuilderLuc Pattyn1-Jul-10 2:34 
GeneralRe: Should I re-write old Article or Post New Article? Pin
The Man from U.N.C.L.E.1-Jul-10 5:22
The Man from U.N.C.L.E.1-Jul-10 5:22 
QuestionUpdating code for an old article Pin
David Maw19-Jun-10 14:19
David Maw19-Jun-10 14:19 
AnswerRe: Updating code for an old article Pin
Luc Pattyn19-Jun-10 16:19
sitebuilderLuc Pattyn19-Jun-10 16:19 
GeneralRe: Updating code for an old article Pin
David Maw20-Jun-10 7:41
David Maw20-Jun-10 7:41 
GeneralRe: Updating code for an old article Pin
Luc Pattyn20-Jun-10 7:48
sitebuilderLuc Pattyn20-Jun-10 7:48 
GeneralRe: Updating code for an old article Pin
David Maw20-Jun-10 12:28
David Maw20-Jun-10 12:28 
GeneralRe: Updating code for an old article Pin
Luc Pattyn20-Jun-10 13:09
sitebuilderLuc Pattyn20-Jun-10 13:09 
QuestionHow do I get my images to show on my article? Pin
Mr Yossu9-Jun-10 2:30
Mr Yossu9-Jun-10 2:30 
AnswerRe: How do I get my images to show on my article? Pin
Luc Pattyn9-Jun-10 4:36
sitebuilderLuc Pattyn9-Jun-10 4:36 
GeneralRe: How do I get my images to show on my article? Pin
Mr Yossu9-Jun-10 6:36
Mr Yossu9-Jun-10 6:36 
AdminNew article format Pin
Chris Maunder7-Jun-10 13:27
cofounderChris Maunder7-Jun-10 13:27 
GeneralRe: New article format Pin
Richard MacCutchan8-Jun-10 23:21
mveRichard MacCutchan8-Jun-10 23:21 
GeneralRe: New article format Pin
Luc Pattyn9-Jun-10 2:48
sitebuilderLuc Pattyn9-Jun-10 2:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.