Good day!
I’m using Aspose.Words (version 16.3.0) and Aspose.PDF (version 11.4.0) java libraries. I need to convert documents from different formats (particularly from DOCX, TXT and PDF) to ODT format. However some convertion results contain several format and appearance issues.
The most important issue is that numeration and bullet markers are shifted in arbitrary way and sometimes extra spaces are added. So I attached some source document (in source.zip) and appropriate convertion results (results.zip) to demonstrate problems.
So, can I solve these issues by SaveOptions instance settings or something else? Or is it a bug?
Here the code snippets how do I convert from .docx to .odt:
protected Document to(Document src, int saveFormat)
{
SaveOptions opts = getSaveOptions(saveFormat);
byte[] bytes = new byte[0];
ILogger logger = LoggerSystem.getLogger(this.getClass().getName());
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
src.save(bos, opts);
bytes = bos.toByteArray();
} catch (Exception e)
{
logger.warn("Fail converting document because of:\n" + ExceptionUtils.getFullStackTrace(e));
return null;
}
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes)) {
return new com.aspose.words.Document(bis);
} catch (Exception e)
{
logger.warn("Fail converting document because of:\n" + ExceptionUtils.getFullStackTrace(e));
return null;
}
}
private SaveOptions getSaveOptions(int saveFormat)
{
if (saveFormat < 0) return null;
switch (saveFormat)
{
//… - here other formats convertion were skipped
case DOC:
case DOCX:
case DOCM:
case DOT:
case DOTM:
case DOTX:
DocSaveOptions dso = new DocSaveOptions();
dso.setUpdateFields(false);
dso.setSaveFormat(saveFormat);
return dso;
case ODT:
case OPEN_XPS:
case OTT:
OdtSaveOptions oso = new OdtSaveOptions(saveFormat);
oso.setUseHighQualityRendering(true);
oso.setPrettyFormat(true);
return oso;
default:
return null;
}
}
What about convertion from PDF, I use convertion from PDF to DOCX at the beginning then from DOCX to ODT.