你可能想看看http://social.msdn.microsoft.com/Forums/office/en-US/e48b3126-941d-490a-85ee-e327bbe7e81b/convert-specific-word-pages-to-pdf-in-c?forum=worddev
它展示了如何从 word 文档中获取特定范围的页面(保留格式)。
相关部分(以防链接页面消失):
打开一个单词的实例。
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
并加载您的文档。打开文件后,您必须为您的选择准备范围。 Count 和 count2 是您在特殊情况下提供的页码。
object what = WdGoToItem.wdGoToPage;
object which = WdGoToDirection.wdGoToFirst;
object count = 1;
Range startRange = word.Selection.GoTo(ref what, ref which, ref count, ref oMissing);
object count2 = (int)count + 3;
Range endRange = word.Selection.GoTo(ref what, ref which, ref count2, ref oMissing);
endRange.SetRange(startRange.Start, endRange.End - 1);
endRange.Select();
Selection.Copy() 然后将所选页面复制到剪贴板,同时保留格式。
word.Selection.Copy();
源的其余部分创建一个新文档,您的选择将粘贴在其中。
word.Documents.Add();
word.Selection.Paste();
object outputFileName = "d:\\test1.doc";
object fileFormat = WdSaveFormat.wdFormatDocument97;
word.ActiveDocument.SaveAs(ref outputFileName,
ref fileFormat, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
我希望这会有所帮助。