Free Support Forum - aspose.com

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

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:SimSun; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

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:

http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/category1378.aspx

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


<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:SimSun; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

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,