URL to a PDF

IronPDF for Python can convert online webpages into PDFs.

This code example uses the RenderUrlAsPdf method in Java. The method will return a PdfDocument object, which can then be exported using the saveAs method.

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions;
import com.ironsoftware.ironpdf.render.ChromeHttpLoginCredentials;

public class PdfExample {
    public static void main(String[] args) {
        try {
            // The URL of the web page to convert to a PDF
            String url = "https://www.example.com";

            // Convert the web page at the given URL into a PdfDocument object
            PdfDocument pdf = PdfDocument.renderUrlAsPdf(url);

            // Save the PdfDocument to a file named "output.pdf"
            pdf.saveAs("output.pdf");
        } catch (Exception e) {
            // Print any exceptions that occur
            e.printStackTrace();
        }
    }
}
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions;
import com.ironsoftware.ironpdf.render.ChromeHttpLoginCredentials;

public class PdfExample {
    public static void main(String[] args) {
        try {
            // The URL of the web page to convert to a PDF
            String url = "https://www.example.com";

            // Convert the web page at the given URL into a PdfDocument object
            PdfDocument pdf = PdfDocument.renderUrlAsPdf(url);

            // Save the PdfDocument to a file named "output.pdf"
            pdf.saveAs("output.pdf");
        } catch (Exception e) {
            // Print any exceptions that occur
            e.printStackTrace();
        }
    }
}
JAVA

PdfDocument.renderUrlAsPdf accepts a String containing an absolute (fully formed) URL to a web page. IronPDF will retrieve the HTML content returned from an HTTP request for the URL and faithfully transform it into its PDF version. Developers can supply login credentials (username and password) that renderUrlAsPdf can use for this HTTP request by including a ChromeHttpLoginCredentials object as an optional, second parameter. This is useful for accessing web pages locked within a password-protected website directory. Refer to the API Reference for more information about the ChromeHttpLoginCredentials class.

It is really a brilliant way to download PDFs from URLs in Java.

Watch this video for additional information.

Also, see the ChromePdfRenderOptions API Reference page for details on how to customize the look and feel of PDF documents midway through their conversion from HTML web pages.