Get a Free Trial

How to convert webpage to PDF using Print CSS

Converting a web page to PDF using Print CSS

Some web pages have special CSS that is used to style a web page when it is printed. By default, when converting a web page to PDF our converter makes the PDF look like what appears in the browser. To do this our converter uses the Screen Media Type.

However, in some cases a print version of a web page may convert to PDF better. To do this you need to instruct GrabzIt to use the print CSS Media Type when converting the web page, as shown below.

//The client should be stored somewhere and reused!
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret", client);
PDFOptions options = new PDFOptions();
options.CSSMediaType = CSSMediaType.Print;
grabzIt.URLToPDF("http://www.bbc.com", options);
await grabzIt.SaveAsync("http://www.mywebsite.com/Home/Handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
PDFOptions options = new PDFOptions();
options.setCSSMediaType(CSSMediaType.PRINT);
grabzIt.URLToPDF("http://www.bbc.com", options);
grabzIt.Save("http://www.mywebsite.com/handler");
<script src="https://cdn.jsdelivr.net/npm/@grabzit/js@3.5.2/grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").ConvertURL("http://www.bbc.com", 
{"format": "pdf", "download": 1, "media": "print"}).Create();
</script>
var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");
var options = {"cssMediaType":"Print"};
client.url_to_pdf("http://www.bbc.com", options);
client.save("http://www.example.com/handler", function (error, id){
    if (error != null){
        throw error;
    }
});
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = GrabzItPDFOptions->new();
$options->cssMediaType("Print");
$grabzIt->URLToPDF("http://www.bbc.com", $options);
$grabzIt->Save("http://www.mywebsite.com/handler.pl");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = new \GrabzIt\GrabzItPDFOptions();
$options->setCSSMediaType("Print");
$grabzIt->URLToPDF("http://www.bbc.com", $options);
$grabzIt->Save("http://www.mywebsite.com/handler.php");
grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzItPDFOptions.GrabzItPDFOptions()
options.cssMediaType = "Print"
grabzIt.URLToPDF("http://www.bbc.com", options)
grabzIt.Save("http://www.mywebsite.com/handler.py")
https://api.grabz.it/convert?key=Sign in to view your Application Key&format=pdf&media=print&url=https%3A%2F%2Fwww.bbc.com%2F
grabzIt = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzIt::PDFOptions.new()
options.cssMediaType = "Print"
grabzIt.url_to_pdf("http://www.bbc.com", options)
grabzIt.save("http://www.mywebsite.com/handler/index")