Hi everyone,
I am trying to add pictures into a html document and so far everthing has been going well but i have a question. Wen i insert the pictures into the html document they show up and i am able to save them to disk in html format.
The thing is when i delete the picture on the disk and read the html document the picture does not show up but if the picture is not deleted from the disk then when i read the html document the picture shows up.
Basically what i need to know if there is a way in which i can embed a picture into the html document without any reliance on the picture that is saved on a different location on the disk.
For example if the Styled Document is serialized with an embedded picture even if the picture is deleted from the disk when the Styled Document is read the picture is not there but this is not so for the HTML Document class.
Basically my question is that is it possible to implement something like that in which that the picture is embedded in the HTML Document and it does not matter if the picture is deleted or not from the disk thus even when the html document is read the embedded picture is still there.
This is what i am doing to insert the picture into the HTML Document
Note that the file name of the picture is converted to a URL and the Html Tag there always depend on the file name with the picture being there
FileChooser3.setDialogType(JFileChooser.OPEN_DIALOG);
FileChooser3.setDialogTitle("Select a picture to insert into document");
if(FileChooser3.showDialog(fr,"Insert") != JFileChooser.APPROVE_OPTION)
{
return;
}
File g = FileChooser3.getSelectedFile();
ImageIcon image1 = new ImageIcon(g.toString());
MutableAttributeSet mas1 = new SimpleAttributeSet();
//The below command line gets the width and height of the image
int w = image1.getIconWidth();
int h = image1.getIconHeight();
try
{
//The below six command line insertss the currently read in image into
//the JTextPane
mas1.addAttribute(StyleConstants.NameAttribute, HTML.Tag.IMG);
//The below command line is where the reliance occurs
mas1.addAttribute(HTML.Attribute.SRC, g.toURL().toString());
mas1.addAttribute(HTML.Attribute.HEIGHT, Integer.toString(h));
mas1.addAttribute(HTML.Attribute.WIDTH, Integer.toString(w));
int p = TextPane1.getCaretPosition();
htmldoc.insertString(p, " ", mas1);
}
catch(Exception e)
{
e.printStackTrace();
}
please note that htmldoc is an instance of the Java HTMLDocument class and TextPane1 is an instance of the Java JTextPane class
This is its HTMl equivalent that is generated in the html document
<html>
<head>
</head>
<body>
<p>
<img height="400" width="400" src="file:/D:/Sample_Pics/venu.jpg">
</p>
</body>
</html>
See the reliance on the picture picture always being on that location on the disk on this line
src="file:/D:/Sample_Pics/venu.jpg"
Is there a way to achieve what i need by simple ways or style sheets or any other way??
Any help is greatly appreciated
Thank You
Yours Sincerely
Richard West