2012-04-24 22 views
0

我有一個MVC3 C#.Net網絡應用程序。我正在使用Aspose.Words創建一個MS Word文檔。我有一個要求,不要在文檔中包含表格。但是,根據文本的寬度,在文檔的多行上,文本的對齊方式會錯誤對齊。
例如:Aspose.Words ...以像素爲單位計算文本的widt

這看起來不錯

Proposal Name: My Proposal   Date:04/24/2012 

這不

Proposal Name: My Prop   Date:04/24/2012 

應該

Proposal Name: My Prop    Date:04/24/2012 

基於文本的第一位的寬度,我需要計算像素寬度(我認爲),並插入一個TAB如果需要ssary。

任何想法如何做到這一點?

回答

1

您可以使用Graphics.MeasureString函數,該函數根據您的字體爲您提供字符串的寬度(以像素爲單位)。更多信息請Here

乾杯,

伊赫桑

0

下面的代碼示例返回當前實體相對於頁面左上角的邊框。

Document doc = new Document(MyDir + "in.docx"); 

LayoutCollector layoutCollector = new LayoutCollector(doc); 
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc); 

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true)) 
{ 
    var renderObject = layoutCollector.GetEntity(para); 
    layoutEnumerator.Current = renderObject; 
    RectangleF location = layoutEnumerator.Rectangle; 
    Console.WriteLine(location); 
} 

源:https://www.aspose.com/community/forums/thread/541215/replace-run-text-with-string-of-spaces-of-same-pixel-length.aspx

相關問題