C# 使用Microsoft打印到PDF打印机打印到PDF

C# 使用Microsoft打印到PDF打印机打印到PDF,c#,.net,ms-project,C#,.net,Ms Project,我尝试将ms project文件打印为pdf,而无需任何其他操作 我尝试过几种解决办法,但都没有成功 PrintDocument doc = new PrintDocument() { //DocumentName = safeDir + fileName, PrinterSettings = new PrinterSettings() { // set the printer to 'Microsoft Print to PDF' Printer

我尝试将ms project文件打印为pdf,而无需任何其他操作

我尝试过几种解决办法,但都没有成功

PrintDocument doc = new PrintDocument()
{
//DocumentName = safeDir + fileName,
    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 = safeDir + fileName,
    }
};
doc.Print();
如果我像之前所展示的那样尝试这种方法,我会得到一个空的pdf文件

手动打印为PDF效果良好

有什么解决这个问题的建议吗?

我的蜘蛛感觉告诉我这很可能是由文件名中的逗号引起的

这是打印为PDF时的已知错误。使用不同的驱动程序或 不要在文件名中加逗号

注意:它不仅来自代码,在某些情况下通常也是如此

免责声明:这是一个完全的猜测


查看这些其他链接


我的文件名中没有逗号。使用相同的文件名手动打印也可以。即使使用Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+@“\test123.pdf”作为保存路径也不起作用。文件只有1KB大。我可以打开它,但它只是白色的。但是谢谢你的提示。