none
How to print the xps document ???

    Question

  • Hi, I have a question:
    I view the xps document with the DocumentViewer control, and call DocumentViewer::Print() method to print current xps document, but nothing to happen, Why? How to print the xps documents? thanks!
    Tuesday, December 13, 2005 9:18 AM

Answers

  • Hi

    Sorry for the late reply.

    As far as we can tell this method should work with our latest build.

    Can you please provide your print code and also specify what WPF CTP exactly are you using ?

    I assume you verified that your printers work with other apps such as Notepad.

    It may be good to try printing the XPS document directly from the browser (e.g. you can do Ctrl+P).

    Thanks. Jossef.

    Tuesday, January 03, 2006 10:07 PM
    Moderator

All replies

  • Hi

    Sorry for the late reply.

    As far as we can tell this method should work with our latest build.

    Can you please provide your print code and also specify what WPF CTP exactly are you using ?

    I assume you verified that your printers work with other apps such as Notepad.

    It may be good to try printing the XPS document directly from the browser (e.g. you can do Ctrl+P).

    Thanks. Jossef.

    Tuesday, January 03, 2006 10:07 PM
    Moderator
  • I would like to print programmatically (I need c++ code) to my hp printer (the default printer). I think that's what he was asking.

    I have

    bool printerInit(void) {
        memset(defaultPrinterName, 0, DefaultPrinterNameSize);
        DWORD dw=DefaultPrinterNameSize;
        if (GetDefaultPrinter(defaultPrinterName, &dw)) {
            return true;
        }
        return false;
    }

    //code for this function obtained from http://social.msdn.microsoft.com/Forums/en-US/4c70e84a-f781-4016-82b9-393d6635755e/xps-and-startdoc?forum=windowsxps
    void printFile(std::string filepath, std::string title, int x, int y, int tabSize) {
        const int leftMargin=1000/4,topMargin=1000/4;
        HANDLE hPrinter;
        title=std::string("\"")+title+std::string("\"\t")+timeStampString();
            HDC hDC = CreateDC(TEXT("Microsoft XPS Document Writer"), TEXT("Microsoft XPS Document Writer"), NULL, NULL);
            HFONT hFont= CreateFont(x,y,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("OCR A Std Regular"));
            /*HFONT hOldFont=(HFONT)*/SelectObject(hDC,(HGDIOBJ)hFont);
            DOCINFO di;
            di.cbSize=sizeof(DOCINFO);
            memset(&di,0,sizeof(DOCINFO));
            di.lpszDocName = filepath.c_str();
            di.lpszOutput = TEXT(soutfile.c_str());
            int JobId = StartDoc(hDC,&di);
            StartPage(hDC);
            INT tabStops[100];
            INT nTabStops=100;
            for (int i=0; i<nTabStops; i++) {
                tabStops[i]=i*tabSize;
            }
            if (TabbedTextOut(hDC,leftMargin,topMargin,title.c_str(),title.size(), nTabStops, tabStops, leftMargin)) {
            } else {
                std::cout<<"ERROR: could not write filepath as title on page. printing anyway.\n";
            }
            EndPage(hDC);
            EndDoc(hDC);
            //SelectObject(hDC,(HGDIOBJ)hOldFont);
            DeleteDC(hDC);
            PRINTER_DEFAULTS pd;
            /*DEVMODE dm;
            strcpy(dm.dmDeviceName,defaultPrinterName);
            dm.dmSpecVersion=DM_SPECVERSION;
            dm.dmDriverVersion
            pd.pDataType=NULL;//TEXT("RAW");
            pd.pDevMode=&dm;
            pd.DesiredAccess=PRINTER_ACCESS_USE;*/
        if (OpenPrinter(defaultPrinterName, &hPrinter, NULL)) {
            std::cout<<"Opened printer \""<<defaultPrinterName<<"\"\n";
            /*DOC_INFO_1 di1;
            di1.pDocName=title.c_str();
            di1.pOutputFile=NULL;;
            di1.pDataType=TEXT("RAW");
            StartDocPrinter(hPrinter, 1, (LPBYTE)&di1);*/
            ADDJOB_INFO_1 aji1, aji1o;
            aji1.Path=(char*)soutfile.c_str();
            aji1.JobId=JobId;
            DWORD dwcbneeded=sizeof(ADDJOB_INFO_1);
            AddJob(hPrinter, 1, (LPBYTE)&aji1o, sizeof(ADDJOB_INFO_1), &dwcbneeded);
            /*DOC_INFO_1 di1;
            di1.pDocName=(char*)title.c_str();
            di1.pOutputFile=(char*)soutfile.c_str();
            di1.pDatatype=TEXT("XPS");
            StartDocPrinter(hPrinter, 1, (LPBYTE)&di1);*/
            ScheduleJob(hPrinter, JobId);
            std::cout<<"Printing "<<title<<"...\n";
            ClosePrinter(hPrinter);
        } else {
            std::cout<<"ERROR:count not open printer \""<<defaultPrinterName<<"\"\n";
        }
    }

    but this only outputs an xps file I think. hp printer doesn't budge.

    I don't know how to get the devmode struct data since it's not documented in the documentation for OpenPrinter.

    running into walls here. need help to get farther. thanks. help and code appreciated.

    Monday, January 20, 2014 6:54 AM