Document Builder has no effect


#1

I noticed some weird behavior today.

I have the following code hooked into an asp.net page. The page allows one to upload a word doc, add text to the doc, and then prompt them to open or download.

Stream fileStream = document1.PostedFile.InputStream;
Document doc = new Document(fileStream);
DocumentBuilder builder = new DocumentBuilder();
builder.Document = doc;

//builder.MoveToDocumentEnd();

builder.Font.Bold = true;
builder.Font.Color = Color.DarkBlue;
builder.Font.Italic = true;
builder.Font.Name = “Arial”;
builder.Font.Size = 24;
builder.Font.Spacing = 5;
builder.Font.Underline = Underline.Double;

// Output formatted text
builder.Writeln(“I’m a very nice formatted string.”);

doc.Save(“Report.doc”, SaveFormat.FormatDocument, SaveType.OpenInBrowser, Response);

Notice the MoveToDocumentEnd() Call. If I uncomment this line, on some word docs, nothing is appended to the document, while on others text is added to the end. If it is left uncommented, I always get the text output on the top.

Why would the MoveToDocumentEnd cause issues only on some documents? Is there a way to hack around this?


#2

It can be a bug. Please send us the document with which the DocumentBuilder displays this unwelcome behavior. It is necessary for us to be able to reproduce the error.


#3

I have attached a sample for you to test.

If you can figure out a work around in the meantime if this is a bug - please let me know.

- Ron


#4

The problem does not display itself on the attached document. I am executing the following code:

string filename = Application.StartupPath + @"\2.doc";

Document doc = new Document(filename);

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToDocumentEnd();

builder.Font.Bold = true;

builder.Font.Color = Color.DarkBlue;

builder.Font.Italic = true;

builder.Font.Name = "Arial";

builder.Font.Size = 24;

builder.Font.Spacing = 5;

builder.Font.Underline = Underline.Double;

// Output formatted text

builder.Writeln("I'm a very nice formatted string.");

doc.Save(Application.StartupPath + @"\2 Out.doc");

And it results in correct adding of the formatted string to the end of the document.

Please send us something that will allow to reproduce the error.


#5

Hmm - I will try out your code and get back to you. I was using this in an asp.net application - I am wondering if that may be an issue.



- Ron


#6

I have tested your code in a command line app. It still does not output the text using the attached document I sent you.

I even tried with another document and it worked - just like my original asp.net file.

Could it have anything to do with the fact that the file uses a template? I am a bit lost on this one. Why would it work for you and not me?

Thanks in advance,

- Ron


#7

What version of Aspose.Words are you using?


#8

I was able to replicate this both with aspose.word 3.3.3 and the latest aspose.words.



I was hoping for a version thing - but it didn’t seem to matter.



I am also using Word 2003, fully patched.


#9

If you are able to reproduce the error on your side then please attach the zipped project illustrating the error - so that I could test it here.


#10

Attached you will find my VS Project.

Please note that the class will look for a license file.

I also included the test document I have been using. I have tried this on several machine with no effect.


#11

The string is written to the end of file correctly. You don't see it because the font formatting of the text in the end of file is set to hidden.

To toggle visibility of hidden text in MS Word check Tools | Options | View | Formatting marks | Hidden text checkbox.

To change hidden setting of the font in MS Word uncheck Format | Font | Hidden checkbox.

To ensure that the string you are writing using DocumentBuilder will not be hidden set the following property:

builder.Font.Hidden = false;


#12

Wow - thanks!

I never thought that the text would be hidden. Great catch!