Click here to Skip to main content
15,916,949 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Advice on skewed ::StretchBlt()-ed image Pin
JWood22-Sep-03 3:42
JWood22-Sep-03 3:42 
GeneralRe: Advice on skewed ::StretchBlt()-ed image Pin
Johann Gerell22-Sep-03 22:36
Johann Gerell22-Sep-03 22:36 
GeneralRe: Advice on skewed ::StretchBlt()-ed image Pin
Anonymous23-Sep-03 2:40
Anonymous23-Sep-03 2:40 
GeneralI got some strange behaviors. ( VS2003 vs VS6 ) Pin
Mathias S.22-Sep-03 1:54
Mathias S.22-Sep-03 1:54 
Generaluse PDF printer as the default printer Pin
harshsingh21-Sep-03 22:12
harshsingh21-Sep-03 22:12 
GeneralRe: use PDF printer as the default printer Pin
Dangleberry22-Sep-03 0:08
sussDangleberry22-Sep-03 0:08 
GeneralRe: use PDF printer as the default printer Pin
harshsingh22-Sep-03 2:08
harshsingh22-Sep-03 2:08 
GeneralRe: use PDF printer as the default printer (long) Pin
Roger Allen22-Sep-03 4:34
Roger Allen22-Sep-03 4:34 
Are you acessing the PDF print driver through the ICDIntf interface?

If you are, I did it this way:
void CMyView::OnPdfPrint() 
{
	DOCINFO			di;
	CPrintInfo		printInfo;
	CString			filename;
	CDC				dc;
	CRect			draw_area;
	char			fname[_MAX_FNAME];
	
	memset(&di, 0, sizeof(DOCINFO));
	
	CFileDialog		dlg(FALSE, "PDF", filename, OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY, "Adobe acrobat PDF files (*.pdf)|*.pdf||");
	
	if (dlg.DoModal() == IDCANCEL)
	{
		return;
	}

	AfxGetMainWnd()->EnableWindow(false);    // disable main window
	CPrintStatus dlgPrintStatus(this);
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, "Creating PDF interface");
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, "");
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, "");
	dlgPrintStatus.ShowWindow(SW_SHOW);
	dlgPrintStatus.UpdateWindow();
	dlgPrintStatus.PumpMessages();

	try
	{
		// start the PDF ole interface
		ICDIntf	pdfInterface;
		// Start Excel and get Application object.
		if (pdfInterface.CreateDispatch("CDIntf.CDIntf"))
		{
			// success
			long lPdfError = pdfInterface.PDFDriverInit("Sirius PDF Generator");
			
			if(lPdfError != 0)
			{
				//An error should only occur when lPdfError == 0 but hey what the hell.
				return;
			}
			
			pdfInterface.SetPaperSize(9); // Sets to A4
			
			pdfInterface.SetDefaultFileName(filename);
			pdfInterface.SetFileNameOptions(1 + 2 + 32); //NoPrompt + UseFileName + BroadcastMessages

			HDC hDC = (HDC)pdfInterface.CreateDC();
			if (hDC != NULL)
			{
				OnAboutToPrint();
				di.cbSize = sizeof(DOCINFO);
				di.lpszDocName = pDoc->GetPathName();
				di.lpszOutput = filename;
				
				// prepare the print information structure
				dc.Attach(hDC);
				printInfo.m_bDirect = TRUE;
				printInfo.m_rectDraw.left = 0;
				printInfo.m_rectDraw.right = dc.GetDeviceCaps(HORZRES);
				printInfo.m_rectDraw.top = 0;
				printInfo.m_rectDraw.bottom = dc.GetDeviceCaps(VERTRES);
				draw_area = printInfo.m_rectDraw;
				
				CString strTemp;
				dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, fname);
				dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, "PDF Generator");
				dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, "");
				dlgPrintStatus.UpdateWindow();
				
				dc.StartDoc(&di);
				OnPreparePrinting(&printInfo);
				printInfo.m_rectDraw = draw_area;
				
				// start printing the document
				for (printInfo.m_nCurPage = 1; printInfo.m_nCurPage <= printInfo.GetMaxPage(); printInfo.m_nCurPage++)
				{
					strTemp.Format("Page %1d of %1d", printInfo.m_nCurPage, printInfo.GetMaxPage());
					dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, strTemp);
					dlgPrintStatus.PumpMessages();
					dc.StartPage();
					OnPrint(&dc, &printInfo);
					dc.EndPage();
					// reset page size as OnPrint may have odified them when
					// header / footers were added to the page
					printInfo.m_rectDraw = draw_area;
				}
				OnEndPrinting(&dc, &printInfo);
				dc.EndDoc();
				VERIFY(dc.DeleteDC());
			}
			else
			{
				// failed to create the HDC
				AfxMessageBox("PDF Driver failed, unable to create DC");
			}

			// Remove the driver
			pdfInterface.SetFileNameOptions(0);
			pdfInterface.DriverEnd();
			
			pdfInterface.DetachDispatch();
			
			// pop-up the pdf viewer
			if (atoi(RegistryProfile::GetProfileStringLM("PrintSettings", "StartPDF", "1")) != 0)
			{
				ShellExecute(NULL, NULL, filename, NULL, NULL, SW_SHOWMAXIMIZED);
			}
		}
	}
	//Catch control-specific exceptions.
	catch (COleDispatchException * e) 
	{
		CString cStr("");
		if (!e->m_strSource.IsEmpty())
		{
			cStr = e->m_strSource + " - ";
		}
		if (!e->m_strDescription.IsEmpty())
		{
			cStr += e->m_strDescription;
		}
		else
		{
			cStr += "unknown error";
		}
		AfxMessageBox(cStr, MB_OK, (e->m_strHelpFile.IsEmpty())? 0:e->m_dwHelpContext);
		e->Delete();
	}
	//Catch all MFC exceptions, including COleExceptions.
	// OS exceptions will not be caught.
	catch (CException *e) 
	{
		TRACE("%s(%d): OLE Execption caught: SCODE = %x", __FILE__, __LINE__, COleException::Process(e));
		e->Delete();
	}
	dlgPrintStatus.DestroyWindow();
	AfxGetMainWnd()->EnableWindow();    // enable main window
}



