I need to print a pdf, I found the code supplied recently in this group by
Peter Below but cannot seem to get it to work, Searching the archives I have
seen this more than once so I am obviously doing something wrong. I have
tried this on WinXP and Win2000 Server to no avail?
The code is shown below, ShellExecute returns 42?
Any Ideas
I obviously have Acrobat Reader installed.
procedure TForm1.Button1Click(Sender: TObject);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
S, strPDFFile : String;
hDeviceMode : THandle;
nErrorCode : Integer;
begin
strPDFFile := 'c:\Test.pdf';
if PrintDialog1.Execute then
begin
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
S:= Format('"%s" "%s" "%s"',[Device, Driver, Port]);
nErrorCode := ShellExecute( handle, 'printto', PChar(strPDFFile),
Pchar(S), Nil, SW_HIDE);
ShowMessage('Error Code = ' + IntToStr(nErrorCode));
end;
end;
Thanks
Mark Redman
That was indeed the problem.
Thank you very much.
Mark Redman
"Gary Williams" <no.mail...@nonexistant.domain.com> wrote in message
news:3d77c24a$1...@newsgroups.borland.com...
>
> "Mark Redman" <Ma...@RedmanSoftware.com> wrote in message
> news:3d77...@newsgroups.borland.com...
> > Hi All,
> >
> > I need to print a pdf, I found the code supplied recently in this group
by
> > Peter Below but cannot seem to get it to work, Searching the archives I
> have
> > seen this more than once so I am obviously doing something wrong. I have
> > tried this on WinXP and Win2000 Server to no avail?
> >
> > The code is shown below, ShellExecute returns 42?
> >
> > Any Ideas
>
> please refer to
>
> http://www.gw.ro/pascal/AcrobatReaderBug.html
>
> I'm betting you're running your application from the IDE.
>
> -Gary
>
>
>
please refer to
Mark Redman
I know of two ways to print a PDF programmatically. Neither seems to work
when run under the IDE on Win2K. The first method works properly when run
outside the IDE, but the second method will leave Acrobat Reader running on
the desktop.
uses
ShellAPI, Printers;
type
TPrinterInfo = record
Device: String;
Driver: String;
Port: String;
end;
TStringBuffer = array[0..MAX_PATH - 1] of Char;
function GetPrinterInfo: TPrinterInfo;
var
DeviceBuffer: TStringBuffer;
DriverBuffer: TStringBuffer;
PortBuffer: TStringBuffer;
DeviceMode: THandle;
begin
Printer.GetPrinter(DeviceBuffer, DriverBuffer, PortBuffer, DeviceMode);
Result.Device := DeviceBuffer;
Result.Driver := DriverBuffer;
Result.Port := PortBuffer;
end;
// This does not appear to work under the IDE on Win2000
procedure PrintPDFDocument1(const FileName: String);
var
Params: String;
begin
with GetPrinterInfo do
Params := Format('"%s" "%s" "%s"', [Device, Driver, Port]);
ShellExecute(0, 'printto', PChar(FileName), PChar(Params), nil, SW_HIDE);
end;
// This does not appear to work under the IDE on Win2000
// This will leave Acrobat running on the desktop.
procedure PrintPDFDocument2(const FileName: String);
var
Params: String;
begin
with GetPrinterInfo do
Params := Format('/t "%s" "%s" "%s" "%s"', [FileName, Device, Driver,
Port]);
ShellExecute(0, 'open', 'AcroRd32', PChar(Params), nil, SW_HIDE);
end;
const
FileName = 'C:\Temp.pdf';
procedure TForm1.Button1Click(Sender: TObject);
begin
PrintPDFDocument1(FileName);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PrintPDFDocument2(FileName);
end;
-Gary
I spent the last three hours conducting extensive tests with Acrobat Reader
version 3.02, 4.05, 5.0, and 5.05, running both under the Delphi IDE and
directly from Explorer, under Windows 2000. The results were surprising, to
say the least.
View the fruit of my research here:
http://www.gw.ro/pascal/AcrobatReaderHell.html
-Gary
I know it shouldn't be necessary to call AcroRd32 directly, but I wanted to
see if there would be any variation in behavior based on how it was called.
After I uploaded the web page, it did occur to me that I didn't try the
generic 'print' shell command. I will try that tomorrow. I'll also try to
document the registry settings for each version of Acrobat Reader that I
have available.
My goal is to compile everything I can about AR and Delphi together on that
one page so I can refer people to it when they post about having problems.
I would be interested in finding out if people using other versions of AR or
Windows (particularly XP) get consistent or differing results compared to my
tests.
> With some more
> work you might be able to check the registration yourself to decide which
> method to use up front.
That would be a good weekend project.
-Gary
The other thing I need to do is possibly print one or more PDF's
consecutively, it seems that once Acrobat is open, the second PDF will not
print?
I will also have a go and see if I can work things out, I didnt think this
PDF printing would be such an issue.
Mark Redman
"Gary Williams" <no.mail...@nonexistant.domain.com> wrote in message
news:3d780093$1...@newsgroups.borland.com...