We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Header and Footer alignment

Hi there!

I need alignment: Left, and Right - withing 1 row or Paragraph in the Header and Footer.

Please have a look at attached picture ParagraphAlignment1.jpg - that’s how I want it to be.

ParagraphAlignment2.jpg - shows how it’s now being built by the code:

private void BuildHeader(DocumentBuilder builder, int iReportID, BusinessFacade busFacade, out DataRow drHeaderFooter, System.Drawing.Image CompanyLogoSystemsthinkingHeader)
{
    drHeaderFooter = null;
    builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

    builder.ParagraphFormat.ClearFormatting();
    builder.ParagraphFormat.KeepTogether = false;
    builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
    builder.ParagraphFormat.SpaceBeforeAuto = false;
    builder.ParagraphFormat.SpaceAfterAuto = false;
    builder.ParagraphFormat.SpaceBefore = 0;
    builder.ParagraphFormat.SpaceAfter = 0;
    builder.ParagraphFormat.LineSpacing = 0;
    builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.AtLeast;

    builder.StartTable();
    builder.InsertCell();
    builder.CellFormat.ClearFormatting();

    //if (SmallHeaderImage == null) // Small header image for report
    //{

    // string sImagePath = Server.MapPath("~/ClientImages/CompanyLogoSystemsthinkingHeader.png");
    // System.Drawing.Image imgCompany = System.Drawing.Image.FromFile(sImagePath);
    // docBuilder.BuildCoverPage(ref builder, iReportID, imgCompany);

    // SmallHeaderImage = busFacade.GetImage((int)Images.HeaderImage);
    //}

    //if (SmallHeaderImage != null && SmallHeaderImage.Length > 0)
    //{
    // builder.InsertImage(SmallHeaderImage);
    //}

    builder.InsertImage(CompanyLogoSystemsthinkingHeader);

    builder.InsertCell();
    builder.Font.Bold = true;
    builder.Font.Color = Color.Gray;
    //builder.CellFormat.Width = 600;
    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
    builder.CellFormat.TopPadding = 0;
    builder.CellFormat.BottomPadding = 0;
    //builder.RowFormat.Alignment = RowAlignment.Right;

    DataTable dtHeaderFooter = busFacade.GetReportPageHeaderAndFooterText(iReportID);
    string sHeader = string.Empty;

    if (dtHeaderFooter.Rows.Count > 0)
    {
        drHeaderFooter = dtHeaderFooter.Rows[0];
        sHeader = drHeaderFooter["reportHeaderText"].ToString();
        builder.Font.Name = drHeaderFooter["reportHeaderTextFontName"].ToString();
        builder.Font.Size = Convert.ToDouble(drHeaderFooter["reportHeaderTextFontSize"].ToString());
        builder.Font.Bold = (bool)drHeaderFooter["reportHeaderTextFontDecorationBold"];
        builder.Font.Italic = (bool)drHeaderFooter["reportHeaderTextFontDecorationItalic"];
        builder.Font.Color = GetColorFromStringName(drHeaderFooter["reportHeaderTextFontDecorationColour"].ToString());

        bool bHeaderUnderline = (bool)drHeaderFooter["reportHeaderTextFontDecorationUnderline"];
        if (bHeaderUnderline)
        {
            builder.Font.Underline = Underline.Single;
        }
    }

    string sCompanyName = busFacade.GetCompanyName(1); // TODO: Company ID and Company name should be supplied later
    sHeader = ReplaceString(sHeader, sCompanyName);

    builder.ParagraphFormat.ClearFormatting();
    builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
    builder.Write(sHeader);
    builder.EndRow();
    builder.EndTable();
}

Hi Alex,

Thanks for your inquiry.

The basis of your code is correct. To layout the content as you want in your screenshot you just need to include another cell. Please see the code below which shows how to achieve this. I have added some code so that the cells are created with sizes relative to the page width.

// Get the page width
Section currentSection = builder.CurrentSection;
double pageWidth = pageWidth = currentSection.PageSetup.PageWidth - (currentSection.PageSetup.LeftMargin + currentSection.PageSetup.RightMargin);
builder.StartTable();
// Insert the left content
builder.InsertCell();
builder.CellFormat.ClearFormatting();
builder.CellFormat.Width = pageWidth / 6;
builder.InsertImage(CompanyLogoSystemsthinkingHeader);
// Insert the middle content
builder.InsertCell();
builder.CellFormat.Width = pageWidth / 1.5;
// Settings here
builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Write(sHeader);
// Insert right content
builder.InsertCell();
builder.CellFormat.Width = pageWidth / 6;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.Write("Text");
builder.EndRow();
builder.EndTable();

Thanks,

Thanks Adam,
that did the job.