Free Support Forum -

Aspose Words and TextBox mangle with RTF

Received : 2008/01/07 09:47:37

Our application uses aspose words to insert a bar code into a document.

We have an number of documents that completely fill the page. However when produced through aspose words it changes the size and crams the first half of the second page into the last part of the first page. It also screws the boarders up.

Any ideas?

This message was posted using Aspose.Live 2 Forum


Thanks for your inquiry. Could you please attach your document for testing (only you and Aspose staff can download it) and provide me code that will allow me to reproduce problem? I will try to reproduce your problem and provide you more information.

Best regards.

Hi Alexey

I have attached the source and output documents.

The main code that does the replacement is too large to paste here but essentially we are replacing the
[!SomeKey] blocks in the raw RTF string with information strings like names and addresses.

Below is the code that inserts the barcodes which i thought was responsible for the document re-arranging itself.


private string ReplaceRTFBarCodeFields(string information, int customerID, int leadID, int matterID, int documentTypeID)
Document wordDoc = Aquarium.Documents.DocumentConverter.GetAsposeDocumentFromRTF(information);
barcodeDetails = new RTFBarcodeDetails(wordDoc, leadID, matterID, customerID, documentTypeID);
wordDoc.Range.Replace(new Regex(@"\[!CustomerBarCode\]"), new ReplaceEvaluator(MyReplaceEvaluator), true);
wordDoc.Range.Replace(new Regex(@"\[!LeadBarCode\]"), new ReplaceEvaluator(MyReplaceEvaluator), true);
wordDoc.Range.Replace(new Regex(@"\[!MatterBarCode\]"), new ReplaceEvaluator(MyReplaceEvaluator), true);
wordDoc.Range.Replace(new Regex(@"\[!DocumentBarCode\]"), new ReplaceEvaluator(MyReplaceEvaluator), true);
wordDoc = barcodeDetails.Document;
information = Aquarium.Documents.DocumentConverter.GetStringFromDocument(wordDoc, Aquarium.Documents.DocumentFormat.RTF);
return information;

private ReplaceAction MyReplaceEvaluator(object sender, ReplaceEvaluatorArgs e)
string barcodeImageURLFormat ={0}&type={1};
DocumentBuilder builder = new DocumentBuilder(barcodeDetails.Document);

switch (e.Match.Value)
case @"[!CustomerBarCode]":
builder.InsertImage(string.Format(barcodeImageURLFormat, barcodeDetails.CustomerID, 'C'));
case @"[!LeadBarCode]":
builder.InsertImage(string.Format(barcodeImageURLFormat, barcodeDetails.LeadID, 'L'));
case @"[!MatterBarCode]":
builder.InsertImage(string.Format(barcodeImageURLFormat, barcodeDetails.MatterID, 'M'));
case @"[!DocumentBarCode]":
builder.InsertImage(string.Format(barcodeImageURLFormat, barcodeDetails.DocumentTypeID, 'D'));

e.Replacement = string.Empty;
barcodeDetails.Document = builder.Document;
return ReplaceAction.Replace;

I have just remembered something else which might be useful. This only occurs since we upgraded from to 4.4.3.



Thanks for additional information. I managed to reproduce the problem. I have logged this problem to our defect database as issue # 4252. Please expect a reply before the next hotfix (within 2-3 weeks). We might just fix it by then or provide more information

Best regards.

We have released a new version of Aspose.Words that contains a fix for this issue.

Issue #4252 - Position of the floating TextBoxes is changed after open/save.

The new version of Aspose.Words is available for download from here.

Best regards.