Add HeaderFooter on PDF while converting HTML to PDF using Aspose.PDF for .NET - System.ArgumentException occurred

First of all, I think I had a similar issue last year. It was solved on this forum:
Find Text in Pdf Error - #4 by alinprisecaru-1

I think my current issue is similar because it’s the same scenario:
Tried to apply something Aspose-specific to a PDF file created with TuesPechkin (a wkhtmltopdf converter).

Now I wanted to add Aspose Headers/Footers to my PDF files. The attached PDF file is an example. Please test it on your side, but I think the result will be the same:

A first chance exception of type ‘System.ArgumentException’ occurred in mscorlib.dll

My code:

Document pdfDocument = new Document(pdfDocumentPath);
HeaderFooter header = new HeaderFooter();
HeaderFooter footer = new HeaderFooter();

HtmlFragment headerText = new HtmlFragment(“<font face="Arial" size=8px>Bold text test underline text”);
headerText.Margin.Bottom = 10;
headerText.Margin.Top = 10;

header.Paragraphs.Add(headerText);

HtmlFragment footerText = new HtmlFragment(“Bold text test underline text”);
footerText.Margin.Bottom = 10;
footerText.Margin.Top = 10;

footer.Paragraphs.Add(footerText);

for (var i = 1; i <= pageCount; i++)
{
pdfDocument.Pages[i].Header = header;
pdfDocument.Pages[i].Footer = header;
}

//crashes here when attempting to save
pdfDocument.Save(editedPdfFilePath);


As an additional note, my code above works if I don’t use HeaderFooter class. This is just something that I want to improve because right now I use TextStamp successfully to create something that looks like a Header / Footer.

Example:
TextStamp auxStamp = new TextStamp(“header text”);
auxStamp.TextAlignment = HorizontalAlignment.Center;
auxStamp.TextState.FontSize = fontSize;

auxStamp.VerticalAlignment = VerticalAlignment.Top;
auxStamp.HorizontalAlignment = HorizontalAlignment.Center;
auxStamp.TopMargin = 10;

auxStamp.Opacity = opacity;

pdfDocument.Pages[i].AddStamp(auxStamp);

Hi Alin,


Thanks for your inquiry. I have tested the scenario with Aspose.Pdf for .NET 9.9.0 but unable to notice any exception. But header/footer text is being added incorrectly. So logged an ticket PDFNEWNET-38029 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

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


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