Inserting an image from URL

Hi,

I am trying to insert a image from URL into a document.Here is the code i have written to insert an image into the document.

public class AsposeImage
{
    public static void main(String[] args)
    {
        try
        {
            DocumentBuilder builder = new DocumentBuilder();
            builder.write("Image from an internet url, automatically downloaded for you: ");
            builder.insertImage("https://www.google.com/accounts/lh2/gp/left-7.jpg");
            builder.writeln();

            builder.getDocument().save("C:\Image.CreateFromUrl Out_4.doc");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

I am Getting "java.net.ConnectException: Connection refused: connect " Exception while running the program.

I am using Aspose 3.0 jdk 1.5 and java 1.5

can any one please help me on this…

Advance Thanks

~Rajesh

Hi Rajesh,
Thanks for your request. I cannot reproduce the problem on my side. I use the latest version of Aspose.Words for Java for testing. You can download it from here:
https://releases.aspose.com/words/java/
Best regards,

Hi Andrey,

Thanks For ur Quick Reply…

I am still getting the issue with latest aspose jar file also.

can u please confirm me with the same code u r able to generate the document.
if not can u send me the code .

Advance Thanks
Rajesh

Hi
Thanks for your request. I used the same code as yours for testing. I attached the document generated on my side. As you can see the image is inserted properly.
Maybe the problem is causes because your firewall blocked the request. Have you tried on another machine?
Best regards,

Hi Andrey,

Thank Q very much for ur reply…

i have made the firewall settings and now the image was inserting into the document.

Now i am agian getting the same exception .Here is the below code what i am trying

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.awt.image.BufferedImage;
import java.net.URL;

import javax.imageio.ImageIO;

import com.aspose.words.DocumentBuilder;

public class AsposeImage {

    public static void main(String[] args) {
        try {
            DocumentBuilder builder = new DocumentBuilder();
            builder.write("Image from an internet url, automatically downloaded for you: ");
            String ImageURL ="https://www.google.com/accounts/lh2/gp/left-7.jpg";
            URL url = new URL(ImageURL);
            BufferedImage image = javax.imageio.ImageIO.read(url);
            builder.insertImage(image);
            builder.writeln();
            builder.getDocument().save("C:\Image.CreateFromUrl Out_6.doc");
        } catch (Exception e) {
            System.out.println("Protocol Exception");
            e.printStackTrace();
        }
    }
}

can you please help me on this

Advance Thanks

Hi
Thank you for additional information. I still cannot reproduce the problem on my side. The picture is present in my output document. I used the same code as yours.
Best regards,