简体   繁体   中英

Print to PDF with Microsoft Print to PDF printer

I try to print a ms project file to pdf without any additional action needed.

I have tried several solutions without success.

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

If i try this approach like showed here , I get an empty pdf file.

Manually printing to PDF works fine.

Any suggestions to solve this problem?

My Spidey Senses tells me this is most likely caused by commas in the file name

This is a known bug when printing to PDF. Use a different driver or don't put a comma in the file name

Note : Its not only from code, its in general in certain situations.

Disclaimer : this is a complete and utter guess


Check these other links out

Bug in "Print to PDF" and "Print to XPS" in Windows 10? comma in filename results in zero-byte file

Microsoft Print to PDF not working

Found a bug in Microsoft Print to PDF

Microsoft Print to PDF in Windows 10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM