質問

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の一部のみを印刷します。EndUsingステートメントは、印刷が完了する前にコントロールでdisposeを呼び出しているようです。

したがって、printAllの呼び出しはブロックされていないようですが、コールバックまたはステータスプロパティが見つからず、印刷スプーリングが完了したかどうかを確認できます。プロパティ/メソッドがありません、またはよりエレガントな(そしてより反応の良い)回避策がありますか?

役に立ちましたか?

解決

この方法を使用して複数のドキュメントを印刷することは、思ったほどうまく機能しません。

動作させるのは非常に難しいですが、ここにソリューションの一般的な説明があります。

System.Diagnostics.Processを使用してmyProcess.StartInfo.Verb =&quot; Print&quot;を使用して印刷します。 次に、2つの手順でプリンターキューの状態と状態をチェックし、次のドキュメントを印刷できるように印刷の準備ができていることを確認します。 WMIとManagementObjectSearcherを使用して、「SELECT * FROM Win32_Printer」を使用してプリンター情報を列挙します。 ロジックは、次の印刷を続行する前にスプーリングが開始されたかどうかを確認しようとすることです。

http://msdn.microsoft.com/en-us/を参照してください。 Win32_Printer WMIクラスのlibrary / 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