Roger Allen
Sonork 100.10016

Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
Generaladf Pin
Anonymous21-Sep-03 21:52
Anonymous21-Sep-03 21:52 
GeneralRe: adf Pin
r i s h a b h s21-Sep-03 23:28
r i s h a b h s21-Sep-03 23:28 
GeneralRe: adf Pin
Dangleberry22-Sep-03 0:06
sussDangleberry22-Sep-03 0:06 
GeneralRe: adf Pin
David Crow22-Sep-03 2:43
David Crow22-Sep-03 2:43 
GeneralRe: adf Pin
Michael Dunn22-Sep-03 4:07
sitebuilderMichael Dunn22-Sep-03 4:07 
GeneralTutorials Help Pin
Neelesh K J Jain21-Sep-03 21:48
Neelesh K J Jain21-Sep-03 21:48 
GeneralCRichEditCtrl Pin
hph21-Sep-03 21:25
hph21-Sep-03 21:25 
GeneralRe: CRichEditCtrl Pin
Blake Coverett21-Sep-03 22:30
Blake Coverett21-Sep-03 22:30 
GeneralRe: CRichEditCtrl Pin
hph21-Sep-03 22:38
hph21-Sep-03 22:38 
GeneralRe: CRichEditCtrl Pin
David Crow22-Sep-03 2:45
David Crow22-Sep-03 2:45 
GeneralGet Info when a new window is created Pin
«_Superman_»21-Sep-03 21:05
professional«_Superman_»21-Sep-03 21:05 
GeneralCreating Control Object Dynamically Pin
drabudawood21-Sep-03 20:55
drabudawood21-Sep-03 20:55 
GeneralRe: Creating Control Object Dynamically Pin
Mike Dimmick22-Sep-03 3:00
Mike Dimmick22-Sep-03 3:00 
GeneralRe: Creating Control Object Dynamically Pin
drabudawood22-Sep-03 19:05
drabudawood22-Sep-03 19:05 
GeneralCopying Dialog Pin
rieber21-Sep-03 20:08
rieber21-Sep-03 20:08 
GeneralRe: Copying Dialog Pin
Michael Dunn21-Sep-03 20:23
sitebuilderMichael Dunn21-Sep-03 20:23 
GeneralRe: Copying Dialog Pin
rieber21-Sep-03 21:56
rieber21-Sep-03 21:56 

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.