hi,
Even with the lower case its not working, I've checked.
If I am going to implement ImageProvider, I am reading a HTML file on
the server, then don't I have to parse the file, search for all the img
tags and then process it?
Also I tried like
objects = htmlWorker.parseToList(new FileReader("index.html"),
styles, interfaceProps);
for (int k = 0; k < objects.size(); ++k)
document.add((Element) objects.get(k));
In this case also I get only the text, but in this way, the CSS in the
HTML doc is not applied :( and neither the images.
Looks like I am doing something fundamentally wrong, and there are not
examples on their site like I am doing.
The main concern is that I am not generating the HTML file, its created
and all I have to do is to just convert it PDF, the HTML file has CSS
and paths of the images.
If there are any example it would be good.
Regards,
Vivek
> ------------------------------------------------------------------------
>
> Balder <mailto:balder@...>
> 24 February 2011 11:01 AM
>
>
>
>
> On 24/02/2011 11:40, Vivek Krishnan wrote:
>> Hi,
>>
>> I changed my code to what you mentioned Vibhav, but still no success,
>> here is what the code looks like now.
>>
>> document = new Document(PageSize.A4);
>> PdfWriter.getInstance(document, new
>> FileOutputStream("ContactSheet02.pdf"));
>> document.open();
>> htmlWorker = new HTMLWorker(document);
>> HashMap interfaceProps = new HashMap();
>> interfaceProps.put("IMG_BASEURL", "/Users/");
> it should be img_baseurl , not in caps. You could also implement
> ImageProvider and add the object to interfaceProps with key img_provider
>>
>> StyleSheet styles = new StyleSheet();
>> styles.loadTagStyle("li", "face", "garamond");
>> styles.loadTagStyle("span", "size", "8px");
>> styles.loadTagStyle("body", "font-family",
>> "times new roman");
>> styles.loadTagStyle("body", "font-size", "10px");
>> StringReader strReader = new
>> StringReader(str.toString());
>>
>> ArrayList<Element> objects =
>> htmlWorker.parseToList(strReader, styles, interfaceProps);
>>
>> for (int k = 0; k < objects.size(); ++k)
>> document.add((Element) objects.get(k));
>>
>> document.close();
>>
>> It just creates the PDF without the images :(. Oh, I am using iText
>> version 2.1.4, not sure if that makes a difference.
>>
>> Regards,
>> Vivek
>>
>>> ------------------------------------------------------------------------
>>>
>>> vaibhav gupta <mailto:vaibhav2383@...>
>>> 23 February 2011 10:11 PM
>>>
>>>
>>> Hi Vivek,
>>>
>>> The problem is that the image src path you have given is a relative.
>>> To use this you need to set "*img_baseurl*" property in the
>>> interface properties.
>>> To do this:
>>>
>>> /Dictionary<string, object> interfaceProps = new Dictionary<string,
>>> object>();/
>>> /interfaceProps.Add("img_baseurl", "Actual Path to the Image folder");/
>>>
>>> The /interfaceProps/ variable should be passed to the /HTMLWorker
>>> /during parsing of your document.
>>>
>>> Regards,
>>> Vaibhav Gupta
>>>
>>> */Please don't print this Email unless you really need to - this
>>> will preserve trees on planet earth./*
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Free Software Download: Index, Search & Analyze Logs and other IT
>>> data in
>>> Real-Time with Splunk. Collect, index and harness all the fast
>>> moving IT data
>>> generated by your applications, servers and devices whether
>>> physical, virtual
>>> or in the cloud. Deliver compliance at lower cost and gain new business
>>> insights. http://p.sf.net/sfu/splunk-dev2dev
>>> _______________________________________________
>>> iText-questions mailing list
>>> iText-questions@...
>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>>
>>> Many questions posted to this list can (and will) be answered with a
>>> reference to the iText book: http://www.itextpdf.com/book/
>>> Please check the keywords list before you ask for examples:
>>> http://itextpdf.com/themes/keywords.php
>>> ------------------------------------------------------------------------
>>>
>>> Vivek Krishnan <mailto:vksvicky@...>
>>> 23 February 2011 9:38 PM
>>>
>>>
>>> Hi Nurettin,
>>>
>>> Thanks for replying. I have checked that, my problem is that I have
>>> a well formed html file and I am reading the file in a Buffer and
>>>
>>> Document document=new Document(PageSize.A4);
>>> PdfWriter.getInstance(document,new FileOutputStream("Test.pdf"));
>>> document.open();
>>> HTMLWorker htmlWorker = new HTMLWorker(document);
>>> StringBuffer str = new StringBuffer();
>>> str.append("<html xmlns=\"http://www.w3.org/1999/xhtml\"
>>> xml:lang=\"en\" lang=\"en\"> ");
>>> str.append("<head>
>>> ");
>>> ..
>>> ...
>>> str.append(" <div
>>> class=\"image\"> ");
>>> str.append(" <img src=\"/Users/display.jpg\" width=\"800\"
>>> height=\"532\" alt=\"Display\" />");
>>> str.append(" <br /> ");
>>> str.append(" Lorem ipsum dolor sit amet. ");
>>> ...
>>> ...
>>> str.append("</body>");
>>> str.append("</html>");
>>> htmlWorker.parse(new StringReader(str.toString()));
>>> document.close();
>>>
>>> Only the link highlighted in BLUE is not begin displayed, but an
>>> empty-space is displayed for that height and width mentioned.
>>>
>>> Any idea?
>>>
>>> Regards,
>>> Vivek
>>>
>>> ------------------------------------------------------------------------
>>>
>>> Nurettin DAG <mailto:nurettindag@...>
>>> 23 February 2011 7:33 PM
>>>
>>>
>>> You may look at PdfImageProvider. Basically, it is an interface that
>>> you need to implement to provide iText with the actual images for a
>>> given img URL src and attributes as found in your source. You can
>>> define custom transformations of src URL in your PdfImageProvider
>>> instance.
>>>
>>> Nurettin
>>>
>>>
>>>
>>>
>>> --
>>> Nurettin DAG
>>> ------------------------------------------------------------------------------
>>> Free Software Download: Index, Search & Analyze Logs and other IT
>>> data in
>>> Real-Time with Splunk. Collect, index and harness all the fast
>>> moving IT data
>>> generated by your applications, servers and devices whether
>>> physical, virtual
>>> or in the cloud. Deliver compliance at lower cost and gain new business
>>> insights. http://p.sf.net/sfu/splunk-dev2dev
>>> _______________________________________________
>>> iText-questions mailing list
>>> iText-questions@...
>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>>
>>> Many questions posted to this list can (and will) be answered with a
>>> reference to the iText book: http://www.itextpdf.com/book/
>>> Please check the keywords list before you ask for examples:
>>> http://itextpdf.com/themes/keywords.php
>>> ------------------------------------------------------------------------
>>>
>>> Vivek Krishnan <mailto:vksvicky@...>
>>> 23 February 2011 5:25 PM
>>>
>>>
>>> Hi,
>>>
>>> I have a HTML file with some images, the image are stored in a
>>> static location and the path is in the HTML are also static,
>>>
>>> When I try to print the PDF of it, I only get the text, but not the
>>> images.
>>>
>>> How do I solve this?
>>>
>>> Regards,
>>> Vivek
>>
>>
>> ------------------------------------------------------------------------------
>> Free Software Download: Index, Search& Analyze Logs and other IT data in
>> Real-Time with Splunk. Collect, index and harness all the fast moving IT data
>> generated by your applications, servers and devices whether physical, virtual
>> or in the cloud. Deliver compliance at lower cost and gain new business
>> insights.http://p.sf.net/sfu/splunk-dev2dev
>>
>>
>> _______________________________________________
>> iText-questions mailing list
>> iText-questions@...
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>
>> Many questions posted to this list can (and will) be answered with a reference to the iText book:http://www.itextpdf.com/book/
>> Please check the keywords list before you ask for examples:http://itextpdf.com/themes/keywords.php
> Kind Regards
> Balder
> ------------------------------------------------------------------------------
> Free Software Download: Index, Search& Analyze Logs and other IT data in
> Real-Time with Splunk. Collect, index and harness all the fast moving IT data
> generated by your applications, servers and devices whether physical, virtual
> or in the cloud. Deliver compliance at lower cost and gain new business
> insights. http://p.sf.net/sfu/splunk-dev2dev
> _______________________________________________
> iText-questions mailing list
> iText-questions@...
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
> Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
> ------------------------------------------------------------------------
>
> Vivek Krishnan <mailto:vksvicky@...>
> 24 February 2011 10:40 AM
>
>
> Hi,
>
> I changed my code to what you mentioned Vibhav, but still no success,
> here is what the code looks like now.
>
> document = new Document(PageSize.A4);
> PdfWriter.getInstance(document, new
> FileOutputStream("ContactSheet02.pdf"));
> document.open();
> htmlWorker = new HTMLWorker(document);
> HashMap interfaceProps = new HashMap();
> interfaceProps.put("IMG_BASEURL", "/Users/");
>
> StyleSheet styles = new StyleSheet();
> styles.loadTagStyle("li", "face", "garamond");
> styles.loadTagStyle("span", "size", "8px");
> styles.loadTagStyle("body", "font-family",
> "times new roman");
> styles.loadTagStyle("body", "font-size", "10px");
> StringReader strReader = new
> StringReader(str.toString());
>
> ArrayList<Element> objects =
> htmlWorker.parseToList(strReader, styles, interfaceProps);
>
> for (int k = 0; k < objects.size(); ++k)
> document.add((Element) objects.get(k));
>
> document.close();
>
> It just creates the PDF without the images :(. Oh, I am using iText
> version 2.1.4, not sure if that makes a difference.
>
> Regards,
> Vivek
>
>
> ------------------------------------------------------------------------
>
> vaibhav gupta <mailto:vaibhav2383@...>
> 23 February 2011 10:11 PM
>
>
> Hi Vivek,
>
> The problem is that the image src path you have given is a relative.
> To use this you need to set "*img_baseurl*" property in the interface
> properties.
> To do this:
>
> /Dictionary<string, object> interfaceProps = new Dictionary<string,
> object>();/
> /interfaceProps.Add("img_baseurl", "Actual Path to the Image folder");/
>
> The /interfaceProps/ variable should be passed to the /HTMLWorker
> /during parsing of your document.
>
> Regards,
> Vaibhav Gupta
>
> */Please don't print this Email unless you really need to - this will
> preserve trees on planet earth./*
>
>
>
> ------------------------------------------------------------------------------
> Free Software Download: Index, Search & Analyze Logs and other IT data in
> Real-Time with Splunk. Collect, index and harness all the fast moving
> IT data
> generated by your applications, servers and devices whether physical,
> virtual
> or in the cloud. Deliver compliance at lower cost and gain new business
> insights. http://p.sf.net/sfu/splunk-dev2dev
> _______________________________________________
> iText-questions mailing list
> iText-questions@...
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Many questions posted to this list can (and will) be answered with a
> reference to the iText book: http://www.itextpdf.com/book/
> Please check the keywords list before you ask for examples:
> http://itextpdf.com/themes/keywords.php
> ------------------------------------------------------------------------
>
> Vivek Krishnan <mailto:vksvicky@...>
> 23 February 2011 9:38 PM
>
>
> Hi Nurettin,
>
> Thanks for replying. I have checked that, my problem is that I have a
> well formed html file and I am reading the file in a Buffer and
>
> Document document=new Document(PageSize.A4);
> PdfWriter.getInstance(document,new FileOutputStream("Test.pdf"));
> document.open();
> HTMLWorker htmlWorker = new HTMLWorker(document);
> StringBuffer str = new StringBuffer();
> str.append("<html xmlns=\"http://www.w3.org/1999/xhtml\"
> xml:lang=\"en\" lang=\"en\"> ");
> str.append("<head>
> ");
> ..
> ...
> str.append(" <div
> class=\"image\"> ");
> str.append(" <img src=\"/Users/display.jpg\" width=\"800\"
> height=\"532\" alt=\"Display\" />");
> str.append(" <br /> ");
> str.append(" Lorem ipsum dolor sit amet. ");
> ...
> ...
> str.append("</body>");
> str.append("</html>");
> htmlWorker.parse(new StringReader(str.toString()));
> document.close();
>
> Only the link highlighted in BLUE is not begin displayed, but an
> empty-space is displayed for that height and width mentioned.
>
> Any idea?
>
> Regards,
> Vivek
>
> ------------------------------------------------------------------------
>
> Nurettin DAG <mailto:nurettindag@...>
> 23 February 2011 7:33 PM
>
>
> You may look at PdfImageProvider. Basically, it is an interface that
> you need to implement to provide iText with the actual images for a
> given img URL src and attributes as found in your source. You can
> define custom transformations of src URL in your PdfImageProvider
> instance.
>
> Nurettin
>
>
>
>
> --
> Nurettin DAG
> ------------------------------------------------------------------------------
> Free Software Download: Index, Search & Analyze Logs and other IT data in
> Real-Time with Splunk. Collect, index and harness all the fast moving
> IT data
> generated by your applications, servers and devices whether physical,
> virtual
> or in the cloud. Deliver compliance at lower cost and gain new business
> insights. http://p.sf.net/sfu/splunk-dev2dev
> _______________________________________________
> iText-questions mailing list
> iText-questions@...
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Many questions posted to this list can (and will) be answered with a
> reference to the iText book: http://www.itextpdf.com/book/
> Please check the keywords list before you ask for examples:
> http://itextpdf.com/themes/keywords.php
|