您好,
我透過 Aspose.Words 開啟 Word 檔時,取得的頁碼為 16,但實際 Word 檔的頁數為 14。 odd2.doc.zip (700.7 KB)
程式碼如下,
var doc = new Aspose.Words.Document("odd2.doc");
Console.WriteLine($"pageCount:{doc.PageCount}");
//pageCount:16
透過 Section 取得所在的頁碼時,也不正確,程式碼如下,
var doc = new Aspose.Words.Document(“odd2.doc”);
Console.WriteLine($“pageCount:{doc.PageCount}”);
var layout = new LayoutCollector(doc);
foreach (var node in doc.ChildNodes)
{
if (node.NodeType == NodeType.Section)
{
var section = (Section)node;
var sectionStart = section.PageSetup.SectionStart;
Console.WriteLine($“Section:{sectionStart}”);
Console.WriteLine($“layout.GetStartPageIndex:{layout.GetStartPageIndex(section)}”);
Console.WriteLine($“layout.GetEndPageIndex:{layout.GetEndPageIndex(section)}”);
}
}
var doc = new Aspose.Words.Document(“odd2.doc”);
Console.WriteLine($“pageCount:{doc.PageCount}”);
var layout = new LayoutCollector(doc);
foreach (var node in doc.ChildNodes)
{
if (node.NodeType == NodeType.Section)
{
var section = (Section)node;
var sectionStart = section.PageSetup.SectionStart;
var nodes = section.GetChildNodes(NodeType.Run, true);
foreach(Run r in nodes)
{
Console.WriteLine(r.Font.Name);
r.Font.Name = "新細明體";
}
}
}
doc.Save("odd2_2.doc");
doc = new Document(“odd2_2.doc”);
Console.WriteLine($“pageCount:{doc.PageCount}”);
Document document = new Document(MyDir + "input.docx");
document.WarningCallback = new HandleDocumentWarnings();
document.Save(MyDir + "output.pdf");
public class HandleDocumentWarnings : IWarningCallback
{
/// <summary>
/// Our callback only needs to implement the "Warning" method. This method is called whenever there is a
/// potential issue during document procssing. The callback can be set to listen for warnings generated during document
/// load and/or document save.
/// </summary>
public void Warning(WarningInfo info)
{
// We are only interested in fonts being substituted.
if (info.WarningType == WarningType.FontSubstitution)
{
Console.WriteLine(info.WarningType + " :: " + info.Description.ToString());
}
}
}
errorPage.doc.zip (37.0 KB)
您好,
我使用上面的檔案,
然後用下面的程式來顯示頁數,顯示的 PageNumber 是 5,但用 Word 來開卻是 6 頁。
而 Warning 的 function 完全沒有被執行到哦! 是不是表示沒有缺字型呢? 謝謝您。
public class HandleDocumentWarnings : Aspose.Words.IWarningCallback
{
/// <summary>
/// Our callback only needs to implement the "Warning" method. This method is called whenever there is a
/// potential issue during document procssing. The callback can be set to listen for warnings generated during document
/// load and/or document save.
/// </summary>
public void Warning(Aspose.Words.WarningInfo info)
{
// We are only interested in fonts being substituted.
if (info.WarningType == Aspose.Words.WarningType.FontSubstitution)
{
Console.WriteLine(info.WarningType + " :: " + info.Description.ToString());
}
}
}
var wordFile = @"C:\page.doc";
var doc = new Aspose.Words.Document(wordFile);
doc.WarningCallback = new HandleDocumentWarnings();
Console.WriteLine($"pageCount:{doc.PageCount}");
doc.Save(@"C:\page2.doc");
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.