Article

How to Automatically Convert a Webpage into a PDF Document

Topic: General Self HelpPublished May 2, 2018
No ratings yet700 viewsSign in to rate
Sometimes in web development you need to save a webpage as a PDF document, this could be for example to turn an online invoice or report into a downloadable copy that can be kept as a permanent record or shared. While there are libraries that enable PDF documents to be constructed piece at a time, one of the best ways to convert a webpage to PDF would just be to pass the URL of the webpage you want to convert to PDF to GrabzIt's URL to PDF API. This free API is available in eight programming languages allowing you to create PDF's in JavaScript, PHP, Python and much more. Simply pass your URL to the API and your finished PDF will be returned a few seconds later. In the PHP example shown below it only takes four lines of code to convert a webpage to PDF.
  • include("GrabzItClient.class.php");
  • $grabzIt = new GrabzItClient("Your Application Key", "Your Application Secret");
  • $grabzIt->URLToPDF("http://www.example.com/invoice.php");
  • $grabzIt->SaveTo("invoice.pdf");
One important point to remember, especially when converting modern webpages is that they are often designed to be responsive to the size of the webpage. Therefore, specifying the browser width parameter can determine if a mobile version or a desktop version of a webpage is converted to PDF. However, as some webpages have content that matches the browser width in some circumstances it may be more useful to pass a -1 to this parameter which makes the browser width match the PDF page width instead. rnOf course, the URL to PDF API can also do much more sophisticated PDF conversions for example creating custom headers and footers that can except special parameters allowing all sorts of content to be inserted when each header or footer is created, to custom page sizes and merging multiple PDF documents into one. Being able to merge multiple PDF documents together would allow an entire website to be turned into a PDF document providing a excellent way of archiving a website as it appears at a certain point in time. rnWhat we have provided here is only a sample of what can be done when converting webpages to PDF with our API, to find out for yourself how flexible our API is get your free API key and get started experimenting need now. Alternatively, if you don't like to write code, GrabzIt also has a online screenshot tool that allows you to convert webpages to PDF with almost all of the same options as our API.

Further reading

Further Reading

4 total

Article

Keeping properties and schools clean is very important in Port Melbourne. Clean spaces help people feel safe, healthy, and comfortable. Whether it is a home for sale, a rental property, or a busy school full of students, the right cleaning care makes a big difference. This is why many people choose professional real estate cleaning Port Melbourne services and trusted School Cleaning Port Melbourne teams to make sure every area looks fresh and welcoming. When a property is bei

January 25, 2026

Article

Construction sites are high-risk environments. Open flames, electrical work, welding, flammable materials, and temporary power setups all increase the likelihood of fire-related incidents. Even a small oversight can lead to major losses, including injuries, property damage, legal penalties, and project delays. This is why having a structured fire prevention plan is no longer optional for construction projects of any size. One of the most effective ways to reduce fire risk on

January 23, 2026

Article

Introduction In a world where inequality, poverty, and social challenges continue to affect millions, organizations driven by compassion and community service play a crucial role in uplifting vulnerable populations. One such organization making a significant impact in Indonesia is Yayasan Sosial Harapan Indonesia — a social foundation dedicated to spreading hope, providing support, and empowering communities in need. With a clear mission to foster sustainable change and pro

December 19, 2025

Article

As Singapore prepares to welcome another exciting year, fashion-forward individuals and groups are turning to custom t shirt printing Singapore services to create memorable celebration attire. This year's trending prints combine festive spirit with contemporary style, making t shirt customization the perfect way to ring in the new year with flair. Metallic and Glitter Accents Take Center Stage Shimmering metallic prints dominate this year's New Year fashion scene. Gold, silve

December 16, 2025