2

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 への呼び出しは非ブロッキングのようですが、印刷スプーリングが完了したかどうかを確認するために照会できるコールバックまたはステータス プロパティが見つかりません。プロパティ/メソッドがありませんか、それともより洗練された (そして応答性の高い) 回避策はありますか?

4

4 に答える 4

2

この方法を使用して複数のドキュメントを印刷すると、あなたが見つけたようにうまくいきません。

機能させるのは非常に難しいですが、ここでは解決策の一般的な説明を示します。

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

Win32_Printer WMI クラスについては、http://msdn.microsoft.com/en-us/library/aa394363.aspxを参照してください。

于 2008-12-28T12:34:36.890 に答える
1

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;
于 2012-02-10T12:34:15.003 に答える
0

最終的に、独自のテスト目的で Adob​​e の PDF Verifier を使用することになりました。これを行うには、実際に acrobat を起動し、SendInputを使用してプログラムでそのインターフェイスを操作する必要がありました。

代わりに内部 API を使用できるかどうか、非常に興味があります。

于 2008-10-24T15:55:41.967 に答える
-2

このコードを使用して、適切なソフトウェアで任意のファイルを表示できます。

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
于 2009-12-07T19:49:39.487 に答える