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

ε祈祈猫儿з 提交于 2019-12-11 09:47:29

问题


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.

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

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

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.

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?


回答1:


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



来源:https://stackoverflow.com/questions/48861858/msproject-add-in-to-convert-mpp-in-pdf-with-given-name-and-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!