0

应用程序是 WPF 和 C# 的组合,我在下面遇到问题的所有代码都在 C# 部分......

我有一个应用程序可以生成一些 HTML 并使用 MS Word Interop 将其保存为 PDF。如果用户选择这样做,我想让用户选择包含他们从我的应用程序中单独创建的页眉或页脚。我已经设法做到了这一点,但我面临的问题是这个。如果在插入下一个文档时任何文档在页面底部结束,则中间有一个空白页。

粗略的例子:

  • 封面(不打到页尾)
  • 从我的应用程序生成的东西(点击页面底部)
  • 空白页
  • 页脚(位于页面底部)
  • 空白页

因此,如果有人可以看看我是如何做到这一点的,并让我知道我的逻辑有什么问题,或者给我一个提示,让我知道在哪里看会很棒。谢谢大家,如果我需要提供更多说明,请告诉我。

这段代码的灵感来自这个 SO question

//Itterate through all wordFiles that have been passed in, in a string array
for ( int i = 0; i < wordFiles.Length; i++)
{
   //Get the current word file
   string file = wordFiles[i];
   //Insert the file
   wDoc.Application.Selection.Range.InsertFile(file,
                                               ref oMissing, 
                                               ref oMissing, 
                                               ref oMissing, 
                                               ref oFalse);
   if(i != 0)
      //if not add a page break
      wDoc.Application.Selection.Range.InsertBreak(ref wdPageBreak);

   // Moves to the end of the current page 
   // (Same funcionality of pressing the "End" Key)
   wDoc.Application.Selection.EndKey(ref wdStory, ref oMissing);
}
4

0 回答 0