Aspose PDF with .Net Footer Height Issue

Hello,

I am creating a PDF using Aspose .Net. In that I am adding image as footer. Please find attached image. When added as footer I am getting PDF as shown in file.
TEst7890.pdf (49.4 KB)

Capture.PNG (28.1 KB)

My code:
HeaderFooter footer = new HeaderFooter();
footer.Margin = new MarginInfo(30, 0, 30, 0);
string formedFooterHTML = (!string.IsNullOrEmpty(coverPageFooterHTML) && i == 1 ? coverPageFooterHTML : footerHTML);
HtmlDocument doc = new();
doc.LoadHtml(formedFooterHTML);
var imageNodes = doc.DocumentNode.SelectNodes(“//img[@src]”);
//// Initialize max height
int maxHeight = 0;
if (imageNodes != null && imageNodes.Any())
{
//// Retrieve image heights
foreach (var img in imageNodes)
{
if (img.Attributes.Contains(“height”))
{
int height;
if (int.TryParse(img.GetAttributeValue(“height”, “”), out height))
{
maxHeight = Math.Max(maxHeight, height);
}
}
}
}

var footerHTMLFragment = new HtmlFragment(formedFooterHTML);
footerHTMLFragment.Margin.Bottom = Convert.ToDouble(maxHeight);
footer.Paragraphs.Add(footerHTMLFragment);

Issue: Complete images is not visible.

@prashantm1989

The image in the shared PDF is different that the image you attached here. Can you please share an expected output along with the code snippet that we can use for testing. Your current shared snippet has some undefined and missing definitions that we cannot use it to replicate the issue. Please try to provide a minimal code snippet that we can use and address the issue accordingly.

dummy.jpg (8.5 KB)

Hello,

Please find the attached images, as the original I am trying to add as footer to PDF using .net.

Please find the correct code below:
NOTE: Just correct the image path based on your code setup below.

            HeaderFooter footer = new HeaderFooter();
footer.Margin = new MarginInfo(30, 0, 30, 0);
string formedFooterHTML = "<p style=\"line-height: 1.2;\" data-mce-style=\"line-height: 1.2;\"><span style=\"font-family: verdana, geneva, sans-serif; font-size: 7pt;\" data-mce-style=\"font-family: verdana, geneva, sans-serif; font-size: 7pt;\"><img src=\"<<Image path>>\" alt=\"\" title=\"download.jfif\" width=\"708\" height=\"193\"></span></p>";
HtmlDocument doc = new();
doc.LoadHtml(formedFooterHTML);
var imageNodes = doc.DocumentNode.SelectNodes(“//img[@src]”);
//// Initialize max height
int maxHeight = 0;
if (imageNodes != null && imageNodes.Any())
{
//// Retrieve image heights
foreach (var img in imageNodes)
{
if (img.Attributes.Contains(“height”))
{
int height;
if (int.TryParse(img.GetAttributeValue(“height”, “”), out height))
{
maxHeight = Math.Max(maxHeight, height);
}
}
}
}

The ourput I am expecting is to fit this image as footer in PDF>

@prashantm1989

Thanks for sharing the sample code snippet. Looks like you are using Aspose.HTML (possibly an older version) as well in your scenario to form the HTML for the PDF footer. Can you please share which version of the API is it?

Hello,

I am using Aspose.PDF and Aspose.Html with version 24.3.

Can you please guide with correct version or code sample to get the desired result?

@prashantm1989

We are checking it and will get back to you shortly.

@prashantm1989

Please check below code snippet where you can use only Aspose.PDF to add the image in the PDF footer:

Document doc = new Document();
doc.Pages.Add();
doc.Pages[1].PageInfo.Margin = new MarginInfo(0, 193, 0, 0);
HtmlFragment htf = new HtmlFragment("<p style=\"line-height: 1.2;\" data-mce-style=\"line-height: 1.2;\"><span style=\"font-family: verdana, geneva, sans-serif; font-size: 7pt;\" data-mce-style=\"font-family: verdana, geneva, sans-serif; font-size: 7pt;\"><img src=\"D:\\Aspose Working\\Files\\dummy.jpg\" alt=\"\" title=\"download.jfif\" width=\"708\" height=\"193\"></span></p>");

//HeaderFooter header = new HeaderFooter();
//header.Paragraphs.Add(htf);
HeaderFooter footer = new HeaderFooter();
footer.Paragraphs.Add(htf);
footer.Margin = new MarginInfo(0, 0, 0, 0);
//doc.Pages[1].Header = header;
doc.Pages[1].Footer = footer;
//doc.Pages[1].Paragraphs.Add(htf);
doc.Save(dataDir + "HTMLInFooter.pdf");

Please note that you need to adjust Page as well as Footer margin information in order to obtain your desired results. Unit of measurement in Aspose.PDF is point where 72 points = 1 inch. Therefore, you can keep in mind these values and adjust accordingly.

THanks for the update! THis helped.

@prashantm1989

It is nice to know that your issue has been resolved. Please keep using the API and feel free to create a new topic in case you need further assistance.