Other content overlaps header

Hey Support,

I am still having trouble dealing with the new way Aspose.PDF handles headers. From my testing so far it looks like unless specified specifically anything added to pages’ paragraphs after creating the header just overlaps the header completely like it doesn’t exist.

Here’s a sample console job that adds a header with some basic information. Once AddInvoiceSummary is called that paragraph just overlaps the header instead of fitting underneath it. Is there some sort of option to set it so there isn’t overflow?

using Aspose.Pdf;
using Aspose.Pdf.Text;
using System.Net;


// ExStart:1
// The path to the documents directory.
string dataDir = @"C:\Users\Public\";

// Instantiate a Document object by calling its empty constructor
Aspose.Pdf.Document pdf1 = new Aspose.Pdf.Document();
// Create a page in the Pdf object
Aspose.Pdf.Page page = pdf1.Pages.Add();
// Create Header Section of the document
Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
// Set the header for the PDF file
page.Header = header;

//header.Margin.Right = 10;

var addressTable = new Table();
addressTable.HorizontalAlignment = HorizontalAlignment.FullJustify;
addressTable.VerticalAlignment = VerticalAlignment.Bottom;
addressTable.Left = 130;
addressTable.Top = 30;
var firstLine = new TextFragment("QA QuickBooks Online");
var secondLine = new TextFragment("123456 Drive Suite 2300");
var thirdLine = new TextFragment("City, IL 60606");

var firstRow = new Row();
var secondRow = new Row();
var thirdRow = new Row();
var firstCell = new Cell();
var secondCell = new Cell();
var thirdCell = new Cell();

firstCell.Paragraphs.Add(firstLine);
secondCell.Paragraphs.Add(secondLine);
thirdCell.Paragraphs.Add(thirdLine);

firstRow.Cells.Add(firstCell);
secondRow.Cells.Add(secondCell);
thirdRow.Cells.Add(thirdCell);

addressTable.Rows.Add(firstRow);
addressTable.Rows.Add(secondRow);
addressTable.Rows.Add(thirdRow);
// Create a Text object
Aspose.Pdf.Text.TextFragment txt1 = new Aspose.Pdf.Text.TextFragment("Aspose.Pdf is a Robust component by");
// Specify the color
txt1.TextState.ForegroundColor = Color.Blue;
txt1.IsInLineParagraph = true;

addressTable.ColumnAdjustment = ColumnAdjustment.AutoFitToContent;

// Create an image object in the section
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
// Set the path of image file
image1.ImageStream = HelperFunctions.GetPlaceholderImage();
// Set the image width Information
image1.FixWidth = 150;
image1.FixHeight = 100;
// Indicate seg1's InlineParagraph is a image.
image1.IsInLineParagraph = false;
image1.HorizontalAlignment = HorizontalAlignment.FullJustify;

var imageTable = new Aspose.Pdf.Table();
var imageRow = new Aspose.Pdf.Row();
var imageCell = new Aspose.Pdf.Cell();

imageCell.Paragraphs.Add(image1);
imageRow.Cells.Add(imageCell);
imageTable.Rows.Add(imageRow);

imageTable.Left = 25;
imageTable.Top = 25;

var companyTable = new Aspose.Pdf.Table();
var companyRow1 = new Aspose.Pdf.Row();
var companyRow2 = new Aspose.Pdf.Row();
var companyRow3 = new Aspose.Pdf.Row();
firstCell = new Aspose.Pdf.Cell();
secondCell = new Aspose.Pdf.Cell();
thirdCell = new Aspose.Pdf.Cell();

firstLine = new TextFragment("ABC Company");
secondLine = new TextFragment("Building 100");
thirdLine = new TextFragment("Suite 23");

firstCell.Paragraphs.Add(firstLine);
secondCell.Paragraphs.Add(secondLine);
thirdCell.Paragraphs.Add(thirdLine);

companyRow1.Cells.Add(firstCell);
companyRow2.Cells.Add(secondCell);
companyRow3.Cells.Add(thirdCell);

companyTable.Rows.Add(companyRow1);
companyTable.Rows.Add(companyRow2);
companyTable.Rows.Add(companyRow3);

companyTable.HorizontalAlignment = HorizontalAlignment.Right;
companyTable.VerticalAlignment = VerticalAlignment.Bottom;
companyTable.Left = 25;
companyTable.Top = 125;

header.Paragraphs.Add(imageTable);
header.Paragraphs.Add(addressTable);
header.Paragraphs.Add(companyTable);

HelperFunctions.AddInvoiceSummary(page);

// Save the Pdf
pdf1.Save(dataDir + @"Test.pdf");
    // ExEnd:1

public static class HelperFunctions {
    public static void AddInvoiceSummary(Page page)
    {
        var table = new Table();
        var cRow = new Row();
        var divCell = new Cell();
        table.ColumnWidths = "100%";

        divCell.Border = new BorderInfo(BorderSide.Box);
        divCell.Border.Top.LineWidth = 2;
        divCell.Border.Bottom.LineWidth = 2;
        divCell.Border.Left.LineWidth = 0;
        divCell.Border.Right.LineWidth = 0;
        //divCell.Border.Top.Color = Color.Gray;
        //divCell.Border.Bottom.Color = Color.Gray;
        divCell.DefaultCellTextState.FontSize = 10;
        divCell.Paragraphs.Add(new TextFragment("Invoice Summary"));
        cRow.Cells.Add(divCell);
        table.Rows.Add(cRow);

        page.Paragraphs.Add(table);

    }

    public static MemoryStream GetPlaceholderImage()
    {
        using (var webClient = new WebClient())
        {
            var bytes = webClient.DownloadData(@"https://png.pngitem.com/pimgs/s/388-3882910_graphics-hd-png-download.png");
            var stream = new MemoryStream(bytes);
            return stream;
        }
    }
}

This is what is being printed currently:

PublicTest.zip (95.8 KB)

I would like for the Invoice Summary line to be after the header

Thank you

@jreed

We tried to prevent the overlapping issue by setting the top margin of page equal to the height of tables in the header but too big values were returned by the API and an exception was thrown saying like “Page does not have space to add content”.

var topMargin = imageTable.GetHeight() + addressTable.GetHeight(); // The values are too big

page.PageInfo.Margin.Top = topMargin;

HelperFunctions.AddInvoiceSummary(page); // An Exception is thrown here

Hence, an issue as PDFNET-51973 has been logged in our issue tracking system. We will further investigate it in details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.