.NET Interop을 사용하여 Adobe Reader 9에서 프로그래밍 방식으로 인쇄합니다
-
04-07-2019 - |
문제
vb.net winforms를 사용하고 있습니다. 일부 PDF를 인쇄하려면 Adobe Reader 9 ActiveX Control에 전화하고 싶습니다. vs 도구 상자에 ActiveX 컨트롤을 추가했습니다 (dll은 acropdf.dll, com name "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 중 일부 만 인쇄 할 것입니다. 진술을 사용하는 종료는 인쇄를 마치기 전에 컨트롤에 대한 처분을 호출하는 것으로 보입니다.
따라서 Printall에 대한 호출은 차단하지 않은 것처럼 보이지만 인쇄 스풀링이 완료되었는지 확인하기 위해 쿼리 또는 콜백 또는 상태 속성을 찾을 수 없습니다. 재산/방법이 없거나 더 우아하고 반응이 좋은 작업이 있습니까?
해결책
이 방법을 사용하여 여러 문서를 인쇄하는 것은 찾은대로 잘 작동하지 않습니다.
작동하는 것은 매우 까다 롭지 만 여기에 솔루션에 대한 일반적인 설명이 있습니다.
나는 system.diagnostics.process를 사용하여 myProcess.startinfo.verb = "print"를 사용하여 인쇄하여 인쇄 한 다음 두 단계로 프린터 큐 상태와 상태를 확인하여 인쇄가 다음 문서를 인쇄 할 수있을 정도로 충분히 준비되어 있는지 확인합니다. WMI 및 ManagementObjectSearcher를 사용하여 "select * from win32_printer"를 사용하여 프린터 정보를 열거하십시오. 논리는 다음을 계속 인쇄하기 전에 스풀링이 시작되었는지 확인하려고한다는 것입니다.
보다 http://msdn.microsoft.com/en-us/library/aa394363.aspx Win32_printer WMI 클래스의 경우.
다른 팁
나는 델파이에서 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 검증기를 사용했습니다. 이를 위해서는 실제로 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