CSS @media print headers and footers

Hi, I’m converting HTML to PDF. The HTML includes an embedded style element with CSS including @media print query to print a footer on every printed page:

<style>@media print {footer {position:fixed;bottom:0}}</style>

The HTML includes a footer element:

<footer><p>This is the text printed at the foot of every page</p></footer>

This works fine when printing from the browser and the text appears at the foot of every page. However, Aspose PDF prints the footer once only on the last page having first inserted two blank pages.

In the same @media print query I also have page-break-before and page-break-after and they work fine in Aspose PDF.

Please confirm if CSS media queries are fully supported?


Thank you for contacting support.

We would to request you to share the source and generated file along with a narrowed down code snippet reproducing this scenario so that we may try to reproduce and investigate it in our environment. Kindly share a ZIP file containing all data and before sharing requested data, please ensure using Aspose.PDF for .NET 18.6 or Aspose.PDF for Java 18.5, as per your requirements.

Thanks for looking into this. Please find attached a zip file containing:

  • The HTML to convert with the media query inside a style element.
  • A snippet of C# to convert the HTML to PDF using Aspose.PDF 18.6.1 NuGet package.
  • The PDF output from the Aspose.PDF conversion.
  • A PDF generated from Google Chrome using the Print option and Save to PDF.

In the Chrome PDF file you will see the header and footer appearing on every page as expected. In the Aspose PDF file the header is only on the first page and the footer only on the last page.

In the same media query the <h1 class="page"> tags throw the pages using page-break-before: always and that works fine in both outputs.

AsposePdfTest.zip (201.5 KB)


Thank you for sharing requested data.

We would like to share with you that CSS media queries are partially supported, at the moment. Therefore, an enhancement ticket with ID PDFNET-44967 has been logged in our issue management system to produce the PDF file as expected. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

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