By: Jeroen van Sluijs
Date: 2006-06-15
Time: 14:43
|
Convert html-styles to open office doc.Hello,
I use a WYSIWYG editor, which stores the text in html-format. Is it possible to convert html-styles like <b>bold text</b>, so the 'bold text' will actually be bold in the generated .odt file? I noticed only line-breaks are converted (\n converted to <text:line-break/>). E.g. template.odt:
The tag is to be replaced by <b>bold text</b>, so the result will be an output_document.odt with the string 'bold text' as bold text. I've been experimenting with this some time, but I can only manage to find a quite difficult/nasty solution. This would be looking up the bold style in the xml-document (after <office:automatic-styles>) and then inserting <b>bold text</b> in the content.xml as
The ugly way would be adding a bold, italic and underlined text at the beginning of the template. In this way, you'll always be sure that bold is mapped to T1, italic->T2 and underlined->T3. Thanks for any help in advance, Jeroen ps. I think I just posted a thread in the wrong forum. I'll try it here again :) |
|||||
By: Olivier Loynet
Date: 2006-06-19
Time: 07:16
|
Re: Convert html-styles to open office doc.Hi,
You're in the good forum... I understand your question, and as now, you can't send some XML tags in the data, the < and > are converted to < and > It will be possible next as with new parameters with tag like for HTML http://www.tinybutstrong.com/manual.php#html_field_prm_htmlconv You can make a workaround in this way in your template:
Then you select [var.content;if [var.style]=1;then [val]] and apply your first style, like bold Second you select [var.content;if [var.style]=2;then [val]] and apply your first style, like italic and in your PHP code you can do :
I've made a test and it works. Now, you have to make a converter from HTML by analyse your data content and call the good style Hope that can help Olivier |
|||||
By: Jeroen van Sluijs
Date: 2006-06-20
Time: 11:22
|
Re: Convert html-styles to open office doc.Hi Olivier
Thanks for the example. I managed to get it work on my PC as well. I've still got 2 questions: 1) I'm only wondering how these global varables $content and $style work. Do they have to be global, or can I put them somewhere else in my own application. In other words, where are $style and $content mapped on 'style' and 'content' in the .odt template? 2) I'm not quite sure if I can use this way of using styles. Let's say I've got this html text:
My php-code would be:
So I'll have to pre-define $contentA - $contentE and $styleA - $styleE in my .odt templte? Or am I misunderstanding something now? Thanks, Jeroen |
|||||
By: Olivier Loynet
Date: 2006-06-20
Time: 15:28
|
Re: Convert html-styles to open office doc.Hi,
I understand your problem to transform a HTML string like your example to the XML OOo equivalent with OOo style
As now, you can't do it easy, and the example I send to you is just to swap beetween 2 styles or more, but for the entire string. You can try in the class to comment the following lines
so you can merge your data with yours XML tags... exemple of XML in the 'content.xml'
and merge your OOo file with the PHP var like is $foo
Be sure in yours data to convert the < and > if there are no XML tags because you'll have an error while opening your OOo file. Olivier |
|||||
By: Jeroen van Sluijs
Date: 2006-06-20
Time: 15:59
|
Re: Convert html-styles to open office doc.Hi,
Only thing is, that you always have to define "T1" and "T2" at the beginning of the open office template, to be sure which tag is which style. Right? I already noticed that "T1" becomes the tag for the first used style and "T2" for the 2nd one and so on. Maybe it can be achieved by using:
Greetings, Jeroen ps. I hope this will work. I'm looking for a solution to use 'bullets' as well. |