473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

converting webpage to image

9
Hi,
I am trying to convert an HTML to an image but the image that gets generated doesnt contain the images in that webpage.
my code is :-
Expand|Select|Wrap|Line Numbers
  1.  
  2. Import javax.imageio.ImageIO;
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.image.BufferedImage;
  6. import java.beans.PropertyChangeEvent;
  7. import java.beans.PropertyChangeListener;
  8. import java.io.File;
  9. import java.io.IOException;
  10. import java.net.URL;
  11.  
  12. public class MyConverter {
  13.     private static volatile boolean loaded;
  14.  
  15.     public static void main(String[] args) throws IOException {
  16.         loaded = false;
  17.  
  18.        URL url = new URL("http://www.google.com");
  19.         JEditorPane editorPane = new JEditorPane();
  20.         editorPane.addPropertyChangeListener(new PropertyChangeListener() {
  21.             public void propertyChange(PropertyChangeEvent evt) {
  22.                 if (evt.getPropertyName().equals("page")) {
  23.                     loaded = true;
  24.                 }
  25.         });
  26.  
  27.         editorPane.setPage(url);
  28.         while (!loaded) {
  29.             Thread.yield();
  30.         }
  31.  
  32.         File file = new File("test.png");
  33.  
  34.         componentToImage(editorPane, file);
  35.     }
  36.  
  37.     public static void componentToImage(Component comp, File file) throws IOException {
  38.         Dimension prefSize = comp.getPreferredSize();
  39.         BufferedImage img = new BufferedImage(prefSize.width, comp.getPreferredSize().height,
  40.                                               BufferedImage.TYPE_INT_ARGB);
  41.         Graphics graphics = img.getGraphics();
  42.         comp.setSize(prefSize);
  43.         comp.paint(graphics);
  44.         ImageIO.write(img, "png", file);
  45.     }
  46. }
  47.  
  48.  
  49.  

Please can someone tell me what I need to do to make sure that the images on the webpage also show up in the final png being created?


Thanks,
Himzi
Apr 6 '10 #1
0 1533

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ming | last post by:
Hi All, I want to write a PHP webpage which allows people to upload images (no matter what formats) to me and at the same time converts any non-jpeg image to JPEG. Here's what I have: ...
9
by: yawnmoth | last post by:
i've written a php script that generates images dynamically, via the GD library. i now want to detect whether or not the image is embedded within a homepage, or is being viewed by itself. at...
1
by: teknowbabble | last post by:
I would like to know how to convert HTML code that users input into a TEXTAREA box on a HTML FORM into a separate WEBPAGE. I have something like the diagram below on my webpage. The user is...
1
by: Saish | last post by:
hi all i'm working with a project in which we have to perform operations on a webpage using c#, i have a small problem, i want to geat the image from a webpage and i have to perform operations...
0
by: prakash | last post by:
Dear Friends I am new guy to Visual C++.NET I've program to save website as a image vc++.net . It have a function "SaveSnapshot" to save the webpage as an image On that function ifor saving...
12
by: M.L. | last post by:
When loaded from my hard drive, the webpage I'm working on renders fine on IE6, Firefox 2.0.0.1, and Opera 9.02. However, after uploading it to the web there are 2 images that fail to display on...
0
by: =?Utf-8?B?Q2hha3JhdmFydGh5?= | last post by:
Hi, Have been trying to capture the webpage as image from quite a long time. Can some one suggest me a solution to convert or capture the HTML Output of any webresponse to anykind of image...
9
by: Prince of Code | last post by:
How do i create a image of webpage in php? Basically what I am looking for is "Create a small image (Thumbnail) of a webpage. Let me know about your thought. Your Help is greatly appreciated !...
0
by: levi2713 | last post by:
We have IP cameras that we can view by putting the IP address in a web browser. This is a control panel type webpage, but I can go a step further and go to http://<ip address>/capture.html and it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.