コード例 #1
0
ファイル: MyCarbonPrinting.c プロジェクト: arnelh/Examples
// ---------------------------------------------------------------------------------------------
static pascal void MyPrintDialogDoneProc(PMPrintSession printSession,
                            WindowRef documentWindow, Boolean accepted)
{
    OSStatus err = noErr, tempErr;
    void *ourDataP = GetOurWindowProperty(documentWindow);
    if(ourDataP)
    {
        PMPrintSettings printSettings = GetPrintSettingsFromPrivateData(ourDataP);
        
	// only run the print loop if the user accepted the print dialog.
        if(accepted){
            err = MyDoPrintLoop(printSession, 
                        GetPageFormatFromPrivateData(ourDataP),
                        printSettings, ourDataP, &gMyPrintingProcsWithStatusDialog);
	}

        // We're done with the print settings on our private data so
        // set them to NULL which causes the print settings to be released
        tempErr = SetPrintSettingsOnPrivateData(ourDataP, NULL);
        if(err == noErr)
            err = tempErr;
    }// else Assert(...);
    
    // now we release the session we created to do the Print dialog
    tempErr = PMRelease(printSession);
    if(err == noErr)
        err = tempErr;
    
    DoErrorAlert(err, kMyPrintErrorFormatStrKey);
}
コード例 #2
0
// --------------------------------------------------------------------------------------------------------------
static pascal void MyPrintDialogDoneProc(PMPrintSession printSession,
                            WindowRef documentWindow, Boolean accepted)
{
    OSStatus status = noErr, tempErr;
    void *ourDataP = GetOurWindowProperty(documentWindow);
    if(ourDataP)
    {
        PMPrintSettings printSettings = GetPrintSettingsFromPrivateData(ourDataP);
	// only run the print loop if the user accepted the print dialog.
        if(accepted)
            status = MyDoPrintLoop(printSession, 
                        GetPageFormatFromPrivateData(ourDataP),
                        printSettings, ourDataP);

        SetPrintSettingsOnPrivateData(ourDataP, NULL);
        tempErr = PMRelease(printSettings);
        if(status == noErr)
            status = tempErr;
    }
    // now we release the session we created to do the Print dialog
    tempErr = PMRelease(printSession);
    if(status == noErr)
        status = tempErr;
    
    DoErrorAlert(status, kMyPrintErrorFormatStrKey);
}
コード例 #3
0
ファイル: MyCarbonPrinting.c プロジェクト: arnelh/Examples
OSStatus MakePDFDocument(WindowRef parentWindow, void *documentDataP, CFURLRef saveURL)
{
#pragma unused (parentWindow)
    OSStatus err = noErr, tempErr;
    PMPrintSettings printSettings = NULL;
    PMPrintSession printSession;
    err = PMCreateSession(&printSession);
    if(err == noErr){
	// validate the page format we're going to use
	err = PMSessionValidatePageFormat(printSession, 
			    GetPageFormatFromPrivateData(documentDataP),
			    kPMDontWantBoolean);
        if (err == noErr)
        {
            err = PMCreatePrintSettings(&printSettings);
            if(err == noErr)
            {
                err = PMSessionDefaultPrintSettings(printSession, printSettings);
                if(err == noErr){
                    CFStringRef myDocumentNameRef;
                    err = CopyDocumentName(documentDataP, &myDocumentNameRef);
                    if(err == noErr)
                    {
                        // set the job name
                        err = PMSetJobNameCFString (printSettings, myDocumentNameRef);
                        CFRelease(myDocumentNameRef);	// release our reference to the document name
                    }
                }

                if (err == noErr)
                    err = PMSetPageRange(printSettings, 1, MyGetDocumentNumPagesInDoc(documentDataP));
                
                // set our destination to be our target URL and the format to be PDF
                if(err == noErr){
                    // this API exists ONLY in MacOS X 10.1 and later only
                    if(!err)
                        err = Call_PMSessionSetDestination(printSession, printSettings,
                                    kPMDestinationFile, kPMDocumentFormatPDF, 
                                    saveURL);
                }
#if !NO_SAVE_STATUS_DIALOG
                /*
                    It looks a bit odd to call PMSessionUseSheets when we aren't even
                    using the print dialog BUT the reason we are doing so is so that
                    the printing status narration will use sheets and not a modal
                    dialog. NOTE: this is only called when this code is built with
                    !NO_SAVE_STATUS_DIALOG is true, i.e. we want status narration
                    of the save to PDF process.
                */
                if(err == noErr){
                    err = PMSessionUseSheets(printSession, parentWindow, NULL);             
                }
#endif
            }

            if (err == noErr)
            {
                err = MyDoPrintLoop(printSession, 
                            GetPageFormatFromPrivateData(documentDataP),
                            printSettings, 
                            documentDataP, 
#if NO_SAVE_STATUS_DIALOG
			    &gMyPrintingProcsNoStatusDialog
#else
                            &gMyPrintingProcsWithStatusDialog
#endif
                        );
            }
        }
        if(printSettings){
            tempErr = PMRelease(printSettings);
            if(err == noErr)
                err = tempErr;
        }

        tempErr = PMRelease(printSession);    
        if(err == noErr)
            err = tempErr;
    }
    DoErrorAlert(err, kMySaveAsPDFErrorFormatStrKey);
    return err;
}