Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. use PDF printer as the default printer

use PDF printer as the default printer

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harshsingh
    wrote on last edited by
    #1

    Is it possible to set the default printer as a PDF printer....are there any APIs which support commands to do the conversion Maverick

    L R 2 Replies Last reply
    0
    • H harshsingh

      Is it possible to set the default printer as a PDF printer....are there any APIs which support commands to do the conversion Maverick

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      SetDefaultPrinter(LPCTSTR pszPrinter)

      H 1 Reply Last reply
      0
      • L Lost User

        SetDefaultPrinter(LPCTSTR pszPrinter)

        H Offline
        H Offline
        harshsingh
        wrote on last edited by
        #3

        thanks a lot...but it seems that you didn't get the whole problem or rather I didn't frame the problem properly...actually there is an application through which I generate some data, and while printing I want to get the printout in PDF format(I have the PDF writer with me), in that what I get is that the browser window asks me first to save the file in a different format which I don't want. I just want file to be stored at some specified location(which we are free to decide)....In all I want that once the user gives the print command he should get the printout in the PDF format....no interaction in between.....hope I am clear this time ;)

        1 Reply Last reply
        0
        • H harshsingh

          Is it possible to set the default printer as a PDF printer....are there any APIs which support commands to do the conversion Maverick

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          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\_n
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups