#StackBounty: #download #print-to-pdf #file-download #user-experience Can this PDF be downloaded to internal storage?

Bounty: 50

There’s a website where information is available to view publicly and one can share that information anywhere but only by taking screenshots. I want to save it as pdf in my device for future reference.

I tried looking for ways on the web but nothing helpful found.

Here’s the link of the PDF that I want to download: https://www.ibps.in/pdfview.html?pdfNameaHR0cHM6Ly93d3cuaWJwcy5pbi93cC1jb250ZW50L3VwbG9hZHMvQ1JQLVBPLUlYdmdndi1OT1RJQ0UucGRm

Instead of saving it to my storage as screenshot it would be much more user friendly to save it as PDF for future use.

Note: It takes a long time to load if you are visiting the link via smartphone or trying to open it using Google Chrome. I had to use Safari to open the link and it opened immediately.

Get this bounty!!!

Code to Download File from URL in Java

Below is the code to download the complete contents of a URL to your local hard drive.

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.io.File;
    private static void download(String url) throws IOException {

        String fileName="Path\to\File.extn";//The file that will be saved on your computer
        URL link = new URL(url); //The file that you want to download

        //Code to download
        InputStream in = new BufferedInputStream(link.openStream());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buf = new byte[2048];
        int n = 0;
        while (-1 != (n = in.read(buf))) {
            out.write(buf, 0, n);
            System.out.print("|");//Progress Indicator
        byte[] response = out.toByteArray();

        FileOutputStream fos = new FileOutputStream(fileName);
        //End download code


Note: For large file downloads, the JVM may throw OutOfMemoryError