Printing using Win32 Printer.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Printing using Win32 Printer.

  1. #1
    Join Date
    Feb 2009
    Posts
    24

    Unhappy Printing using Win32 Printer.

    Hi ,
    I have a problem printing using win32 printer to "Adobe PDF" printer ( Which generates output in pdf format)

    But the same code prints well with all other printers like Freepdf , Primopdf,ConvertWIZ , hardware printer..etc...

    When i select the "Adobe PDF" to print the document the "StartDoc" returns -1.
    but for the other printers "StartDoc" returns value > 0

    I have attached the sample code below.

    Code:
    	HGLOBAL 					 hDevMode;
    	DEVMODE* 				 pDevMode;
    	HDC 				                 hPrinterDC;
    	DOCINFO 					 DocumentInfo;
    
    
    	hDevMode = GlobalAlloc(GHND, sizeof(DEVMODE));
    	if ( hDevMode )
    	{
    	   // lock the memory and return a pointer to it
    	   pDevMode = (DEVMODE *) GlobalLock(hDevMode);
    	   if ( pDevMode )
    	   {
    		  // set the size of the DEVMODE structure
    		  pDevMode->dmSize             = sizeof(DEVMODE);
    		  pDevMode->dmOrientation = DMORIENT_LANDSCAPE
    		  pDevMode->dmPaperSize   = m_pPrintSetupParams->iPaperMediaID ;
    		  
                                      // tell Windows that I will be setting the dmOrientation and paper size ;
    		  pDevMode->dmFields 	  = DM_ORIENTATION | DM_PAPERSIZE ;
    	   }
    	   // unlock the memory for other functions to use this
    	   GlobalUnlock(hDevMode);
    	}
    	hPrinterDC = CreateDC("WINSPOOL\0", pszPrinterName.c_str(),NULL,pDevMode);
    	memset( &DocumentInfo, 0, sizeof(DOCINFO) );
    	DocumentInfo.cbSize 	= sizeof(DOCINFO);
    	DocumentInfo.lpszDocName 	= "TestPage" ;
    	DocumentInfo.lpszOutput  	= (LPTSTR) NULL;
    	DocumentInfo.lpszDatatype 	= (LPTSTR) NULL;
    	DocumentInfo.fwType = 0;
    
    	int nError = StartDoc(hPrinterDC, &DocumentInfo); // The return value of this function is -1 with "Adobe PDF " printer.
    
    	if (nError == SP_ERROR)
    	{
        	return false; 
    	}
    The "Adobe PDF " printer will get installed with the installation of "Adobe Acrobat 9 Standard"

    Plz help, Thanks in advance.

    Regards,
    Vijay.
    Last edited by Marc G; March 25th, 2010 at 08:44 AM. Reason: Added code tags

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Printing using Win32 Printer.

    What does GetLastError() tell you?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center