我正在使用VB.Net WinForms。我想调用Adobe Reader 9 ActiveX控件来打印一些PDF。我已将ActiveX控件添加到VS工具箱(dll是AcroPDF.dll,COM名称“Adobe PDF Reader”。经过一些实验后,以下代码可以正常工作。

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

如果没有Yuk位,这只会打印一些PDF,似乎End Using语句在控件完成打印之前调用dispose。

因此,似乎对printAll的调用是非阻塞的,但我找不到回调或状态属性,我可以查询以查看打印假脱机是否已完成。我错过了一个属性/方法,或者是否有更优雅(反应更灵敏)的工作?

有帮助吗?

解决方案

使用此方法打印多个文档并不像您找到的那样有效。

让它工作是非常棘手的,但这里是对解决方案的一般描述。

我使用System.Diagnostics.Process使用myProcess.StartInfo.Verb =&quot; Print&quot;进行打印。 然后,我分两步检查打印机队列的状态和状态,以确保打印已准备就绪,以便能够打印下一个文档。使用WMI和ManagementObjectSearcher使用“SELECT * FROM Win32_Printer”枚举打印机信息。 逻辑是我在继续打印下一个之前尝试查看假脱机是否已启动。

请参阅 http://msdn.microsoft.com/en-us/用于Win32_Printer WMI类的库/ aa394363.aspx

其他提示

我在Delphi中使用AcroPDF遇到同样的问题..然后我发现当我“停止”时在使用消息的过程中,AcroPDF开始打印。

所以我只创建一个模态TForm,在几秒钟后自动关闭。

var
  formModal : TFormModal;
begin
  formModal := TFormModal.Create(self);
  //PrintMethodHere  
  frmPecas.CarregarDocumentoParaImpressao();
  formModal.ShowModal;
end;

TFormModal就是这个,我只是在表单上插入一个加载图标来表示“打印”等内容。

unit FModal;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Animate, GIFCtrl;

type
  TFormModal = class(TForm)
    Timer: TTimer;
    imgGif: TRxGIFAnimator;
    procedure TimerTimer(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormModal: TFormModal;

implementation

{$R *.dfm}
//    Author: Anderson Mello  Date: 09-fev-2012
//  DEscription: Using TTimer after 5 seconds I close this form
procedure TFormModal.TimerTimer(Sender: TObject);
begin
 close;
end;

//    Author: Anderson Mello  Date: 09-fev-2012
//  Description: Enable the timer only when the form is shown
procedure TFormModal.FormShow(Sender: TObject);
begin
 Timer.Enabled := true;
end;

//  Description: disable when close
procedure TFormModal.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 Timer.Enabled := false;
end;

//    Author: Anderson Mello  Date: 09-fev-2012
//  Description: disable close button "X", so the user can't close 
procedure TFormModal.FormCreate(Sender: TObject);
var
  hSysMenu:HMENU;
begin
  hSysMenu:=GetSystemMenu(Self.Handle,False);
  if hSysMenu <> 0 then begin
    EnableMenuItem(hSysMenu,SC_CLOSE,MF_BYCOMMAND or MF_GRAYED);
    DrawMenuBar(Self.Handle);
  end;
  KeyPreview:=True;
end;

//    Author: Anderson Mello  Date: 09-fev-2012
//  Description: disable shortcuts to close
procedure TFormModal.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_F4) and (ssAlt in Shift) then
    Key:=0;
end;

我们最终使用Adobe的PDF Verifier进行测试。为了做到这一点,我们必须实际启动acrobat并使用 SendInput 以编程方式操作它的界面一>。

我很想知道是否可以使用内部API。

您可以使用此代码显示任何带有相应软件的文件。

Sub Show_Document(ByVal FILENAME As String)
    Dim p As Process = Nothing
    Try
        If My.Computer.FileSystem.FileExists(FILENAME) Then
            p = Process.Start(FILENAME)
            p.Dispose()
        End If

    Catch ex As Exception

    Finally

    End Try

End Sub
scroll top