[Resolved] Issue downloading PDF with Java

We’re not java experts here, but we have gotten some reports from customers who run into issues after generating the PDF file – they want to download that file and save it locally. Never faced any issues with python or c#, but Java seems to have some problems. The below code is example of how to download the PDF file with Java without any problems.

 

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
public void downloadFileUtil(String pdfUrlToDownload) {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(pdfUrlToDownload);
HttpResponse response;
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
FileOutputStream outstream = new FileOutputStream("/storage/directory/filename.pdf");
entity.writeTo(outstream);
}

More posts

View all

Website redesign!

We’ve given the website a complete refresh.Our previous site launch in September 2024 was primari...

V2 XL now available

Our default public SaaS line at v2.api2pdf.com has the current limitations of 2 gb of memory, 2 C...