Click here to Skip to main content
15,913,669 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Device Context Pin
Anonymous1-Dec-03 20:40
Anonymous1-Dec-03 20:40 
GeneralRe: Device Context Pin
eldar_20012-Dec-03 14:43
eldar_20012-Dec-03 14:43 
GeneralCdataGrid Pin
sdfdsfa1-Dec-03 14:00
sdfdsfa1-Dec-03 14:00 
GeneralRe: CdataGrid Pin
bilas1-Dec-03 19:47
bilas1-Dec-03 19:47 
GeneralRe: CdataGrid Pin
sdfdsfa2-Dec-03 6:41
sdfdsfa2-Dec-03 6:41 
Generaladd Wnds to an SDI Pin
Zizilamoroso1-Dec-03 13:26
Zizilamoroso1-Dec-03 13:26 
GeneralRe: add Wnds to an SDI Pin
Anonymous1-Dec-03 20:43
Anonymous1-Dec-03 20:43 
QuestionHow to Print to a PDF File using printer driver in C++ Pin
Richard Guion1-Dec-03 13:01
Richard Guion1-Dec-03 13:01 
I have an MFC Win32 client application that needs to generate PDF
files. The easiest way to do it is to have our customers purchase and
install Adobe Acrobat, and then our program will use the "Adobe PDF" printer
driver to output our text to PDF files.

From any application like Notepad, Word, Excel, using the Adobe PDF writer
works fine when I do File\Print, click "Print to File", uncheck the printer
property of downloading fonts to printer--my PDF file is created fine.

I need to do this from C++. The user is not going to use File\Print in our
app, we need to convert files as we go.

Something is not working in my code which I've pasted below. I'm using OpenPrinter
to open the "Adobe PDF" printer (return code is good), I call StartDocPrinter setting
my output file name to "D:\temp\test.pdf" and set the datatype either to RAW or NULL,
same result occurs: a test.pdf file is created, but it is pure text "this is a test"
instead of PDF content.

Anyone see what I am doing wrong? It appears to me that I need another code for
pDatatype. Or should I not be using these OS calls for a printer driver?

#include <winspool.h>
...
BOOL PrintStringDirect( LPCSTR Str, LPTSTR PrinterName, LPSTR DeviceName )
{
BOOL bRet = FALSE;
HANDLE hPrinter;

if ( OpenPrinter( PrinterName, &hPrinter, NULL ) )
{
DOC_INFO_1 doc_info = {0};

doc_info.pDocName = "Test Document";
doc_info.pOutputFile = DeviceName;
//doc_info.pDatatype = (LPTSTR) NULL;
doc_info.pDatatype = "raw";

DWORD jobid = StartDocPrinter( hPrinter, 1, (LPBYTE)&doc_info );

if ( jobid != 0 )
{
DWORD written;
DWORD dwNumBytes = lstrlen( Str );

WritePrinter( hPrinter, (void*) Str,
dwNumBytes, &written );

if ( written == dwNumBytes )
bRet = TRUE;
}

EndDocPrinter(hPrinter);
ClosePrinter(hPrinter);
}

return bRet;
}


PrintStringDirect("This is a test", "Adobe PDF", "D:\\temp\\test.pdf");


AnswerRe: How to Print to a PDF File using printer driver in C++ Pin
Roger Allen2-Dec-03 2:13
Roger Allen2-Dec-03 2:13 
GeneralRe: How to Print to a PDF File using printer driver in C++ Pin
Richard Guion2-Dec-03 6:39
Richard Guion2-Dec-03 6:39 
GeneralRe: How to Print to a PDF File using printer driver in C++ Pin
Richard Guion2-Dec-03 16:10
Richard Guion2-Dec-03 16:10 
GeneralActiveX error Pin
vijisu1-Dec-03 12:49
vijisu1-Dec-03 12:49 
QuestionCDHTMLDialog control position? Pin
Robert Mooney1-Dec-03 12:39
Robert Mooney1-Dec-03 12:39 
General--Problem using class CADORecordset-- Pin
bilas1-Dec-03 10:20
bilas1-Dec-03 10:20 
GeneralRe: --Problem using class CADORecordset-- Pin
Debs1-Dec-03 23:15
Debs1-Dec-03 23:15 
GeneralRe: --Problem using class CADORecordset-- Pin
bilas2-Dec-03 11:27
bilas2-Dec-03 11:27 
GeneralRe: --Problem using class CADORecordset-- Pin
Debs2-Dec-03 12:59
Debs2-Dec-03 12:59 
GeneralWinsock Reply From Server 2 Client Pin
jake_t1-Dec-03 9:49
jake_t1-Dec-03 9:49 
GeneralRe: Winsock Reply From Server 2 Client Pin
BaldwinMartin1-Dec-03 19:35
BaldwinMartin1-Dec-03 19:35 
GeneralRe: Winsock Reply From Server 2 Client Pin
Anonymous1-Dec-03 23:58
Anonymous1-Dec-03 23:58 
GeneralRe: Winsock Reply From Server 2 Client Pin
v_srinu_26_f17-Dec-03 18:54
v_srinu_26_f17-Dec-03 18:54 
Generallist of Properties ID Pin
pnpfriend1-Dec-03 9:44
pnpfriend1-Dec-03 9:44 
GeneralRe: list of Properties ID Pin
Big Art1-Dec-03 10:31
Big Art1-Dec-03 10:31 
Generalsending messages between applications Pin
srev1-Dec-03 9:23
srev1-Dec-03 9:23 
GeneralRe: sending messages between applications Pin
Christian Graus1-Dec-03 9:46
protectorChristian Graus1-Dec-03 9:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.