Hello,
We are trying to compare two versions of the same file. Both versions contain textboxes, but the difference lies in the text formatting inside each textbox. However, when we run the comparison and then attempt to save the file using Aspose, we encounter the following error:
IllegalStateException: Cannot translate from '64' in '5' to '2'
.
Has anyone encountered this issue before? Any advice on how to resolve it would be greatly appreciated.
original.docx (15.7 KB)
modified.docx (15.8 KB)
Document originalVersion = documents.get(0);
Document modifiedVersion = documents.get(1);
originalVersion.updatePageLayout();
modifiedVersion.updatePageLayout();
originalVersion.compare(modifiedVersion, " ", Calendar.getInstance().getTime(), getCompareOptions());
document.save(os, PdfSaveOptionsProvider.create(useDocTitle));
Aspose version 24.9
expected result
@LuisParradfinsolutions
It seems you are encountering an IllegalStateException
when trying to compare two Word documents that contain textboxes. This error can occur due to various reasons, especially when the documents have different formatting or structure.
To troubleshoot and potentially resolve this issue, consider the following steps:
-
Update Page Layout: Ensure that you are updating the page layout for both documents before performing the comparison. This can help in aligning the formatting and structure of the documents.
originalVersion.updatePageLayout();
modifiedVersion.updatePageLayout();
-
Use Compare Options: When comparing documents, you can specify options to ignore certain elements that might be causing the issue. For instance, if the differences in textboxes are not critical, you can ignore them during the comparison:
CompareOptions options = new CompareOptions();
options.setIgnoreTextboxes(true);
// Set other options as needed
originalVersion.compare(modifiedVersion, "user", Calendar.getInstance().getTime(), options);
-
Check Document Structure: Ensure that both documents have a similar structure. Sometimes, differences in the number of textboxes or their properties can lead to exceptions during comparison.
-
Aspose Version: You mentioned using Aspose version 24.9. If possible, consider updating to the latest version of Aspose.Words, as newer versions may contain bug fixes and improvements that could resolve your issue.
-
Error Handling: Implement error handling to catch exceptions and log detailed information about the documents being compared. This can help in diagnosing the specific cause of the error.
If the issue persists after trying these steps, you may want to reach out to the Aspose support team with detailed information about the documents and the error message for further assistance.
Feel free to ask if you have any more questions or need further clarification!
@LuisParradfinsolutions Unfortunately, I cannot reproduce the problem on my side using the latest 25.2 version of Aspose.Words for Java. Please try using the latest version and let us know if the problem still persists on your side.
In addition, I see you call Document.updatePageLayout
before comparing document. This is not required.
@alexey.noskov, here is my code, and I’ve identified the part that’s causing the issue. When I add the line:
revisionOptions.setShowInBalloons(ShowInBalloons.FORMAT);
It causes an error. Do you know why this happens?
CODE
Document doc1 = new Document();
Section section1 = doc1.getSections().get(0);
Shape textbox1 = new Shape(doc1, ShapeType.TEXT_BOX);
textbox1.setWidth(300);
textbox1.setHeight(100);
textbox1.setTop(50);
textbox1.setLeft(50);
section1.getBody().getFirstParagraph().appendChild(textbox1);
Paragraph para1 = new Paragraph(doc1);
Run run1 = new Run(doc1, "New line");
para1.appendChild(run1);
textbox1.appendChild(para1);
para1.getParagraphFormat().setAlignment(0);
doc1.save("Documento1.docx");
Document doc2 = new Document();
Section section2 = doc2.getSections().get(0);
Shape textbox2 = new Shape(doc2, ShapeType.TEXT_BOX);
textbox2.setWidth(300);
textbox2.setHeight(100);
textbox2.setTop(50);
textbox2.setLeft(50);
section2.getBody().getFirstParagraph().appendChild(textbox2);
Paragraph para2 = new Paragraph(doc2);
Run run2 = new Run(doc2, "New line");
para2.appendChild(run2);
textbox2.appendChild(para2);
para2.getParagraphFormat().setAlignment(2);
doc2.save("Documento2.docx");
doc1.compare(doc2, " ", Calendar.getInstance().getTime(), getCompareOptions());
RevisionOptions revisionOptions = doc1t.getLayoutOptions().getRevisionOptions();
revisionOptions.setRevisionBarsColor(RevisionColor.GRAY_25);
revisionOptions.setInsertedTextColor(RevisionColor.GREEN);
revisionOptions.setDeletedTextColor(RevisionColor.RED);
revisionOptions.setCommentColor(RevisionColor.BLUE);
revisionOptions.setShowInBalloons(ShowInBalloons.FORMAT); //-> WHEN I ADD THIS OPTION, I GET THE ERROR
//save document
doc1.save(os, PdfSaveOptionsProvider.create(useDocTitle));
@LuisParradfinsolutions
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSJAVA-3056
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.