Free Support Forum - aspose.com

Different font sizes and boldnesses in a paragraph

I am creating a work doc The first line is a subheading and it is bold. There are N pages in the report and each are basically the same usually. I cannot use a template document because there will be occasions when there will be differences between the pages. Now the problem: Only the last page has the correct format and if there is only one page, the formatting is wrong. Parts of the first paragraph are bold when they should not be. The font type seem to always be correct but the size is not. It does not seem to be random, but in a strange pattern where some test is correct and the next line is big and bold. Any ideas?

here is the code.

internal static class Education

{

///

/// Create a report section for each education item

///

/// DcoumentBuilder

/// ItemEducation

public static void CreateEntry(DocumentBuilder builder, ItemEducation itemEd)

{

SetFontCharacteristics(builder, false, "Times New Roman", 12);

builder.Writeln("");

//make sure the text is inserted into the correct place

builder.MoveToDocumentStart();

CreateEducationHeading(builder);

CreateVerificationEntry(builder);

CreateSchoolInfoEntry(builder, itemEd);

CreateAdditionalInfoEntry(builder);

CreateCommentsEntry(builder);

}

private static void SetFontCharacteristics(DocumentBuilder builder, bool isBold, string fontType, int size)

{

//Clear the formatting before each format change to ensure there are not remnants for an earlier format.

builder.Font.ClearFormatting();

builder.Font.Bold = isBold;

builder.Font.Color = System.Drawing.Color.Black;

builder.Font.Name = fontType;

builder.Font.Size = size;

}

private static void CreateEducationHeading(DocumentBuilder builder)

{

SetFontCharacteristics(builder, true, "Courier", 16);

builder.Writeln("V EDUCATION");

builder.Font.ClearFormatting();

builder.Writeln("");

builder.InsertParagraph();

}

private static void CreateCommentsEntry(DocumentBuilder builder)

{

SetFontCharacteristics(builder, true, "Courier", 12);

builder.Writeln("");

builder.Writeln("COMMENTS");

builder.Writeln("");

builder.InsertParagraph();

SetFontCharacteristics(builder, false, "Times New Roman", 12);

}

private static void CreateAdditionalInfoEntry(DocumentBuilder builder)

{

SetFontCharacteristics(builder, true, "Courier", 12);

builder.Writeln("");

builder.Writeln("Additional Information ");

builder.Writeln("");

SetFontCharacteristics(builder, false, "Courier", 12);

builder.Write("Academic Ranking / GPA : ");

builder.Writeln("");

builder.Write("Credit Hours Earned : ");

builder.Writeln("");

builder.Write("Awards of Honors : ");

builder.Writeln("");

builder.Write("Membership in Organizations : ");

builder.Writeln("");

builder.Write("Conduct : ");

builder.Writeln("");

builder.InsertParagraph();

}

private static void CreateSchoolInfoEntry(DocumentBuilder builder, ItemEducation itemEd)

{

SetFontCharacteristics(builder, false, "Times New Roman", 12);

builder.Writeln(" SUBJECT’s attendance at the below listed school has been verified.");

SetFontCharacteristics(builder, false, "Courier", 12);

builder.Write("Name of School : ");

builder.Writeln(itemEd.SchoolName);

builder.Write("Address : ");

builder.Writeln(itemEd.SchoolAddress.Street1 + " " + itemEd.SchoolAddress.City + ", " + itemEd.SchoolAddress.State + " " + itemEd.SchoolAddress.Zipcode);

builder.Write("Dates of Attendance : ");

builder.Write(itemEd.DateRange.From.ToShortDateString() + " - ");

if (itemEd.DateRange.To.HasValue)

{

builder.Writeln(itemEd.DateRange.To.Value.ToShortDateString());

}

else

{

builder.Write("Present");

}

builder.Write("Degree Earned : ");

if (itemEd.Certificate != null)

{

builder.Writeln(itemEd.Certificate);

}

else

{

builder.Writeln("N/A");

}

builder.Write("Date of Degree : ");

if (itemEd.CertificateAwardedDate.HasValue)

{

builder.Writeln(itemEd.CertificateAwardedDate.Value.ToShortDateString());

}

else

{

builder.Writeln("N/A");

}

builder.InsertParagraph();

}

private static void CreateVerificationEntry(DocumentBuilder builder)

{

SetFontCharacteristics(builder, false, "Courier", 12);

builder.Write("Date Verified: ");

builder.Write(DateTime.Today.ToShortDateString());

builder.Write(" Records received from: ");

builder.Writeln("Tom");

builder.Writeln("");

SetFontCharacteristics(builder, false, "Wingdings 2", 20);

builder.Write("T");

}

}

I looked at your code and at the resulting document and it seems all correct to me. Whenever you call your SetFontCharacteristics, the font gets set properly and all further text is output using that formatting until you call ClearFormatting or another SetFontCharacteristics.

If you still think there is something wrong, please let me know exactly what paragraph/line/word is not correct and what you expect it to be.