How to use Media Queries @print and @screen


Hallo Aspose,

I am trying to save a html code into a png. In the style tag I am using @print and @screen commands. Is there any possibility to make the respective code of the commands visible oder invisible? I am using the latest version of Aspose.Words for Java 18.1. .

Here is the code which I use to save the png:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);, saveOptions);

Thanks for your help



Thanks for your inquiry. Please note that Aspose.Words mimics the behavior of MS Word. The HTML and PNG documents are completely different file formats.The @print and @screen are CSS rules and apply in HTML document. You can convert HTML to image. However, these rules are not applied to image file format.

Could you please share some more detail about your query along with expected output image? We will then provide you more information on this.


Hi tahir.manzoor!
Thanks for your fast reply. Please find attached the expected output image as well as the image I rendered with Aspose.Words.
ExpectedOutput.png (4.3 KB)
AsposeOutput.png (194.8 KB)
Maybe the Aspose.Words lib is not the one I should use to achieve this task. Perhaps the function I am looking for is already included in another lib, for instance Aspose.Html? The class description of aspose.html.rendering.image sounds precisely like what I am looking for.

Thanks in advance



Thanks for your inquiry. Please ZIP and attach your input HTML document here for our reference. We will then provide you more information about your query.

#5 (439 Bytes)



I have worked with the data shared by you and have rendered a PNG image using below code snippet with Aspose.Html for .NET 18.1, but the image is not being rendered as per your requirements Html_18.1.png. I have logged a request for implementation of this feature. The issue ID HTMLNET-888, has been linked with this thread so that you will receive notification as soon as the issue is resolved.

        Aspose.Html.Rendering.Image.ImageRenderingOptions pdf_options = new Aspose.Html.Rendering.Image.ImageRenderingOptions();

        // Instantiate PdfDevice object while passing PdfRenderingOptions and resultant file path as arguments
        using (Aspose.Html.Rendering.Image.ImageDevice pdf_device = new Aspose.Html.Rendering.Image.ImageDevice(pdf_options, dataDir + "Html_18.1.png"))
        // Create HtmlRenderer object
        using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
        // Create HtmlDocument instance while passing path of already created HTML file
        using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(dataDir+@"input_test.html"))
            // Render the output using HtmlRenderer
            renderer.Render(pdf_device, html_document);

We are sorry for the inconvenience.



Yes I also tried it meanwhile with Aspose.Html but I could not come to an satisfying result. Thank you anyway for your efforts. I am looking forward to the release of the feature.



Thank you for your kind feedback.

We will notify you as soon as the requested feature will be supported. We greatly appreciate your patience in this regard.


The issues you have found earlier (filed as HTMLNET-888) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by Farhan.Raza