Follows the code
public byte[] converterHtmlParaDoc(byte[] doc) throws Exception
{
XComponent xComp =
getFachadaOpenOffice().carregarDocumentoOpenOffice(doc,
FachadaOpenOffice.TIPO_HTML);
byte[] docConvertido = null;
if (xComp != null)
{
docConvertido = getFachadaOpenOffice().converterDocumento(xComp,
FachadaOpenOffice.TIPO_DOC);
}
public XComponent carregarDocumentoOpenOffice(byte[] doc, String tipo)
throws Exception
{
try
{
XDesktop desktop = obterComponenteDesktop();
XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime
.queryInterface(XComponentLoader.class, desktop);
OOInputStream oois = new OOInputStream(doc);
PropertyValue[] loadProps = new PropertyValue[3];
loadProps[0] = new PropertyValue();
loadProps[0].Name = "Hidden";
loadProps[0].Value = new Boolean(true);
loadProps[1] = new PropertyValue();
loadProps[1].Name = "FilterName";
loadProps[1].Value = new Boolean(true);
loadProps[2] = new PropertyValue();
loadProps[2].Name = "InputStream";
loadProps[2].Value = oois;
if (tipo.equals(TIPO_HTML))
{
loadProps[1].Value = HTML_IMPORT;
} else if (tipo.equals(TIPO_DOC))
{
loadProps[1].Value = DOC_EXPORT;
} else if (tipo.equals(TIPO_RTF))
{
loadProps[1].Value = RTF_EXPORT;
}
XComponent xComponent =
xComponentLoader.loadComponentFromURL("private:stream", "_blank",
0, loadProps);
Thread.sleep(1000);
return xComponent;
} catch (java.lang.Exception e)
{
throw e;
}
}
public byte[] converterDocumento(XComponent documento, String
tipoDocumento)
throws Exception
{
XTextDocument aTextDocument = (XTextDocument) UnoRuntime.queryInterface(
com.sun.star.text.XTextDocument.class, documento);
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
XStorable.class, aTextDocument);
OOOutputStream streamSaida = new OOOutputStream();
PropertyValue[] storeProps = new PropertyValue[4];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
if (tipoDocumento.equals(TIPO_RTF))
{
storeProps[0].Value = RTF_EXPORT;
} else if (tipoDocumento.equals(TIPO_DOC))
{
storeProps[0].Value = DOC_EXPORT;
} else if (tipoDocumento.equals(TIPO_PDF))
{
storeProps[0].Value = PDF_EXPORT;
}else if (tipoDocumento.equals(TIPO_HTML))
{
storeProps[0].Value = HTML_IMPORT;
}
storeProps[1] = new PropertyValue();
storeProps[1].Name = "CompressMode";
storeProps[1].Value = "0";
storeProps[2] = new PropertyValue();
storeProps[2].Name = "Overwrite";
storeProps[2].Value = Boolean.TRUE;
storeProps[3] = new PropertyValue();
storeProps[3].Name = "OutputStream";
storeProps[3].Value = streamSaida;
xStorable.storeToURL("private:stream", storeProps);
Thread.sleep(1000);
byte[] result = streamSaida.toByteArray();
XCloseable xcloseable = (XCloseable)UnoRuntime.
queryInterface( XCloseable.class,xStorable );
if ( xcloseable != null )
{
try
{
xcloseable.close();
}
catch (SQLException ex5)
{
}
}
streamSaida.close();
return result;
}
private static void testarConversaoHTMLParaRTF() throws Exception
{
LOG.info("testarConversaoHTMLParaRTF - Iniciando ...");
ByteArrayOutputStream streamAux = new ByteArrayOutputStream();
FileInputStream streamEntrada = new FileInputStream(new File(
FachadaOpenOffice.obterInstancia().getDiretorioBase()
+ "testarConversaoHTMLParaRTF.html"));
IOUtils.copy(streamEntrada, streamAux);
byte[] streamSaida = Conversor.obterInstancia().converterHtmlParaRtf(
streamAux.toByteArray());
FileOutputStream documentoFinal = new FileOutputStream(new File(
FachadaOpenOffice.obterInstancia().getDiretorioBase()
+ "testarConversaoHTMLParaRTF_Saida.rtf"));
documentoFinal.write(streamSaida);
documentoFinal.close();
streamEntrada.close();
streamAux.close();
LOG.info("testarConversaoHTMLParaRTF - Sucesso");
}
InputFile http://www.nabble.com/file/3987/testarConversaoHTMLParaRTF.html
testarConversaoHTMLParaRTF.html
OutputFile
http://www.nabble.com/file/3988/testarConversaoHTMLParaRTF_Saida.rtf
testarConversaoHTMLParaRTF_Saida.rtf
Juergen Schmidt-3 wrote:
>
> aloizio wrote:
>> Generally, when we convert one document to other formats we want to keep
>> the
>> formatting. In my case, the document has other sentences that are
>> centralized in the text and they appear centralized after converting.
>> This
>> happens with some sentences not all of them.
>
> create an example document + maybe a macro how you convert the document
> to other formats, so that the bug can be easy reproduced and submit an
> issue.
>
> Juergen
>
>>
>>
>>
>> Juergen Schmidt-3 wrote:
>>> Tobias Krais wrote:
>>>> Hi aloizio,
>>>>
>>>>> I am converting one HTML document into PDF and RTF. The HTML document
>>>>> has
>>>>> some centralized texts. After the convertion the centralized texts or
>>>>> part
>>>>> of them has left alignment. Why do this happens? I am losing the
>>>>> original
>>>>> format.
>>>> there was a thread about converting to and from HTML documents some
>>>> months ago. There seem to be several problems with html documents. I
>>>> think you'll just have to accept it...
>>> no, you should at least submit an issue for that problem, the lost of
>>> information is always critical
>>>
>>> Juergen
>>>
>>>> Greetings, Tobias
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/losing-docuemnt-format-during-convertion-tf2569321.html#a7200631
Sent from the openoffice - api dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]