Use ScreenshotMAX API in Java to capture website screenshots, automate rendering tasks, and securely generate images with signed API requests. Fast, reliable, and developer-friendly.
java.net.http
import java.io.*; import java.net.*; public class Main { public static void main(String[] args) throws Exception { String accessKey = "YOUR_ACCESS_KEY"; String api = "https://api.screenshotmax.com/v1/screenshot"; String params = String.format("access_key=%s&url=%s&format=png", accessKey, URLEncoder.encode("https://example.com", "UTF-8")); URL url = new URL(api + "?" + params); InputStream in = url.openStream(); Files.copy(in, Path.of("screenshot.png"), StandardCopyOption.REPLACE_EXISTING); in.close(); System.out.println("Image saved to screenshot.png"); } }
import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.io.InputStream; import java.net.URI; import java.net.URLEncoder; import java.net.http.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; public class ScreenshotMAX { public static void main(String[] args) throws Exception { String accessKey = "YOUR_ACCESS_KEY"; String secretKey = "YOUR_SECRET_KEY"; String api = "https://api.screenshotmax.com/v1/screenshot"; String urlParam = URLEncoder.encode("https://example.com", "UTF-8"); String format = "png"; String query = "url=" + urlParam + "&format=" + format + "&access_key=" + accessKey; String signature = sign(secretKey, query); String finalURL = api + "?" + query + "&signature=" + signature; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(finalURL)) .GET() .build(); HttpClient client = HttpClient.newHttpClient(); HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream()); Files.copy(response.body(), Path.of("screenshot.png")); System.out.println("Screenshot saved to screenshot.png"); } private static String sign(String key, String message) throws Exception { Mac hmac = Mac.getInstance("HmacSHA256"); hmac.init(new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256")); byte[] hash = hmac.doFinal(message.getBytes(StandardCharsets.UTF_8)); StringBuilder hex = new StringBuilder(); for (byte b : hash) { hex.append(String.format("%02x", b)); } return hex.toString(); } }