🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.language.objectpascal
Article #169

Change Printer settings

#169
From: zeina
Date: Wed, 19 Sep 2007 00:14
112 lines
4339 bytes
I have the adobe printer installed into my system, in the Adobe
Acrobat profitional 8 the printer has a settings such as (view pdf
result, pdf output folder) I need to change them from my program, I
did some research over the net and I found this code, when I try it I
had an error (Abstract Error) so what I'm missing?? And is there
another way to achieve my goal??

thanks


code :

procedure TForm1.LoadPrinterInfo(APrinterName: PChar; ASourceStream:
TStream);
var
  HPrinter : THandle;
  InfoSize,
  BytesNeeded: Cardinal;
  PI2: PPrinterInfo2;
  PrinterDefaults: TPrinterDefaults;
begin
  with PrinterDefaults do
  begin
    DesiredAccess := PRINTER_ACCESS_USE;
    pDatatype := nil;
    pDevMode := nil;
  end;
  if OpenPrinter(APrinterName, HPrinter, @PrinterDefaults) then
  try
    SetLastError(0);
    //Determine the number of bytes to allocate for the PRINTER_INFO_2
construct...
    if not GetPrinter(HPrinter, 2, nil, 0, @BytesNeeded) then
    begin
      //Allocate memory space for the PRINTER_INFO_2 pointer
(PrinterInfo2)...
      PI2 := AllocMem(BytesNeeded);
      try
        InfoSize := SizeOf(TPrinterInfo2);
        if GetPrinter(HPrinter, 2, PI2, BytesNeeded, @BytesNeeded)
then
        begin
          PI2.pSecurityDescriptor := nil;
          ASourceStream.ReadBuffer(PChar(PI2)[InfoSize], BytesNeeded -
InfoSize); // the error line
          // Apply settings to the printer
          if DocumentProperties(0, hPrinter, APrinterName,
PI2.pDevMode^,
                                PI2.pDevMode^, DM_IN_BUFFER or
DM_OUT_BUFFER) = IDOK then
          begin
            SetPrinter(HPrinter, 2, PI2, 0);  // Ignore the result of
this call...
          end;
        end;
      finally
        FreeMem(PI2, BytesNeeded);
      end;
    end;
procedure TForm1.SetPrinterSettings(FPrinter: TPrinter);
var
  FDevice: PChar;
  FDriver: PChar;
  FPort: PChar;
  DeviceMode: THandle;
  DevMode: PDeviceMode;
begin
  {to get a current printer settings}
  FPrinter.GetPrinter(FDevice, FDriver, FPort, DeviceMode);
  {lock a printer device}
  DevMode := GlobalLock(DeviceMode);

  {set a paper size as A4-Transverse}
  if ((DevMode^.dmFields and DM_PAPERSIZE) = DM_PAPERSIZE) then
  begin
    DevMode^.dmFields := DevMode^.dmFields or DM_PAPERSIZE;
    DevMode^.dmPaperSize := DMPAPER_A4_TRANSVERSE;
  end;

  {set a paper source as Tractor bin}
  if  ((DevMode^.dmFields and DM_DEFAULTSOURCE) = DM_DEFAULTSOURCE)
then
  begin
    DevMode^.dmFields := DevMode^.dmFields or DM_DEFAULTSOURCE;
    DevMode^.dmDefaultSource := DMBIN_TRACTOR;
  end;

  {set a Landscape orientation}
  if  ((DevMode^.dmFields and DM_ORIENTATION) = DM_ORIENTATION) then
  begin
    DevMode^.dmFields := DevMode^.dmFields or DM_ORIENTATION;
    DevMode^.dmOrientation := DMORIENT_LANDSCAPE;
  end;

  {set a printer settings}
  FPrinter.SetPrinter(FDevice, FDriver, FPort, DeviceMode);

  {unlock a device}
  GlobalUnlock(DeviceMode);
end;
  finally
    ClosePrinter(HPrinter);
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  s:Tstream;
begin
   s:= Tstream.Create;
  LoadPrinterInfo(pchar('Adobe PDF'),s);
end   ;
Technical Details
Message-ID: <1190160848.129993.299900@19g2000hsx.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!19g2000hsx.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 109d30,8bd5e56c3b17d38a
X-Google-Attributes: gid109d30,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!19g2000hsx.googlegroups.com!not-for-mail
From:  zeina <zeinaedelbi@gmail.com>
Newsgroups: borland.public.delphi.language.objectpascal
Subject: Change Printer settings
Date: Tue, 18 Sep 2007 17:14:08 -0700
Organization: http://groups.google.com
Lines: 113
Message-ID: <1190160848.129993.299900@19g2000hsx.googlegroups.com>
NNTP-Posting-Host: 90.153.128.12
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1190160849 26427 127.0.0.1 (19 Sep 2007 00:14:09 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 19 Sep 2007 00:14:09 +0000 (UTC)
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Avant Browser; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: 19g2000hsx.googlegroups.com; posting-host=90.153.128.12;
   posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0