You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by gennady <ge...@yahoo.com> on 2009/01/26 21:17:58 UTC

How to convert HTML tags(rich text) into XML-FO?

I have a basic task. The website has a text area to type some comments.
Currently it's a regular text area and the text is appearing as is in
generated PDF using FOP-0.95. 
Now new task is to enable user to create rich text for the comments. I will
probably use Yahoo UI JavaScript library. Or do you have other suggestions?
As a result, Yahoo JS will generate some HTML tags in this text. So how to
convert those tags into PDF with FOP (how to interpret those tags)?
Thank you,

-Gennady
-- 
View this message in context: http://www.nabble.com/How-to-convert-HTML-tags%28rich-text%29-into-XML-FO--tp21672932p21672932.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: How to convert HTML tags(rich text) into XML-FO?

Posted by gennady <ge...@yahoo.com>.
Hi Ferran,
Thank you for your suggestion.
Actually, this is what I ended up doing in FOP jsp file:
               //handle bold
	  formatNotes = formatNotes.replaceAll("<strong>", "<fo:wrapper
font-weight=\"bold\">");
	  formatNotes = formatNotes.replaceAll("</strong>", "</fo:wrapper>");
	  //handle italic
	  formatNotes = formatNotes.replaceAll("<em>", "<fo:wrapper
font-style=\"italic\">");
	  formatNotes = formatNotes.replaceAll("</em>", "</fo:wrapper>");
	  //handle color
	  formatNotes = formatNotes.replaceAll("", "</fo:wrapper>");
	  //handle font-size
	  formatNotes = formatNotes.replaceAll("", "<fo:wrapper
text-decoration=\"underline\">");
	  formatNotes = formatNotes.replaceAll("</u>", "</fo:wrapper>");
	  
	  formatNotes = formatNotes.replaceAll("<p>", "");
	  formatNotes = formatNotes.replaceAll("</p>", "");

And then finally, this:<fo:block font-size="12pt" text-align="left"
font-family="sans-serif" color="black">
                         <fo:wrapper font-weight="bold">My
Remarks:</fo:wrapper>     
                          <%= formatNotes %>
                          </fo:block>

I know, it's a stupid way, but it works out well - doesn't create me any
extra stuff.

-Gennady
 

Ferran Basora wrote:
> 
> Hello,
> 
> I have developed a simple example using namespaces:
> 
> The XML:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> 	<name>TEST HTML-FO</name>
> 	<descripcion xmlns="http://www.w3.org/1999/xhtml">Pellentesque habitant
> morbi tristiquesenectus et netus et malesuada fames ac
> <u>turpis</u></descripcion>
> </root>
> 
> the XSLT:
> 
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format"
> xmlns:xhtml="http://www.w3.org/1999/xhtml">
> 
> ...
> 				<fo:flow flow-name="xsl-region-body" font-size="10pt">
> 					<fo:block font-size="15pt">
> 						<xsl:value-of select="name"/>
> 					</fo:block>
> 					<fo:block font-size="15pt">
> 						<xsl:apply-templates select="xhtml:descripcion"/>
> 					</fo:block>
> 				</fo:flow>
> ...
> 
> 	<!-- HTML ENTITIES -->
> 	<xsl:template match="xhtml:b">
> 		<fo:inline font-weight="bold">
> 			<xsl:apply-templates/>
> 		</fo:inline>
> 	</xsl:template>
> 	<xsl:template match="xhtml:i">
> 		<fo:inline font-style="italic">
> 			<xsl:apply-templates/>
> 		</fo:inline>
> 	</xsl:template>
> 	<xsl:template match="xhtml:u">
> 		<fo:inline text-decoration="underline">
> 			<xsl:apply-templates/>
> 		</fo:inline>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> May be it usefull...
> 
> I attach the files.
>  http://www.nabble.com/file/p22413453/htmlfo.xml htmlfo.xml 
>  http://www.nabble.com/file/p22413453/htmlfo.xslt htmlfo.xslt 
> 
> Bye!
> 
> 
> 
> 
> 
> 
> gennady wrote:
>> 
>> I have a basic task. The website has a text area to type some comments.
>> Currently it's a regular text area and the text is appearing as is in
>> generated PDF using FOP-0.95. 
>> Now new task is to enable user to create rich text for the comments. I
>> will probably use Yahoo UI JavaScript library. Or do you have other
>> suggestions?
>> As a result, Yahoo JS will generate some HTML tags in this text. So how
>> to convert those tags into PDF with FOP (how to interpret those tags)?
>> Thank you,
>> 
>> -Gennady
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-convert-HTML-tags%28rich-text%29-into-XML-FO--tp21672932p22501223.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: How to convert HTML tags(rich text) into XML-FO?

