while converting xhtml with css to pdf got an exception java.lang.IndexOutOfBoundsException: Index: 8, Size: 8
<p>While I am converting my html page to pdf U got an <code>IndexOutOfBoundsException</code>.
First I convert my html string into a temporary html file whos name is tempFile, then html ------> xhtml+css. Then I get the exception.</p>

<p><strong>here is the code:</strong></p>

<pre><code>File tempFile = File.createTempFile("tempFile", "a.html");

OutputStream outhtml = new FileOutputStream(tempFile);
outhtml.write(htmlcode);
outhtml.flush();
outhtml.close();
System.out.println("check2   HtML file Created");
// /////////////////////////////////////////////////////////////
// /to create pdf////////////
// /////////////////////////////////////////////////
URL url = tempFile.toURI().toURL();
final String filepath = fup.getUploadFolderPath() + "/docs/";
final String site = url.toString();
final String cssUrl = site;
// URL url = new URL(site);
System.out.println("url is////////////" + url);
CleanerProperties props = new CleanerProperties();

// HTMLCleaner part
// set some properties to non-default values
props.setTranslateSpecialEntities(true);
props.setTransResCharsToNCR(true);
props.setOmitComments(true);
System.out.println("props is " + props);

// do parsing
TagNode tagNode = new HtmlCleaner(props).clean(url);
System.out.println("TagNode is " + tagNode);
tagNode.traverse(new TagNodeVisitor() {

    public boolean visit(TagNode tagNode, HtmlNode htmlNode) {
        if (htmlNode instanceof TagNode) {
            System.out.println("html node  is " + htmlNode);
            TagNode tag = (TagNode) htmlNode;
            System.out.println("tag  is " + tag);
            String tagName = tag.getName();
            if ("img".equals(tagName)) {
                String src = tag.getAttributeByName("src");
                if (src != null &amp;&amp; !src.startsWith("http")) {
                    tag.setAttribute("src", Utils.fullUrl(site, src));
                }
            }
            if ("link".equals(tagName)) {
                String rel = tag.getAttributeByName("rel");
                System.out.println("rel is is " + rel);
                String href = tag.getAttributeByName("href");

                System.out.println("href is " + href);

                if (href != null &amp;&amp; "stylesheet".equals(rel)) {
                    try {
                        HttpClient client = new DefaultHttpClient();
                        String fullUrl = "";
                        if (href.startsWith("http"))
                            fullUrl = href;
                        else
                            fullUrl = Utils.fullUrl(cssUrl, href);
                        HttpGet get = new HttpGet(fullUrl);
                        System.out.println("get is " + get);
                        HttpResponse response = client.execute(get);
                        System.out.println("response is " + response);
                        HttpEntity entity = response.getEntity();
                        System.out.println("entity is " + entity);
                        if (entity != null) {
                            InputStream is = entity.getContent();
                            System.out.println("is is " + is);
                            href = filepath + "css" + cssCounter
                                    + ".css";
                            System.out.println("href is " + href);
                            cssCounter++;
                            OutputStream os = new FileOutputStream(href);
                            System.out.println("os is " + os);
                            IOUtils.copy(is, os);
                        }
                        tag.setAttribute("href", href);
                    } catch (IOException ex) {
                        System.out.println(ex);
                    }
                }
            }
        } else if (htmlNode instanceof CommentNode) {
            CommentNode comment = ((CommentNode) htmlNode);
            System.out.println("comment is " + comment);
            comment.getContent().append(" -- By HtmlCleaner");
        }
        // tells visitor to continue traversing the DOM tree
        return true;
    }
});

// serialize to xml file
new PrettyXmlSerializer(props).writeToFile(tagNode, filepath
        + "/page.xhtml", "utf-8");
System.out.println("tag node later is " + tagNode);
System.out.println(" props  later is " + props);

// FlyingSaucer and iText part
String inputFile = filepath + "/page.xhtml";
String url2 = new File(inputFile).toURI().toURL().toString();
System.out.println("url2 is " + url2);
String outputFile = filepath + "/firstdoc.pdf";
System.out.println("check3");
OutputStream os = new FileOutputStream(outputFile);
System.out.println("check4");
ITextRenderer renderer = new ITextRenderer();
System.out.println("check5");
renderer.setDocument(url2);
System.out.println("check6");

renderer.layout();
System.out.println("check7");
renderer.createPDF(os);
System.out.println("check8");
os.close();

System.out.println("check9");
tempFile.delete();
</code></pre>

<p>and output is :--</p>

<pre><code>url2 is file:/home/east/workspace/spring-tms/WebContent/uploads/trips/docs/page.xhtml
check3
check4
check5
check6
java.lang.IndexOutOfBoundsException: Index: 8, Size: 8
</code></pre>

<p>this means error in    <code>renderer.layout();</code>   this line
but how i remove this exception?
help me plz.
Thanks in advance.</p>
