Home > Domino Tips > Developer > Java > Converting Web pages to images using Java
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVA

Converting Web pages to images using Java


Michael Marcavage
03.13.2007
Rating: -3.05- (out of 5)


Lotus Notes, Domino, Workplace and WebSphere tips and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


I was recently asked to come up with some Java code that would convert Web pages into images.
VIEW MEMBER FEEDACK TO THIS TIP
My objective was to have the Web page become an image upon the clicking of a button or when certain events happened. Below is the Java code I came up with, I hope it works as well for you as it did for me.

//Call the Web page and convert to Image
BufferedImage ire;
ire = WebImage.create("<web page URL>", 800, 600);
//You can convert the BufferedImage to 
any format that you wish, jpg I thought was the best format
ImageIO.write(ire, "jpg", new File
("c:\\Temp\\tt.jpg"));



//Class that Converts the web page to Image
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;

public abstract class WebImage 
{ 
static class Kit extends HTMLEditorKit 
{
public Document createDefaultDocument() {
HTMLDocument doc = 
(HTMLDocument) super.createDefaultDocument();
doc.setTokenThreshold(Integer.MAX_VALUE);
doc.setAsynchronousLoadPriority(-1);
return doc;
}
}

public static BufferedImage create
(String src, int width, int height) {
BufferedImage image = null;
JEditorPane pane = new JEditorPane();
Kit kit = new Kit();
pane.setEditorKit(kit);
pane.setEditable(false);
pane.setMargin(new Insets(0,0,0,0));
try {
pane.setPage(src);
image = new BufferedImage
(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
Container c = new Container();
SwingUtilities.paintComponent
(g, pane, c, 0, 0, width, height);
g.dispose();
} catch (Exception e) {
System.out.println(e);
}
return image;
}
}

MEMBER FEEDBACK TO THIS TIP

Wouldn't it just be easier to hit the PrintScreen button or Alt+PrintScreen to bring up only the active window?
—Leonard V.

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • FAQ: Java for Lotus Notes and Domino
  • Reference Center: Java tips and resources

    This tip was submitted to the SearchDomino.com tip library by member Michael Marcavage. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

    Rate this Tip
    To rate tips, you must be a member of SearchDomino.com.
    Register now to start rating these tips. Log in if you are already a member.




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


    RELATED CONTENT
    Java for Lotus Notes Domino
    Java code shortens strings in a SQL table
    How to execute a stored procedure in Lotus Notes Domino using Java
    Top 10 Lotus Notes Domino programming and development tips of 2007
    How to return an HTML representation of a Lotus Notes rich-text field
    Shrink Lotus Notes databases with many attachments
    Converting Lotus Notes Domino Web pages to PDF files with a Java agent
    Developing Eclipse plug-ins for Lotus Notes and Domino -- 7 tips in 7 minutes
    A bevy of Notes/Domino development tips
    Creating Microsoft Word documents from Lotus Notes
    Sending and logging faxes from Lotus Notes and Domino

    Java
    Java code shortens strings in a SQL table
    How to execute a stored procedure in Lotus Notes Domino using Java
    How to return an HTML representation of a Lotus Notes rich-text field
    Shrink Lotus Notes databases with many attachments
    Converting Lotus Notes Domino Web pages to PDF files with a Java agent
    A bevy of Notes/Domino development tips
    Creating Microsoft Word documents from Lotus Notes
    FAQ: Java for Lotus Notes and Domino
    Automatically scan Lotus Notes database document attachments for viruses
    Creating PDF documents from Lotus Notes

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



  • Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
    HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




    All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts