MSProject加载项以给定名称和日期将.mpp转换为.pdf [英] MSProject Add-In to convert .mpp in .pdf with given name and date

查看:45
本文介绍了MSProject加载项以给定名称和日期将.mpp转换为.pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为MSProject 2013及更高版本开发外接程序.我想将打开的.mpp文件安全/转换为.pdf文件,而无需为用户提供其他对话框.只需按一下按钮,一切完成后就会收到通知.

I am developing an Add-In for MSProject 2013 and higher. I want to safe/convert the opened .mpp file into an .pdf file without having an additional dialog for the user. He just presses the button an gets an notification when everything is done.

我需要将其保存在一个不规则的路径中,并为用户定义一个开始日期和结束日期.

I need to save it in a spacific path and user a defined start and end date.

我尝试了SaveAs方法,但是由于它使用MSProject.PjFileType作为输入,而pdf是no选项,所以我不能使用它. PjFileFormat枚举

I tried the SaveAs-methode, but since it takes an MSProject.PjFileType as input and the is no option for pdf, I can't use this. PjFileFormat Enumeration

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

An other approche was using the DocumentExport-methode.

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

但是在这种情况下,我一次只能看到3个星期.它被放大了,还没有找到改变它的方法.在导出之前更改MSProject中的视图无济于事.

But in this case i only see 3 weeks at once. It is zoomed in and haven't found a way to change this. Changing the View in MSProject, before exporting does not help.

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

A third way is using the Windows10 pdf-printer:

// 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();

但是这样我不能给出开始和结束日期.这样就可以访问许多我不需要的页面.

but this way I can not give the starting and end date. This results in having way to many pages I do not need.

是否有机会通过更改一种解决方案来实现我的目标?或者还有其他选择吗?

Is there any chance to achieve my goal with changing one of my solutions or is there any other option?

推荐答案

在找不到合适的解决方案之后,我使用了Windows 10打印机和模拟键盘事件将路径插入对话框中,该对话框随即打开.使用Enter,我开始打印.

After not finding a proper solution, i used the windows 10 Printer and simulated keyboard events to insert the path in the dialog, which opens. With Enter i start the printing.

我知道这不是一个很好的解决方案,但这是我让它起作用的唯一途径

I know it is not a nice solution, but it is the onlyway i got it to work

这篇关于MSProject加载项以给定名称和日期将.mpp转换为.pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