Provide state-of-the-art image capture, screen capture, video capture and audio capture software
Home     Download     Purchase     Support     Contact     View my shopping cart
You are here: ACASystems » ACA WebThumb ActiveX Control » FAQ » Convert HTML to image in Java

How to convert HTML to image in Java - Java Sample Code

If you are a Java developer and want to add conerting HTML to image feature to your Java application, ACA WebThumb ActiveX may be one of the best choice for you. It helps you convert the HTML to images in Java with a few Java API calls, it takes the snapshots of given URLs as JPG, GIF, PNG, BMP, TIFF, WMF and EMF image, capture full length website screenshots, generate thumbnail image previews of web pages.

Tips: ACA WebThumb ActiveX Control is a developer SDK for converting HTML web page to image. If you are looking for a windows application to coverting HTML web page to image and save HTML to JPG/PNG/GIF/TIF files, please free trial ACA HTML to Image Converter.

Guidelines: Convert HTML to image in Java

  1. Free download ACA WebThumb ActiveX.
  2. You will find a Java demo project in the folder {install-folder}\sample\java.
  3. Open file Readme.txt, follow the instructions, build and run it.

Free Trial ACA WebThumb ActiveX Now

Example code: Java - Convert HTML to image

Java Code for Converting HTML to image:

Code File: snap.java

import sun.awt.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.peer.*;

public class Snap
{
  static
  {
    System.loadLibrary("Snap");
  }

  public static void main( String[] argv )
  {
    Snap t_xSnap = new Snap();
    t_xSnap.Start("http://www.google.com", "snapshot-google.png");
  }

  public native void Start(String pi_strURL, String pi_strImageName);
}

Code File: snap.cpp

#include <windows.h>
#include <atlbase.h>
#include "snap.h"

#pragma comment(lib,"atl.lib")
#import "./../../acawebthumb.dll" no_namespace

JNIEXPORT void JNICALL 
Java_Snap_Start(JNIEnv *pEnv, jobject, jstring pi_strUrl, jstring pi_strFileName)
{
  CoInitialize(0);

  _bstr_t t_strUrl = pEnv->GetStringUTFChars(pi_strUrl, 0);
  _bstr_t t_strFileName = pEnv->GetStringUTFChars(pi_strFileName, 0);	

  IThumbMakerPtr HTML_Converter = NULL;
  HRESULT hr = HTML_Converter.CreateInstance(L"ACAWebThumb.ThumbMaker");	
  if (SUCCEEDED(hr))
  { 
    HTML_Converter->SetURL(t_strUrl);
    if ( 0 == HTML_Converter->StartSnap() )
      HTML_Converter->SaveImage(t_strFileName);
  }
  if (HTML_Converter)
    HTML_Converter.Release();

  CoUninitialize();    	  	
}

Code File: Build.bat

@echo off

REM ======================================================
REM To build this Java sample code,
REM Please set your VCBIN and JDKFOLDER folder first
REM ======================================================
echo Setting Environment...

SET VCBIN=D:\Dev\Tool\Microsoft Visual Studio 8\VC\bin
SET JDKFOLDER=D:\apps\Java\jdk1.6.0_11

call "%VCBIN%\VCVARS32.BAT"
cd /D "%~dp0"

echo Compiling Java script...
"%JDKFOLDER%\bin\javac" Snap.java
"%JDKFOLDER%\bin\javah" -classpath . Snap

echo Building DLL...
cl Snap.cpp -I"%JDKFOLDER%\include\Win32" 
            -I"%JDKFOLDER%\Include" -FeSnap.dll -MT -LD /link user32.lib gdi32.lib

echo Running Sample...
"%JDKFOLDER%\bin\java" Snap

Free Trial ACA WebThumb ActiveX Now

Other resource about Converting HTML to image in Java:


Get discount alerts, new product information and technical articles:
Name:
Email:
* Get 10% off your first order by joining our mailing list!
* You may safely unsubscribe at any time!