HTML to PDF Conversion with @media print query

Hi Aspose,


We have your .net HTML to PDF generator running in our web application. It appears to load embedded CSS, as it should. But the client wants a PDF only design, without affecting the web application.

So in other words, can I load an aspose.css file to ONLY load when a PDF is generated from HTML?

This way I can add CSS !important overrides to the aspose.css file to make the design of the final PDF match the intended design.

Thank you.

Hi Mitchell,


Thanks for your inquiry. As per my understanding you want a feature in HTML to PDF conversion to control CSS, whether embedded CSS should be honored or not in the conversion. We will appreciate it if you please share your source HTML along with current resultant PDF and expected PDF. It will help us to understand your requirement exactly and address it accordingly.

Best Regards,

Not sure how easy it would be to share the HTML, but maybe there’s a simpler question:


When using the browser’s native print function, the page looks perfect.

Is there a way to have Aspose HTML to PDF follow print media query CSS?

Hi Mitchell,


Thanks for your feedback. I am afraid currently Aspose.Pdf does not honor @media print query in HTML to PDF conversion. However we will appreciate if you share your sample HTML with @media print query so we will log a ticket for investigation and rectification accordingly.

We are sorry for the inconvenience.

Best Regards,

Hello @tilal.ahmad

The landscape orientation is not being respected during HTML to PDF conversion using aspose-pdf 23.7 library. We used “@media print” query to set the landscape orientation.
Attached is a sample file that did not respect the landscape orientation. Please confirm if Aspose still does not support this or if there is any workaround for this.

test.zip (245 Bytes)

@rprasadcr

Can you please share the code snippet as well that you are using to perform conversion along with an expected output PDF for our reference? We will test the scenario in our environment and address it accordingly.

The Java code used to convert is:
var document = com.aspose.pdf.Document("test.html", new HtmlLoadOptions()); document.save("output", new PdfSaveOptions());

Aspose pdf version:23.7 JDK17

Expected output PDF:
test.html.pdf (38.8 KB)

@msholly

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-43148

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.