Free Support Forum - aspose.com

Am I using this wrong- or is the eval crippled?

I am working on a proof of concept and am having an issue. I am to move through a document, intserting text at varioud bookmarks in the document and then saving it as a new copy. I am getting the document, accessing the bookmarks with no exception, and am saving it to the new location - but the only information in the new document is the garbage text that the evaluation version puts in - not my new text…

Below is my code:


try

{

//load the original document

Document doc = new Document(spec.OriginalFilePath);

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Font.Size = 24;

builder.Font.Bold = true;

builder.Font.Color = System.Drawing.Color.Blue;

builder.Font.Name = “Arial”;

builder.Underline = Underline.Dash;

foreach(string bookmarkName in spec.Replacements.Keys)

{

try

{

builder.MoveToBookmark(bookmarkName, true, true);

Console.WriteLine(“Adding: " + (string)spec.Replacements[bookmarkName] + " to the document”);

builder.Write((string)spec.Replacements[bookmarkName]);

// builder.InsertCheckBox(“bob”, false, 40);

}

catch(Exception e)

{

Console.WriteLine("Error updating bookmark name: " + bookmarkName + " : " + e.Message);

}

}

string newName = “foo.doc”;

doc.Save(spec.OutputDirectory + “/” + newName);

return true;

}

catch(Exception ex)

{

Console.WriteLine("Error performing replacement: " + ex.Message);

return false;

}







The “spec” object is an object containing references to the original doc, the

directory for the new one, and the replacements to be made.

NO errors are being reported to the console.

What am I missing here?


Thank you in advance.

B

Actually the original doc is covered by an NDA and I can't attach it, but will, if I have to, come up with a test case that shows the issue.

ok, so instead of moving to the bookmark, I assign to the Text property of the bookmark, but that also causes some rather bad output as I iterate over the bookmarks in the document. Ideas?

Thanks,
B

attached is the original

attached is the generated document.

The Code.


try

{

//load the original document

Document doc = new Document(spec.OriginalFilePath);

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Font.Size = 24;

builder.Font.Bold = true;

builder.Font.Color = System.Drawing.Color.Blue;

builder.Font.Name = "Arial";

builder.Underline = Underline.Dash;

foreach(string bookmarkName in spec.Replacements.Keys)

{

try

{

Bookmark bm = doc.Range.Bookmarks[bookmarkName];

bm.Text = (string)spec.Replacements[bookmarkName];

}

catch(Exception e)

{

Console.WriteLine("Error updating bookmark name: " + bookmarkName + " : " + e.Message);

}

}

string newName = "foo.doc";

doc.Save(spec.OutputDirectory + "/" + newName);

return true;

}

catch(Exception ex)

{

Console.WriteLine("Error performing replacement: " + ex.Message);

return false;

}


So now I think nevermind. I modified the original document, removing some of the odd formatting, and the previous code does what one would think…

I apologize for the crippled comment, and look forward to proofing your product to the customer for use. It is great when the input isn’t mangled.