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

Free Support Forum - aspose.com

Quotation marks Word

Hi,


I have problem with extraction text, I extract text, do what I need with him but when I save it to my word document quotation marks are not same as in original document and I have more words (see word count in Word) in my saved document. Here is my test:

public class QuotationMarksAspose extends AbstractTests {

@Test
public void test() throws Exception {

Document document=new Document("/home/emisia/Desktop/Navodnici.doc");
TestVisitor visitor = new TestVisitor(document);

document.accept(visitor);

document.save("/home/emisia/Desktop/Quotation.doc");
}

}

second class:


public class TestVisitor extends DocumentVisitor {
DocumentBuilder docB;

public TestVisitor(Document documente) {
super();
this.docB = new DocumentBuilder(documente);
docB.moveToDocumentStart();
}

@Override
public int visitParagraphStart(Paragraph paragraph) throws Exception {
return super.visitParagraphStart(paragraph);
}

@Override
public int visitParagraphEnd(Paragraph paragraph) throws Exception {

try {
File file = new File("/home/emisia/Desktop/textAsFile.txt");
FileOutputStream fos = new FileOutputStream(file);
fos.write(paragraph.getText().getBytes());
fos.close();
} catch (FileNotFoundException e1) {

e1.printStackTrace();
} catch (IOException e1) {

e1.printStackTrace();
}
paragraph.removeAllChildren();

File file = new File("/home/emisia/Desktop/textAsFile.txt");
String text = FileUtils.readFileToString(file);

docB.write(text);

return super.visitParagraphEnd(paragraph);
}
}

Can You help me?


Thanks

Hi Djordje,


Thanks for your inquiry. This doesn’t seem to be a problem in Aspose.Words. Please try running the following code to confirm this:
static class TestVisitor extends DocumentVisitor {
DocumentBuilder docB;
<font color="RED"><b>public</b></font> TestVisitor<font color="BLUE"><b>(</b></font>Document documente<font color="BLUE"><b>)</b></font> <font color="BLUE"><b>{</b></font>
    <font color="RED"><b>super</b></font><font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
    <font color="RED"><b>this</b></font><font color="BLUE"><b>.</b></font>docB <font color="BLUE">=</font> <font color="RED"><b>new</b></font> DocumentBuilder<font color="BLUE"><b>(</b></font>documente<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
    docB<font color="BLUE"><b>.</b></font>moveToDocumentStart<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
<font color="BLUE"><b>}</b></font>

@Override
<font color="RED"><b>public</b></font> <font color="RED"><b>int</b></font> visitParagraphStart<font color="BLUE"><b>(</b></font>Paragraph paragraph<font color="BLUE"><b>)</b></font> <font color="RED"><b>throws</b></font> Exception <font color="BLUE"><b>{</b></font>
    <font color="RED"><b>return</b></font> <font color="RED"><b>super</b></font><font color="BLUE"><b>.</b></font>visitParagraphStart<font color="BLUE"><b>(</b></font>paragraph<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
<font color="BLUE"><b>}</b></font>

@Override
<font color="RED"><b>public</b></font> <font color="RED"><b>int</b></font> visitParagraphEnd<font color="BLUE"><b>(</b></font>Paragraph paragraph<font color="BLUE"><b>)</b></font> <font color="RED"><b>throws</b></font> Exception <font color="BLUE"><b>{</b></font>

    <font color="RED"><b>try</b></font> <font color="BLUE"><b>{</b></font>
        docB<font color="BLUE"><b>.</b></font>writeln<font color="BLUE"><b>(</b></font>paragraph<font color="BLUE"><b>.</b></font>toString<font color="BLUE"><b>(</b></font>SaveFormat<font color="BLUE"><b>.</b></font>TEXT<font color="BLUE"><b>)</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
    <font color="BLUE"><b>}</b></font> <font color="RED"><b>catch</b></font> <font color="BLUE"><b>(</b></font>FileNotFoundException e1<font color="BLUE"><b>)</b></font> <font color="BLUE"><b>{</b></font>

        e1.printStackTrace<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
    <font color="BLUE"><b>}</b></font> <font color="RED"><b>catch</b></font> <font color="BLUE"><b>(</b></font>IOException e1<font color="BLUE"><b>)</b></font> <font color="BLUE"><b>{</b></font>

        e1.printStackTrace<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
    <font color="BLUE"><b>}</b></font>
    paragraph<font color="BLUE"><b>.</b></font>removeAllChildren<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>

    <font color="RED"><b>return</b></font> <font color="RED"><b>super</b></font><font color="BLUE"><b>.</b></font>visitParagraphEnd<font color="BLUE"><b>(</b></font>paragraph<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
<font color="BLUE"><b>}</b></font></font>

}

I think, there is something wrong with “text encoding” during writing to text file using File class instance or during re-loading the text file in File instance. Please try specifying a suitable encoding before performing these read/write operations using File class. I hope, this helps.

Best regards,

Hi,

thanks for answer but this isn’t helped me. I need to extract text to some xml document, work with him and than put it in document. In your code this will work and without code “SaveFormat.TEXT” in method toString(), but I can’t do with that text what I need.

Hi Djordje,


Thanks for your inquiry. I am working over your query and will get back to you soon.

Best regards,

Hi Djordje,


Thanks for being patient. I tested the scenario and have managed to reproduce the same problem on my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-9452. Our development team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-9452) have been fixed in this Aspose.Words for .NET 19.10 update and this Aspose.Words for Java 19.10 update.