Microsoft
Windows 10附带了一个可打印PDF文件的Microsoft Print To PDF打印机.它提示文件名下载.
我如何以编程方式控制这个从C#不提示PDF文件名,但保存到我提供的某个文件夹中的特定文件名?
这是用于批量处理以编程方式将大量文档或其他类型的文件打印到PDF.
要使用Microsoft Print to PDF打印机打印PrintDocument对象,而不提示文件名,以下是纯代码方法:
// generate a file name as the current date/time in unix timestamp format file = (string)(DateTime.UtcNow.Subtract(new DateTime(1970,1,1))).TotalSeconds.ToString(); // the directory to store the output. 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();