Posted by Ferran Basora <fc...@gmail.com>.
Hello,

I have developed a simple example using namespaces:

The XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<name>TEST HTML-FO</name>
	<descripcion xmlns="http://www.w3.org/1999/xhtml">Pellentesque habitant
morbi tristiquesenectus et netus et malesuada fames ac
<u>turpis</u></descripcion>
</root>

the XSLT:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xhtml="http://www.w3.org/1999/xhtml">

...
				<fo:flow flow-name="xsl-region-body" font-size="10pt">
					<fo:block font-size="15pt">
						<xsl:value-of select="name"/>
					</fo:block>
					<fo:block font-size="15pt">
						<xsl:apply-templates select="xhtml:descripcion"/>
					</fo:block>
				</fo:flow>
...

	<!-- HTML ENTITIES -->
	<xsl:template match="xhtml:b">
		<fo:inline font-weight="bold">
			<xsl:apply-templates/>
		</fo:inline>
	</xsl:template>
	<xsl:template match="xhtml:i">
		<fo:inline font-style="italic">
			<xsl:apply-templates/>
		</fo:inline>
	</xsl:template>
	<xsl:template match="xhtml:u">
		<fo:inline text-decoration="underline">
			<xsl:apply-templates/>
		</fo:inline>
	</xsl:template>
</xsl:stylesheet>

May be it usefull...

I attach the files.
http://www.nabble.com/file/p22413453/htmlfo.xml htmlfo.xml 
http://www.nabble.com/file/p22413453/htmlfo.xslt htmlfo.xslt 

Bye!






gennady wrote:
> 
> I have a basic task. The website has a text area to type some comments.
> Currently it's a regular text area and the text is appearing as is in
> generated PDF using FOP-0.95. 
> Now new task is to enable user to create rich text for the comments. I
> will probably use Yahoo UI JavaScript library. Or do you have other
> suggestions?
> As a result, Yahoo JS will generate some HTML tags in this text. So how to
> convert those tags into PDF with FOP (how to interpret those tags)?
> Thank you,
> 
> -Gennady
> 

-- 
View this message in context: http://www.nabble.com/How-to-convert-HTML-tags%28rich-text%29-into-XML-FO--tp21672932p22413453.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: How to convert HTML tags(rich text) into XML-FO?

Posted by Andreas Delmelle <an...@telenet.be>.
On 27 Jan 2009, at 18:52, Tatiyana Tarabara wrote:

Hi

> I am working on same problem as a was described below (using FOP to  
> create pdf with some dynamical fields entered by users included  
> field Comment) but I need to save  at least breaks in Comment  
> entered by users just to let them have all their paragraphs not  
> glued together. What you can recommend me to do besides to ask users  
> enter  each paragraphs as a separate comment?

If the content of the comment edit-box is posted back to the server,  
it will (should) contain only the linefeeds explicitly entered by the  
user. If that text is subsequently saved to a database and transformed  
to FO for output, then specifying linefeed-treatment="preserve" on the  
surrounding fo:block should suffice to keep the hard returns/paragraph  
marks in tact.



HTH!

Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: How to convert HTML tags(rich text) into XML-FO?

Posted by Tatiyana Tarabara <ta...@egr.msu.edu>.
Dear Andreas,

I am working on same problem as a was described below (using FOP to 
create pdf with some dynamical fields entered by users included field 
Comment) but I need to save  at least breaks in Comment entered by users 
just to let them have all their paragraphs not glued together. What you 
can recommend me to do besides to ask users enter  each paragraphs as a 
separate comment?

Thank you.
Tatiyana.

Andreas Delmelle wrote:
> On 27 Jan 2009, at 17:29, gennady wrote:
> 
>> Basically I am saving in the database some record from user input in 
>> Struts
>> Web app which has some 20 values like name, addreess, phone, email, 
>> ... and
>> 1 value "coments" which is saved like this:
>> just some comment. So I don't want to save this value comments as a 
>> separate
>> XHTML file.
> 
> Strictly speaking, you wouldn't need to save it as an XHTML *file*. If 
> you have it in a memory buffer somewhere, then this should do fine too, 
> but... (see below)
> 
>> For this I used Rich Text Editor I found here:
>> http://www.dynamicdrive.com/dynamicindex16/richtexteditor/index.htm
>> All I need is to send it along with name, address, etc. to FOP in 
>> order to
>> generate in PDF this - make word "comment" bolded:
>> just some comment
> 
> How then do you discern bold text from regular text in the source? I 
> mean: if the comment is saved in the database as "just some comment", 
> how would the processor know that the word "comment" is to appear in 
> bold? Are RTF commands stored in the database somehow?
> 
> Just a reminder: FOP converts FO to PDF (or other output formats). 
> That's it.
> For convenience, the user can also supply XML with a stylesheet that 
> transforms the XML to FO before FOP actually processes it. If you need 
> to render something else than XML to PDF, FOP is actually not suited for 
> that task.
> 
>>
>> So what is the best way/tool/library to use to accomplish this?
> 
> I can't really judge that based upon the info provided so far. It 
> depends greatly on the answer to my above question....
> 
> 
> Andreas
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: How to convert HTML tags(rich text) into XML-FO?

Posted by Andreas Delmelle <an...@telenet.be>.
On 27 Jan 2009, at 17:29, gennady wrote:

> Basically I am saving in the database some record from user input in  
> Struts
> Web app which has some 20 values like name, addreess, phone,  
> email, ... and
> 1 value "coments" which is saved like this:
> just some comment. So I don't want to save this value comments as a  
> separate
> XHTML file.

Strictly speaking, you wouldn't need to save it as an XHTML *file*. If  
you have it in a memory buffer somewhere, then this should do fine  
too, but... (see below)

> For this I used Rich Text Editor I found here:
> http://www.dynamicdrive.com/dynamicindex16/richtexteditor/index.htm
> All I need is to send it along with name, address, etc. to FOP in  
> order to
> generate in PDF this - make word "comment" bolded:
> just some comment

How then do you discern bold text from regular text in the source? I  
mean: if the comment is saved in the database as "just some comment",  
how would the processor know that the word "comment" is to appear in  
bold? Are RTF commands stored in the database somehow?

Just a reminder: FOP converts FO to PDF (or other output formats).  
That's it.
For convenience, the user can also supply XML with a stylesheet that  
transforms the XML to FO before FOP actually processes it. If you need  
to render something else than XML to PDF, FOP is actually not suited  
for that task.

>
> So what is the best way/tool/library to use to accomplish this?

I can't really judge that based upon the info provided so far. It  
depends greatly on the answer to my above question....


Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: How to convert HTML tags(rich text) into XML-FO?

Posted by gennady <ge...@yahoo.com>.
Hi Andreas,
Basically I am saving in the database some record from user input in Struts
Web app which has some 20 values like name, addreess, phone, email, ... and
1 value "coments" which is saved like this:
just some comment. So I don't want to save this value comments as a separate
XHTML file. For this I used Rich Text Editor I found here:
http://www.dynamicdrive.com/dynamicindex16/richtexteditor/index.htm
All I need is to send it along with name, address, etc. to FOP in order to
generate in PDF this - make word "comment" bolded:
just some comment
So what is the best way/tool/library to use to accomplish this?
Thanks so much for help.

-Gennady

Andreas Delmelle-2 wrote:
> 
> On 26 Jan 2009, at 21:17, gennady wrote:
> 
> Hi Gennady
> 
>> I have a basic task. The website has a text area to type some  
>> comments.
>> Currently it's a regular text area and the text is appearing as is in
>> generated PDF using FOP-0.95.
>> Now new task is to enable user to create rich text for the comments.  
>> I will
>> probably use Yahoo UI JavaScript library. Or do you have other  
>> suggestions?
>> As a result, Yahoo JS will generate some HTML tags in this text. So  
>> how to
>> convert those tags into PDF with FOP (how to interpret those tags)?
> 
> Provided that the generated HTML is well-formed XHTML (= XML), it can  
> be transformed via XSLT to FO. There are various tools/stylesheets  
> available for that purpose, mentioned on FOP's resource page (
> http://xmlgraphics.apache.org/fop/resources.html#products-other 
>   )
> 
> 
> HTH!
> 
> Andreas
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-convert-HTML-tags%28rich-text%29-into-XML-FO--tp21672932p21688825.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: How to convert HTML tags(rich text) into XML-FO?

Posted by Andreas Delmelle <an...@telenet.be>.
On 26 Jan 2009, at 21:17, gennady wrote:

Hi Gennady

> I have a basic task. The website has a text area to type some  
> comments.
> Currently it's a regular text area and the text is appearing as is in
> generated PDF using FOP-0.95.
> Now new task is to enable user to create rich text for the comments.  
> I will
> probably use Yahoo UI JavaScript library. Or do you have other  
> suggestions?
> As a result, Yahoo JS will generate some HTML tags in this text. So  
> how to
> convert those tags into PDF with FOP (how to interpret those tags)?

Provided that the generated HTML is well-formed XHTML (= XML), it can  
be transformed via XSLT to FO. There are various tools/stylesheets  
available for that purpose, mentioned on FOP's resource page ( http://xmlgraphics.apache.org/fop/resources.html#products-other 
  )


HTH!

Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org