Sophisticated header behavior

I need my PDF document to have a header placed either from the first page to the last, or from the second page to the last. It needs 3 lines of text. The first must be centered, the other two are not. What’s the best approach to this situation? I don’t see instructions for changing text properties over multiple lines when dealing with headers and footers.

Hi Scott,


Thanks for your inquiry. You may accomplish your requirement by using table in headers and control formatting of table rows. Please check a sample code snippet for the purpose. Hopefully it will help.

Document doc = new Document(myDir

  • “Helloworld.pdf”);<o:p></o:p>

Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();

Aspose.Pdf.Text.TextState textState = new Aspose.Pdf.Text.TextState();

textState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;

textState.Font = FontRepository.FindFont("Helvetica");

textState.FontSize = (float)8;

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

table.ColumnWidths = "600";

table.Rows.Add().Cells.Add("Aspose.pdf for .NET", textState);

table.Rows.Add().Cells.Add("May, 2014");

header.Paragraphs.Add(table);

for (int cnt = 1; cnt <= doc.Pages.Count; cnt++)

{

doc.Pages[cnt].Header = header;

}

doc.Save(myDir + "Output_DOMheaderfooter.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

Thanks for the reply. While helpful, it hasn’t gotten me all the way to where I need to be. Here’s my implementation:

Aspose.Pdf.Text.TextState textState = new Aspose.Pdf.Text.TextState();
textState.Font = FontRepository.FindFont(“Arial”);
textState.FontSize = (float)12;
textStateTopHeader.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;

Aspose.Pdf.Text.TextState textStateInfoHeader= new Aspose.Pdf.Text.TextState();
textStateInfoHeader.Font = FontRepository.FindFont(“Arial”);
textStateInfoHeader.FontSize = (float)12;
textStateInfoHeader.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Left;

var table = new Aspose.Pdf.Table();
table.ColumnWidths = “840”;

table.Rows.Add().Cells.Add(“OFFICIAL USE ONLY”, textStateTopHeader);
table.Rows.Add().Cells.Add(“NAME: Doe, John”, textStateInfoHeader);
table.Rows.Add().Cells.Add(“SSN: 111-11-1111”, textStateInfoHeader);

The resulting document has both lines set much too far to the right, with the “OFFICIAL USE ONLY” pushed half-way off the page.

What am I doing wrong with this formatting?

Hi Scott,


Thanks for your feedback. After initial investigation we have notice the left alignment is not working properly in header. So we have logged an investigation ticket as PDFNEWNET-37174 in our issue tracking system for further investigation and resolution. We will keep you updated about the issue resolution progress via this forum thread.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-37174) have been fixed in Aspose.Pdf for .NET 9.5.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Scott,


As stated above the issue has been fixed in Aspose.Pdf for NET 9.5.0. You may set table width as following. It will help you to accomplish the task.

table.ColumnWidths = (840 - header.Margin.Left -
header.Margin.Right).ToString();<o:p></o:p>

Please feel free to contact us for any further assistance.


Best Regards,



Hi, I do have couple of pdf files, converted to PDF format from Word. I am trying to insert a custom header on each page. That header would contain a table with some text in it. I am using similar code snippet as the one above and in the output file the header is indeed added. But it doesn’t push the rest of the pages’ content to the bottom but rather moves behind the content.

I am attaching the code snippet I am using, the original pdf file and the output file. Please advise.

Thank you in advance for the information.

Regards

Hi Gerasim,

Thanks for your inquiry. Please note while we are creating a PDF form scratch then API can adjust page body contents automatically as per Header/Footer contents. However in case of existing PDF pages we need to resize the page contents our self to adjust Header/Footer contents. Please check following documentation link to reize PDF page contents, hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,

Hi,
Thanks for the response, the resizing did the trick. but now I am facing another problem. On every subsequent page of the document the table in the header gets moved lower and lower, even though the margin is set to 10. What am I doing wrong?

Source code and documents are attached.

Thanks in advance

Hi Gerasim,


Thanks for your inquriy. I have tested the scenario and notice that header object is moving lower and lower in subsequent pages, so logged a ticket PDFNEWNET-40503 in our issue tracking system for further investigation and rectification. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,

Hi, any update on this (ticket PDFNEWNET-40503)?

Thanks

Hi Gerasim,


Thanks for your inquriy. I am afraid the reported issue(PDFNEWENET-40503) is still pending for investigation in the queue with other issues, as we have recently logged the issue. We will notify you as soon as we made some significant progress towards issue resolution.

We are sorry for the inconvenience.

Best Regards,