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

Free Support Forum - aspose.com

Positioning of Paragraphs and Headers

I am upgrading to the latest version of PDF using the .NET library. I have a heading for the page that is 11 lines and it prints correctly, but when I add additional lines to the report using the following code, the lines overwrite the heading. My questions are:
a) How to get the text to start below the heading automatically?
b) Will the page overflow to a new page automatically as before?

In the previous version I was using the following code for the header and lines of the report (section was created as Section):

private void SetHeader(List<PDFTextLine> headerLines)
{
  if(headerLines != null && headerLines.Count > 0)
  {
    Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(section);
    foreach(PDFTextLine pdfTextLine in headerLines)
    {
      string lineToUse = pdfTextLine.Line;
      if (String.IsNullOrEmpty(pdfTextLine.Line))
        lineToUse = "#$NL";
      Text text = new Text(lineToUse);
      text.TextInfo.FontName = pdfTextLine.FontDefinition.FontName;
      text.TextInfo.FontSize = pdfTextLine.FontDefinition.Size;
      header.Paragraphs.Add(text);
    }
    section.OddHeader = header;
    section.EvenHeader = header;
  }
}

public void AddLine(string line)
{
  if(section != null)
  {
    Text text = new Text(line);
    section.Paragraphs.Add(text);
  }
}

In the current version I am using:

private void SetHeader(List<PDFTextLine> headerLines)
{
  if(headerLines != null && headerLines.Count > 0)
  {
    Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
    header.Margin = page.PageInfo.Margin;
    foreach(PDFTextLine pdfTextLine in headerLines)
    {
      string lineToUse = pdfTextLine.Line;
      if (String.IsNullOrEmpty(pdfTextLine.Line))
        lineToUse = "\n";
      TextFragment text = new TextFragment(lineToUse);
      text.TextState.Font = FontRepository.FindFont(pdfTextLine.FontDefinition.FontName);
      text.TextState.FontSize = pdfTextLine.FontDefinition.Size;
      header.Paragraphs.Add(text);
    }
    page.Header = header;
  }

public void AddLine(string line)
{
  if(page != null)
  {
    TextFragment text = new TextFragment(line);
    page.Paragraphs.Add(text);
  }
}

If you have references that give a good description of how to use these effectively that would be helpful. Thank you for any pointers.

Jeff

@JeffBallance,
Kindly send us the complete code and source PDF. We will investigate and share our findings with you.

I am attaching a test project that includes the class I use to create the reports and the code calling it to produce the report in questions. I have also included the report generated (I did not include the license in the project). You will note that the text lines of the report content should be below the heading lines.Aspose_SupervisoryReport.zip (38.4 KB)
I do have an active license.
Thank you,
Jeff

@JeffBallance,
We managed to replicate the problem of overlapping text. It has been logged under the ticket ID PDFNET-43505 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Thank you. Is there a work around or another way I could accomplish this? I am caught with the new versions solving some issues that I had encountered and this one is keeping from releasing the program.
Jeff

@JeffBallance,
You can insert the image, table and text fragments in the floating box, and then set the width, height and position of the floating box with respect to the page size. FloatingBox accepts absolute positioning rather than flow layout, so you will get the power to specify the position instead of letting the page rendering engine to place it. You can use Top, Left, Bottom and Right properties to adjust the position of a floating box. Please try the following code example:

[C#]

string dataDir = @"C:\Pdf\test334\";
// Open document
Document pdfDocument = new Document(dataDir + "Input.pdf");
FloatingBox box = new FloatingBox();

TextFragment fragment = new TextFragment("Main Text");
fragment.Margin = new MarginInfo(0, 20, 0, 0);
fragment.TextState.HorizontalAlignment = HorizontalAlignment.Justify;
fragment.TextState.Rotation = 90;
box.Paragraphs.Add(fragment);

pdfDocument.Pages[1].Paragraphs.Add(box);
pdfDocument.Save(dataDir + "Test_Out.pdf");

Thank you. I have implemented this approach and that will work. It is a little more work in having to handle the page breaks, but it works fine.
Jeff

@JeffBallance,

It is nice to hear from you that this approach works fine in your scenario. Please feel free to let us know whenever you require any further assistance.

The issues you have found earlier (filed as PDFNET-43505) have been fixed in Aspose.PDF for .NET 22.2.