编程印刷在Adobe Reader 9使用.NET互操作操作、Adobe、Reader、NET

2023-09-04 00:28:07 作者:相见欢

我使用VB.Net WinForms的。我想打电话给Adobe Reader的9 ActiveX控件来打印一些PDF文件。我已经加入了ActiveX控件到VS工具箱(该dll是AcroPDF.dll,在COM域名的Adobe PDF阅读器。一些实验后下code ++工程。

I am using VB.Net WinForms. I would like to call the Adobe Reader 9 ActiveX control to print some PDFs. I have added the ActiveX control to the VS toolbox (the dll is AcroPDF.dll, the COM name "Adobe PDF Reader". After some experiment the following code works.

Dim files As String() = Directory.GetFiles(TextBoxPath.Text, "*.pdf", SearchOption.TopDirectoryOnly)

Using ActiveXPDF As New AxAcroPDFLib.AxAcroPDF

    Me.Controls.Add(ActiveXPDF)
    ActiveXPDF.Hide()

    For Each filename As String In files

        ActiveXPDF.LoadFile(filename)
        ActiveXPDF.printAll()

        'Begin Yukky Hack    '


        Dim endTime As Date = DateAdd(DateInterval.Second, 20, Now)
        Do While Now < endTime
            My.Application.DoEvents()
        Loop

        'End Yuk   '

    Next

End Using

如果没有育位,这将只打印某些PDF文件中,似乎最终使用声明呼吁处置的控制之前就已经完成打印。

Without the Yuk bit this will only print some of the PDFs, it seems that the End Using statement is calling dispose on the control before it has finished printing.

因此​​,它似乎调用printAll是非阻塞但我不能找到一个回调或状态的财产,我可以查询,看看后台打印工作已经完成。我缺少属性/方法还是有更优雅(多反应)解决?

Therefore it seems the call to printAll is non-blocking but I can't find a callback or status property I can query to see if the print spooling has been completed. I am missing a property/method or is there a more elegant (and more responsive) work around?

推荐答案

使用这种方法来打印多份文档是行不通的好,因为你找到了。

Using this method to print multiple documents is not going to work good as you found.

有它的工作是相当棘手,但这里是解决方案的总体描述。

Having it work is quite tricky but here is a general description of the solution.

我使用的System.Diagnostics.Process使用myProcess.StartInfo.Verb =打印,打印 然后我检查打印机队列的状态和状况的两个步骤,以确保印刷足够的准备可以打印下一个文档。使用WMI和ManagementObjectSearcher枚举使用SELECT * FROM Win32_Printer打印机信息。 其中的逻辑是,我试试,看是否是后台继续打印在下单前开始。

I use System.Diagnostics.Process to print using myProcess.StartInfo.Verb = "Print" Then I check the Status and State of printer queue in two steps to make sure that the printing is ready enough to be able to print the next document. Use WMI and ManagementObjectSearcher to enumerate the printer info using "SELECT * FROM Win32_Printer". The logic is that I try to see if the spooling is started before continuing to print the next one.

请参阅 http://msdn.microsoft.com/en-us/library /aa394363.aspx ,在Win32_Printer WMI类。

See http://msdn.microsoft.com/en-us/library/aa394363.aspx for the Win32_Printer WMI class.