PC Review


Reply
Thread Tools Rate Thread

Cannot print directly to XPS printer.

 
 
Ian Boyd
Guest
Posts: n/a
 
      13th Feb 2008
Using the code from

HOWTO: Send Raw Data to a Printer by Using the Win32 API
http://support.microsoft.com/kb/q138594/

i can print fine to every "real" printer. But when i print to the "Microsoft
XPS Document Writer" printer, no save dialog ever appears.

To sum up:
OpenPrinter()
StartDocPrinter()
StartPagePrinter()
WritePrinter()
EndPagePrinter()
EndDocPrinter()
CloserPrinter()

There are no errors, the spooler appears and disappears, the bytes written
equal the bytes supposed to be written. Just in the end no Save Dialog
appears.

Where is my print job going?


Code:

procedure PrintStrToPrinter(const TextToPrint: string; const PrinterName:
string);
var
hPrinter: THandle;
DocInfo: TDocInfo1;
dwBytesWritten : DWORD;
dwJobID: DWORD;
begin
{
HOWTO: Send Raw Data to a Printer by Using the Win32 API
http://support.microsoft.com/kb/q138594/
}
if TextToPrint = '' then
raise Exception.Create('[PrintStrToPrinter] To text specified');

if not WinSpool.OpenPrinter(PChar(PrinterName), hPrinter, nil) then
raise Exception.Create('[PrintStrToPrinter] Cannot find the
printer "'+PrinterName+'".');
try
// Fill in the structure with info about this "document"
ZeroMemory(@DocInfo, SizeOf(DocInfo));
DocInfo.pDocName := 'My Document';
DocInfo.pOutputFile := nil;
DocInfo.pDatatype := 'RAW';

// Inform the spooler the document is beginning
dwJobID := StartDocPrinter(hPrinter, 1, @docInfo);
if dwJobID = 0 then
RaiseLastWin32Error;
try
if not StartPagePrinter (hPrinter) then
RaiseLastWin32Error;
try
if not WritePrinter(hPrinter, PChar(TextToPrint),
Length(TextToPrint), dwBytesWritten) then
RaiseLastWin32Error;
finally
EndPagePrinter(hPrinter);
end;
finally
EndDocPrinter(hPrinter);
end;
finally
WinSpool.ClosePrinter(hPrinter);
end;
end;


PrintStrToPrinter('adfasfasdf', 'Microsoft XPS Document Writer');


 
Reply With Quote
 
 
 
 
Christoph Lindemann
Guest
Posts: n/a
 
      14th Feb 2008
Well this probably is because you send "RAW" data directly to the printer,
and RAW can be any PDL. But the XPS driver will probably only understands
XPS, and it will probably just ignore your "unknown: adfasfasdf" PDL. The
XPS driver will probably, if any, only accept XPS data when you write
directly to it.

If you want to render text on the XPS driver, you should use GDI. You might
be able to send plain text to the driver if you specify "TEXT" as the
datatype. The print processor attached to the driver will then "convert" the
plaintext for you by rendering the job via GDI to the driver.

Btw, you should also call AbortPrinter in case of any exception, so that the
spoolfile will be deleted.

--
Christoph Lindemann
Undocumented Printing
http://www.undocprint.org/


"Ian Boyd" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Using the code from
>
> HOWTO: Send Raw Data to a Printer by Using the Win32 API
> http://support.microsoft.com/kb/q138594/
>
> i can print fine to every "real" printer. But when i print to the
> "Microsoft XPS Document Writer" printer, no save dialog ever appears.
>
> To sum up:
> OpenPrinter()
> StartDocPrinter()
> StartPagePrinter()
> WritePrinter()
> EndPagePrinter()
> EndDocPrinter()
> CloserPrinter()
>
> There are no errors, the spooler appears and disappears, the bytes written
> equal the bytes supposed to be written. Just in the end no Save Dialog
> appears.
>
> Where is my print job going?
>
>
> Code:
>
> procedure PrintStrToPrinter(const TextToPrint: string; const PrinterName:
> string);
> var
> hPrinter: THandle;
> DocInfo: TDocInfo1;
> dwBytesWritten : DWORD;
> dwJobID: DWORD;
> begin
> {
> HOWTO: Send Raw Data to a Printer by Using the Win32 API
> http://support.microsoft.com/kb/q138594/
> }
> if TextToPrint = '' then
> raise Exception.Create('[PrintStrToPrinter] To text specified');
>
> if not WinSpool.OpenPrinter(PChar(PrinterName), hPrinter, nil) then
> raise Exception.Create('[PrintStrToPrinter] Cannot find the
> printer "'+PrinterName+'".');
> try
> // Fill in the structure with info about this "document"
> ZeroMemory(@DocInfo, SizeOf(DocInfo));
> DocInfo.pDocName := 'My Document';
> DocInfo.pOutputFile := nil;
> DocInfo.pDatatype := 'RAW';
>
> // Inform the spooler the document is beginning
> dwJobID := StartDocPrinter(hPrinter, 1, @docInfo);
> if dwJobID = 0 then
> RaiseLastWin32Error;
> try
> if not StartPagePrinter (hPrinter) then
> RaiseLastWin32Error;
> try
> if not WritePrinter(hPrinter, PChar(TextToPrint),
> Length(TextToPrint), dwBytesWritten) then
> RaiseLastWin32Error;
> finally
> EndPagePrinter(hPrinter);
> end;
> finally
> EndDocPrinter(hPrinter);
> end;
> finally
> WinSpool.ClosePrinter(hPrinter);
> end;
> end;
>
>
> PrintStrToPrinter('adfasfasdf', 'Microsoft XPS Document Writer');
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Print directly to printer RicLo Microsoft ASP .NET 0 25th Nov 2006 11:35 AM
How can i print directly to printer?? --[zainy]-- Microsoft C# .NET 1 25th Aug 2006 07:47 PM
How to open Print property window of selected printer directly without Print Dialog Box =?Utf-8?B?U2FjaGlu?= Microsoft C# .NET 3 2nd Apr 2004 03:46 AM
print directly to the printer Maverick Microsoft Access Reports 1 13th Mar 2004 02:00 PM
Print directly to the printer DShinn Microsoft Windows 2000 Printing 0 24th Jul 2003 11:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 AM.