I
Ian Boyd
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');
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');