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

Free Support Forum - aspose.com

Multiple header and footer items ignoring margins and Overlapping

I have recently upgraded my Aspose.Pdf library from 3.0.4.0 to 9.3.0.0. After the upgrade our use of the PdfFileStamp starting ignoring our margin options (top, left, right) and instead, writing all of the headers center aligned overlapping. (see image OverlappingHeaders.png)





Before, these headers were working fine (see image OverlappingHeadersOldVersion.png)



I tried placing each header item in their own file stamp, but that did not fix the issue.



TL;DR: why are my margin values in my header being ignored?



(I have also asked this question on stack overflow here:

http://stackoverflow.com/questions/25254759/aspose-pdffilestamp-headers-overlapping

)

Hi Nathan,


Thanks for contacting support.

Can you please share complete code snippet and sample PDF file so that we can test the scenario at our end. We are sorry for this inconvenience.

Hi Nathan,


We have further tested the scenario with a sample PDF file and it seems that margin calculation logic is changed somewhere between 3.0.4 and 9.5.0 version. As you were using a quite old version and it is difficult to point the version, in which this logic changed. However, to accomplish the task you may use following code snippet for the purpose.

PdfFileStamp fileStamp = new PdfFileStamp();<o:p></o:p>

fileStamp.BindPdf(myDir+"HelloWorld.pdf");

fileStamp.AddHeader(new Aspose.Pdf.Facades.FormattedText("ID: 0001", System.Drawing.Color.FromArgb(0, 0, 0), "Arial",

Aspose.Pdf.Facades.EncodingType.Winansi, false, 9), 20, 80, fileStamp.PageWidth);

fileStamp.AddHeader(new Aspose.Pdf.Facades.FormattedText("Site: Site A",System.Drawing.Color.FromArgb(0, 0, 0), "Arial",

Aspose.Pdf.Facades.EncodingType.Winansi, false, 9), 20);

fileStamp.AddHeader(new Aspose.Pdf.Facades.FormattedText("Visit: Baseline Visit", System.Drawing.Color.FromArgb(0, 0, 0), "Arial",

Aspose.Pdf.Facades.EncodingType.Winansi, false, 9), 30);

fileStamp.AddHeader(new Aspose.Pdf.Facades.FormattedText("Group: Group A",System.Drawing.Color.FromArgb(0, 0, 0), "Arial",

Aspose.Pdf.Facades.EncodingType.Winansi, false, 9), 20, fileStamp.PageWidth,100);

fileStamp.AddHeader(new Aspose.Pdf.Facades.FormattedText("From: From Date",System.Drawing.Color.FromArgb(0, 0, 0), "Arial",

Aspose.Pdf.Facades.EncodingType.Winansi, false, 9), 30, fileStamp.PageWidth, 100);

fileStamp.Save(myDir+"Header_out.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

Hey there Tilal,


I tried to use the provided sample within our code, but I am still getting the overlapping headers and footers. I have built a sample console app with just the method that is causing the problem. it also has a sample pdf file we are attempting to stamp. It also shows the same result.

update I cannot attach the zip file with the sample project within it. I have created a gethub project with the sample project at the following url:

https://github.com/ntregillus/HeadersNotAligningCorrectly

Please let me know what I am missing. the method is called “AddHeaderAndFooter”

I have included an example that is being hosted on Github. Any assistance is greatly appreciated!

Hi Nathan,


Thanks for sharing your source code. It seems you have not made changes suggested above. Please change your code as following, it will help you to get the desired results with latest API.

if (null != ftMedrioID)

{

fileStamp.AddHeader(ftMedrioID, medrioIdTopMargin, 80, fileStamp.PageWidth);

}

fileStamp.AddHeader(ftSite, 20);

fileStamp.AddHeader(ftVisit, 30);

fileStamp.AddHeader(ftGroup, 20, fileStamp.PageWidth-150, 0);

fileStamp.AddHeader(ftForm, 30, fileStamp.PageWidth-150, 0);

TimeZoneInfo tzi = null;

try

{

tzi = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneFormatForCurrentUser);

}

catch

{

tzi = TimeZoneInfo.Local;

}

DateTime dt = TimeZoneInfo.ConvertTime(DateTime.UtcNow, tzi);

FormattedText ftDatetime = new FormattedText(string.Format("{0} {1:HH:mm} ({2})", dt.ToString(ExportDateFormat), dt, TimeZoneFormatForCurrentUser)

, fontColor, FONT_STYLE, FONT_ENCODING, FONT_EMBEDED, FONT_SIZE);

// add footer

fileStamp.AddFooter(ftStudy, 20);

fileStamp.AddFooter(ftDatetime, 20, 25, fileStamp.PageWidth-150);

fileStamp.Save(PathToPdf);

Please feel free to contact us for any further assistance.


Best Regards,