We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose Words for Java - Issue with converting DocX in compatibility mode to pdf

Hello ,


I am having an issue with converting a source document ( doc or docx) that is in compatibility mode.
Is there a way I can possibly handle that ? Is there way for me to convert it to a non compatible mode using aspose and convert it to pdf ?

Could you tell me how I can modify this code to handle the compatibility mode issue I am running into.
Thanks
Sharadha

InputStream in= new ByteArrayInputStream(... some source byte array ...);

ByteArrayOutputStream out = new ByteArrayOutputStream();

com.aspose.words.Document doc = null;

int asposeOutputFormat=-1;

switch ( documentByteContent.getDestinationDocumentType().getNumber() ) {

case DocumentType.DOCTYPE_DOC_VALUE :

asposeOutputFormat=com.aspose.words.SaveFormat.DOC;

break;

case DocumentType.DOCTYPE_DOCX_VALUE :

asposeOutputFormat=com.aspose.words.SaveFormat.DOCX;

break;

case DocumentType.DOCTYPE_TXT_VALUE :

asposeOutputFormat=com.aspose.words.SaveFormat.TEXT;

break;

case DocumentType.DOCTYPE_RTF_VALUE :

asposeOutputFormat=com.aspose.words.SaveFormat.RTF;

break;

}

doc = new com.aspose.words.Document(in);

in.close();

doc.save(out, asposeOutputFormat);



Hi Sharadha,


Thanks for your inquiry. You can use CompatibilityOptions.OptimizeFor method which allows to optimize the document contents as well as default Aspose.Words behavior to a particular versions of MS Word. Use this method to prevent MS Word from displaying “Compatibility mode” ribbon upon document loading. Moreover, there are many CompatibilityOptions you can specify before saving to PDF to get the desired output. I hope, this helps.

Best regards,

Hello Hafeez,

Thanks for your reply. Would it be possible for you to send me a code snippet for using compatibitilytoptions please ? It would greatly help.

What i am trying to accomplish is to detect if a certain document is in compatibility mode and , if it is , then i want to be able to save it in a non compatibility mode for further operations on the document.

Thanks for your help.
Sharadha

Hi Sharadha,


Thanks for your inquiry. There are many public instance properties inside CompatibilityOptions class that you can turn On/Off as per your needs. For example, if you want to disable “Use printer metrics to lay out documents” compatibility option in Word, you can use the following code:

Document doc = new Document(getMyDir() + “in.docx”);
doc.getCompatibilityOptions().setUsePrinterMetrics(false);
doc.save(getMyDir() + “out.doc”);

I hope, this helps.

Best regards,