如何编程“microsoft print to pdf” vb.net中的虚拟打印机 [英] How to programme "microsoft print to pdf" virtual printer in vb.net

查看:608
本文介绍了如何编程“microsoft print to pdf” vb.net中的虚拟打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道如何编写使用Windows 10下载的Microsoft Print to PDF虚拟打印机。

我想使用Microsoft Print to PDF虚拟打印机打印Excel工作表。 />
我希望能够在代码中设置pdf文件的路径和文件名。

我已经尝试过下面的代码,但它要求用户输入文件名和路径在创建PDF文件之前。



我尝试过:



Does anybody know how to program the "Microsoft Print to PDF" virtual printer downloaded with Windows 10.
I want to print an Excel worksheet using "Microsoft Print to PDF" virtual printer.
I want to be able to set the path and filename of the pdf file within the code.
I have tried the code below but it requires the user to put the filename and path in before creating the PDF file.

What I have tried:

Private Sub SaveWorksheetAsPDF(Title As String, Path As String)
        Dim FileName As String = "ResultsSheet" & Title & ".pdf"

        'Print the document to PDF
        oSheet.PrintOut(copies:=1, Preview:=True, ActivePrinter:="Microsoft Print To PDF")

       'Wait until the file shows up before closing PDF Creator
        Do
            My.Application.DoEvents()
        Loop Until Dir(Path & FileName) = FileName

     End Sub

推荐答案

您需要将 PrToFileName PrintToFile 参数传递给 PrintOut 方法 [ ^ ]:

You need to pass the PrToFileName and PrintToFile parameters to the PrintOut method[^]:
Dim fullPath As String = System.IO.Path.GetFullPath(FileName)
oSheet.PrintOut(copies:=1, Preview:=True, ActivePrinter:="Microsoft Print To PDF", PrToFileName:=fullPath, PrintToFile:=True)


这篇关于如何编程“microsoft print to pdf” vb.net中的虚拟打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