加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何以编程方式打印到PDF文件,而不使用Windows 10附带的Microsof

发布时间:2020-12-13 19:25:19 所属栏目:Windows 来源:网络整理
导读:Microsoft Windows 10附带了一个可打印PDF文件的Microsoft Print To PDF打印机.它提示文件名下载. 我如何以编程方式控制这个从C#不提示PDF文件名,但保存到我提供的某个文件夹中的特定文件名? 这是用于批量处理以编程方式将大量文档或其他类型的文件打印到PD
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();

您还可以将此方法用于其他另存为文件类型的方法,如Microsoft XPS打印机

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读