使用给定名称和日期将 .pdf 中的 .mpp 转换为 .mpp 的 MSProject 加载项

MSProject Add-In to convert .mpp in .pdf with given name and date

我正在为 MSProject 2013 及更高版本开发插件。 我想 safe/convert 将打开的 .mpp 文件转换为 .pdf 文件,而无需为用户提供额外的对话框。当一切都完成时,他只需按下按钮就会收到通知。

我需要将它保存在一个特定的路径中,并为用户指定一个定义的开始和结束日期。

我尝试了 SaveAs 方法,但由于它需要一个 MSProject.PjFileType 作为输入并且没有 pdf 选项,我无法使用它。 PjFileFormat Enumeration

另一种方法是使用 DocumentExport 方法。

app.DocumentExport(@"D:/doc_exportqwre.pdf", MSProject.PjDocExportType.pjPDF, true, true, false, System.DateTime.Now, System.DateTime.Now.AddDays(42));

但在这种情况下,我一次只能看到 3 周。它被放大了,还没有找到改变它的方法。在导出之前更改 MSProject 中的视图没有帮助。

第三种方法是使用 Windows10 pdf 打印机:

// generate a file name as the current date/time in unix timestamp format
string file = (string)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString();

// the directory to store the output.
string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

// initialize PrintDocument object
PrintDocument doc = new PrintDocument()
{
    PrinterSettings = new PrinterSettings()
    {
        // set the printer to 'Microsoft Print to PDF'
        PrinterName = "Microsoft Print to PDF",

        // tell the object this document will print to file
        PrintToFile = true,

        // set the filename to whatever you like (full path)
        PrintFileName = Path.Combine(directory, file + ".pdf"),
    }
};
doc.Print();

但是这样我不能给出开始和结束日期。这导致有许多我不需要的页面。

是否有机会通过更改我的其中一个解决方案来实现我的目标,或者是否有任何其他选择?

在没有找到合适的解决方案后,我使用 windows 10 打印机和模拟键盘事件在打开的对话框中插入路径。按 Enter 我开始打印。

我知道这不是一个好的解决方案,但这是我让它工作的唯一方法