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


Am currently working as a Struts 2 Developer in a reputed IT Organisations. I can help you with teaching Core java and Struts 2. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.