fbpx
Pages Navigation Menu

Coding is much easier than you think

Get bytearray from pdf URL in java

Get bytearray from pdf URL in java

 
Below code converts pdf from URL to byteArray
It need common-httpClient.jar from apache HttpComponents .
Download link – http://hc.apache.org/downloads.cgi
 

String url= "http://gradcollege.okstate.edu/sites/default/files/PDF_linking.pdf";
byte[] byteArray = null;
HttpClient httpClient =null;
	{
	try 
	{
	httpClient =new httpClient();
	httpGetmethod =new GetMethod(url);
	httpGetmethod.setFollowRedirects(true);
	byteArray = httpGetmethod.getResponseBody();
	}
	catch (Exception ex)
	{
	System.out.println("Error Logs "+ex);
	}
	finally()
	{
		if(httpGetmethod !=null)
		{
		httpGetmethod.releaseConnection();
		}
	}
			
	System.out.println("ByeArray Generated"+new XStream().toXML(byteArray));
}

 

About Mohaideen Jamil


I'm a Full stack developer of IT exp in J2EE, AngularJs, MicroServices, Docker, Spring (Boot, MVC, Cloud), Bluemix, DevOps. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

Advertisements
%d bloggers like this: